-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.go
59 lines (51 loc) · 1.04 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
package command
import (
"errors"
"os"
"os/exec"
"github.com/tracerun/tracerun/service"
"github.com/urfave/cli"
)
// NewStartCMD create a start command.
func NewStartCMD() cli.Command {
return cli.Command{
Name: "start",
Usage: "start TCP service",
Action: startAction,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "d",
Usage: "Run in background mode.",
},
},
}
}
func startAction(c *cli.Context) error {
p := c.GlobalUint("p")
if c.Bool("d") {
idx := 0
for i := 0; i < len(os.Args); i++ {
if os.Args[i] == "-d" {
idx = i
break
}
}
// "-d" can't be the first two arg.
if idx < 2 {
return errors.New("-d flag is wrong")
}
args := append(os.Args[:idx], os.Args[idx+1:]...)
cmd := exec.Command(args[0], args[1:]...)
// start the command
if err := cmd.Start(); err != nil {
return err
}
// release the process from this thread, make it a daemon
if err := cmd.Process.Release(); err != nil {
return err
}
} else {
service.Start(uint16(p), c.GlobalString("db"))
}
return nil
}