-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper_linux_test.go
48 lines (42 loc) · 1015 Bytes
/
wrapper_linux_test.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
package service
import "fmt"
var fileName string
const goSpfcTestSystemd string = "\"[Unit]\n " +
"Description=go-spfc-test\n " +
"\n " +
"[Service]\n " +
"TimeoutStartSec=0\n " +
"ExecStart=/bin/sh -c 'while true; do sleep 1; done'\n " +
"\n " +
"[Install]\n " +
"WantedBy=multi-user.target\" "
func createService() {
var text string
if controlType == SystemD {
fileName = fmt.Sprintf("/usr/lib/systemd/system/%s.service", servNameTest)
text = goSpfcTestSystemd
} else {
fileName = fmt.Sprintf("/etc/init/%s.conf", servNameTest)
text = "\"script\n while : ; do sleep 1 ; done\nend script\""
}
fmt.Println(fileName)
cmd := fmt.Sprintf("echo %s > %s", text, fileName)
var err error
if sudo {
_, err = execCmd("sudo", "sh", "-c", cmd)
} else {
_, err = execCmd("sh", "-c", cmd)
}
if err != nil {
panic(err)
}
}
func removeService() {
if controlType == Upstart {
someServiceThatExists.Stop()
}
execCmd("sudo", "rm", fileName)
}
func waitStop() {
// We dont need to. :)
}