forked from codeskyblue/gosuv
-
Notifications
You must be signed in to change notification settings - Fork 10
/
gosuv.go
136 lines (129 loc) · 2.44 KB
/
gosuv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/urfave/cli"
)
var cl = &Client{}
func main() {
//初始global 变量
CfgDir = getCurrentPath()
CurrentDir = getCurrentPath()
CmdDir = getExecPath()
app := cli.NewApp()
app.Name = AppName
app.Version = Version
app.Usage = "golang supervisor"
app.Before = func(c *cli.Context) error {
var err error
CfgFile = c.GlobalString("conf")
if filepath.IsAbs(CfgFile) {
CfgDir = filepath.Dir(CfgFile)
} else {
CfgDir = filepath.Dir(filepath.Join(getCurrentPath(), CfgFile))
}
Cfg, err = readConf(CfgFile)
if err != nil {
fmt.Printf("read conf failed,", err)
os.Exit(-1)
}
//加载client配置
cl = NewClient()
return nil
}
app.Authors = []cli.Author{
cli.Author{
Name: Author,
Email: Email,
},
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "conf, c",
Usage: "config file",
Value: DefaultConfig,
},
}
app.Commands = []cli.Command{
{
Name: "start-server",
Usage: "Start supervisor and run in background",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "foreground, f",
Usage: "start in foreground",
},
cli.StringFlag{
Name: "conf, c",
Usage: "config file",
Value: DefaultConfig,
},
},
Action: actionStartServer,
},
{
Name: "status",
Aliases: []string{"st"},
Usage: "Show program status",
Action: actionProgramStatus,
},
{
Name: "status-server",
Aliases: []string{"st"},
Usage: "Show server status",
Action: actionStatus,
},
{
Name: "start",
Usage: "Start program",
Action: actionStart,
},
{
Name: "stop",
Usage: "Stop program",
Action: actionStop,
},
{
Name: "reload",
Usage: "Reload config file",
Action: actionReload,
},
{
Name: "shutdown",
Usage: "Shutdown server",
Action: actionShutdown,
},
{
Name: "kill",
Usage: "kill stop server by pid file.",
Action: actionKill,
},
{
Name: "restart-server",
Usage: "restart server",
Action: actionRestart,
},
{
Name: "conftest",
Aliases: []string{"t"},
Usage: "Test if config file is valid",
Action: actionConfigTest,
},
{
Name: "edit",
Usage: "Edit config file",
Action: actionEdit,
},
{
Name: "version",
Usage: "Show version",
Aliases: []string{"v"},
Action: actionVersion,
},
}
if err := app.Run(os.Args); err != nil {
fmt.Println(err)
os.Exit(1)
}
}