-
Notifications
You must be signed in to change notification settings - Fork 328
/
cmds_04_service.go
86 lines (75 loc) · 2.08 KB
/
cmds_04_service.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
// +build !client
package cli
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
initCmdFuncs = append(initCmdFuncs, func(c *CLI) {
c.initServiceCmds()
c.initServiceFlags()
})
}
func (c *CLI) initServiceCmds() {
c.serviceCmd = &cobra.Command{
Use: "service",
Short: "The service controller",
Run: func(cmd *cobra.Command, args []string) {
cmd.Usage()
},
}
c.c.AddCommand(c.serviceCmd)
c.serviceStartCmd = &cobra.Command{
Use: "start",
Short: "Start the service",
Run: func(cmd *cobra.Command, args []string) {
serviceStart(c.ctx, c.config, c.nopid)
},
}
c.c.AddCommand(c.serviceStartCmd)
c.serviceCmd.AddCommand(c.serviceStartCmd)
c.serviceRestartCmd = &cobra.Command{
Use: "restart",
Aliases: []string{"reload", "force-reload"},
Short: "Restart the service",
Run: func(cmd *cobra.Command, args []string) {
serviceRestart(c.ctx, c.config, c.nopid)
},
}
c.c.AddCommand(c.serviceRestartCmd)
c.serviceCmd.AddCommand(c.serviceRestartCmd)
c.serviceStopCmd = &cobra.Command{
Use: "stop",
Short: "Stop the service",
Run: func(cmd *cobra.Command, args []string) {
serviceStop(c.ctx)
},
}
c.c.AddCommand(c.serviceStopCmd)
c.serviceCmd.AddCommand(c.serviceStopCmd)
c.serviceStatusCmd = &cobra.Command{
Use: "status",
Short: "Print the service status",
Run: func(cmd *cobra.Command, args []string) {
serviceStatus(c.ctx)
},
}
c.c.AddCommand(c.serviceStatusCmd)
c.serviceCmd.AddCommand(c.serviceStatusCmd)
c.serviceInitSysCmd = &cobra.Command{
Use: "initsys",
Short: "Print the detected init system type",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getInitSystemCmd())
},
}
c.c.AddCommand(c.serviceInitSysCmd)
}
func (c *CLI) initServiceFlags() {
c.serviceStartCmd.Flags().BoolVarP(&c.nopid, "foreground", "f", false,
"Deprecated. The service is always run in the foreground now.")
c.serviceStartCmd.Flags().BoolVarP(&c.nopid, "nopid", "", false,
"Disable PID file checking")
c.serviceStartCmd.Flags().BoolVarP(&c.force, "force", "", false,
"Forces the service to start, ignoring errors")
}