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
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -20,6 +21,21 @@ func isSystemd() bool {
|
||||
if _, err := os.Stat("/run/systemd/system"); err == nil {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -228,9 +244,8 @@ func (s *systemd) Restart() error {
|
||||
const systemdScript = `[Unit]
|
||||
Description={{.Description}}
|
||||
ConditionFileIsExecutable={{.Path|cmdEscape}}
|
||||
{{range .Dependencies}}
|
||||
{{.}}
|
||||
{{end}}
|
||||
{{range $i, $dep := .Dependencies}}
|
||||
{{$dep}} {{end}}
|
||||
|
||||
[Service]
|
||||
StartLimitInterval=5
|
||||
|
||||
Reference in New Issue
Block a user