forked from kavanahuang/system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
61 lines (52 loc) · 1000 Bytes
/
command.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
/**
* Created by Kernel.Huang
* User: kernelman@live.com
* Date: 2021/3/23
* Time: 16:03
*/
package system
import "os"
type CommandServices struct {
ExecDir string
ExecName string
PidDir string
PidName string
}
var Command = new(CommandServices)
func (cs *CommandServices) Run(execDir, execName, pidDir, pidName string) {
cs.ExecDir = execDir
cs.ExecName = execName
cs.PidDir = pidDir
cs.PidName = pidName
switch len(os.Args) {
case 2:
cs.isRun(os.Args)
default:
cs.usage()
}
}
// 如果是合法指令则执行程序
func (cs *CommandServices) isRun(args []string) {
Daemon.ExecDir = cs.ExecDir
Daemon.ExecName = cs.ExecName
Daemon.PidDir = cs.PidDir
Daemon.PidName = cs.PidName
command := args[1]
switch command {
case "start":
_ = Daemon.Start()
os.Exit(0)
case "stop":
_ = Daemon.Stop()
os.Exit(0)
case "restart":
_ = Daemon.Restart()
os.Exit(0)
default:
cs.usage()
}
}
func (cs *CommandServices) usage() {
Daemon.Usage()
os.Exit(1)
}