-
Notifications
You must be signed in to change notification settings - Fork 0
/
initctl_linux.go
47 lines (40 loc) · 934 Bytes
/
initctl_linux.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
package service
import (
"errors"
"strconv"
"strings"
)
const initctlExec = "initctl"
type initctl struct {
}
func (s initctl) startCmd(sName string) []string {
return []string{initctlExec, "start", sName}
}
func (s initctl) statusCmd(sName string) []string {
return []string{initctlExec, "status", sName}
}
func (s initctl) stopCmd(sName string) []string {
return []string{initctlExec, "stop", sName}
}
func (s initctl) parseStatus(sData string, err error) (Status, error) {
var st Status
lines := strings.Split(sData, "\n")
if len(lines) == 2 {
if err != nil {
err = errors.New(string(sData))
} else {
words := strings.Split(string(sData), " ")
if len(words) == 4 {
if strings.HasPrefix(words[1], "start/running") {
st.Running = true
pid := words[3][0 : len(words[3])-1]
st.PID, err = strconv.Atoi(pid)
if err != nil {
panic(err)
}
}
}
}
}
return st, err
}