/
start.go
65 lines (52 loc) · 1.26 KB
/
start.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
package command
import (
"flag"
"fmt"
"github.com/mitchellh/cli"
"strings"
)
// StartCommand starts a registered process
type StartCommand struct {
Ui cli.Ui
}
func (c *StartCommand) Help() string {
helpText := `
Usage: watchdog start [options] <process_name> ...
Starts a process.
Options:
-rpc-addr=127.0.0.1:6673 RPC address of the Watchdog agent.
`
return strings.TrimSpace(helpText)
}
func (c *StartCommand) Run(args []string) int {
cmdFlags := flag.NewFlagSet("start", flag.ContinueOnError)
cmdFlags.Usage = func() { c.Ui.Output(c.Help()) }
rpcAddr := RPCAddrFlag(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
processNames := cmdFlags.Args()
if len(processNames) == 0 {
c.Ui.Error("At least one process name must be supplied.")
c.Ui.Error("")
c.Ui.Error(c.Help())
return 1
}
client, err := RPCClient(*rpcAddr)
if err != nil {
c.Ui.Error("Error connecting to Watchdog agent")
return 1
}
defer client.Close()
pids, err := client.Start(processNames...)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error starting processes: %s", err))
return 1
}
c.Ui.Output(fmt.Sprintf(
"Successfully started processes with PIDs: %v", pids))
return 0
}
func (c *StartCommand) Synopsis() string {
return "Start a process"
}