Linux systemd: two small fixes (#171)
* Linux systemd: fixed bug in service configuration template. Dependencies should now work for Linux systemd. * Linux systemd: enabled detection of systemd inside chroot environments * Linux systemd: enabled detection of systemd inside chroot environments fix
This commit is contained in:
committed by
Daniel Theophanes
parent
0e5bec1b9e
commit
61d6d01901
@@ -5,6 +5,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -20,6 +21,21 @@ func isSystemd() bool {
|
|||||||
if _, err := os.Stat("/run/systemd/system"); err == nil {
|
if _, err := os.Stat("/run/systemd/system"); err == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if _, err := os.Stat("/proc/1/comm"); err == nil {
|
||||||
|
filerc, err := os.Open("/proc/1/comm")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer filerc.Close()
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
buf.ReadFrom(filerc)
|
||||||
|
contents := buf.String()
|
||||||
|
|
||||||
|
if strings.Trim(contents, " \r\n") == "systemd" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,9 +244,8 @@ func (s *systemd) Restart() error {
|
|||||||
const systemdScript = `[Unit]
|
const systemdScript = `[Unit]
|
||||||
Description={{.Description}}
|
Description={{.Description}}
|
||||||
ConditionFileIsExecutable={{.Path|cmdEscape}}
|
ConditionFileIsExecutable={{.Path|cmdEscape}}
|
||||||
{{range .Dependencies}}
|
{{range $i, $dep := .Dependencies}}
|
||||||
{{.}}
|
{{$dep}} {{end}}
|
||||||
{{end}}
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
StartLimitInterval=5
|
StartLimitInterval=5
|
||||||
|
|||||||
Reference in New Issue
Block a user