mirror of
https://github.com/kardianos/service.git
synced 2025-10-18 14:50:44 +08:00
Support the systemd option setting for 'Restart' and 'SuccessExitStatus (#168)
* support the dependency config for linux systemd * remote the binary file incorrectly added * Support the systemd option setting for 'Restart' and 'SuccessExitStatus'
This commit is contained in:

committed by
Daniel Theophanes

parent
61d6d01901
commit
fffe6c52ed
@@ -63,6 +63,9 @@ func main() {
|
|||||||
svcFlag := flag.String("service", "", "Control the system service.")
|
svcFlag := flag.String("service", "", "Control the system service.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
options := make(service.KeyValue)
|
||||||
|
options["Restart"] = "on-success"
|
||||||
|
options["SuccessExitStatus"] = "1 2 8 SIGKILL"
|
||||||
svcConfig := &service.Config{
|
svcConfig := &service.Config{
|
||||||
Name: "GoServiceExampleLogging",
|
Name: "GoServiceExampleLogging",
|
||||||
DisplayName: "Go Service Example for Logging",
|
DisplayName: "Go Service Example for Logging",
|
||||||
@@ -70,6 +73,7 @@ func main() {
|
|||||||
Dependencies: []string{
|
Dependencies: []string{
|
||||||
"Requires=network.target",
|
"Requires=network.target",
|
||||||
"After=network-online.target syslog.target"},
|
"After=network-online.target syslog.target"},
|
||||||
|
Option: options,
|
||||||
}
|
}
|
||||||
|
|
||||||
prg := &program{}
|
prg := &program{}
|
||||||
|
@@ -81,6 +81,9 @@ const (
|
|||||||
optionRunWait = "RunWait"
|
optionRunWait = "RunWait"
|
||||||
optionReloadSignal = "ReloadSignal"
|
optionReloadSignal = "ReloadSignal"
|
||||||
optionPIDFile = "PIDFile"
|
optionPIDFile = "PIDFile"
|
||||||
|
optionRestart = "Restart"
|
||||||
|
|
||||||
|
optionSuccessExitStatus = "SuccessExitStatus"
|
||||||
|
|
||||||
optionSystemdScript = "SystemdScript"
|
optionSystemdScript = "SystemdScript"
|
||||||
optionSysvScript = "SysvScript"
|
optionSysvScript = "SysvScript"
|
||||||
@@ -139,6 +142,9 @@ type Config struct {
|
|||||||
// - ReloadSignal string () [USR1, ...] - Signal to send on reaload.
|
// - ReloadSignal string () [USR1, ...] - Signal to send on reaload.
|
||||||
// - PIDFile string () [/run/prog.pid] - Location of the PID file.
|
// - PIDFile string () [/run/prog.pid] - Location of the PID file.
|
||||||
// - LogOutput bool (false) - Redirect StdErr & StdOut to files.
|
// - LogOutput bool (false) - Redirect StdErr & StdOut to files.
|
||||||
|
// - Restart string (always) - How shall service be restarted.
|
||||||
|
// - SuccessExitStatus string () - The list of exit status that shall be considered as successful,
|
||||||
|
// in addition to the default ones.
|
||||||
Option KeyValue
|
Option KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -149,6 +149,8 @@ func (s *systemd) Install() error {
|
|||||||
HasOutputFileSupport bool
|
HasOutputFileSupport bool
|
||||||
ReloadSignal string
|
ReloadSignal string
|
||||||
PIDFile string
|
PIDFile string
|
||||||
|
Restart string
|
||||||
|
SuccessExitStatus string
|
||||||
LogOutput bool
|
LogOutput bool
|
||||||
}{
|
}{
|
||||||
s.Config,
|
s.Config,
|
||||||
@@ -156,6 +158,8 @@ func (s *systemd) Install() error {
|
|||||||
s.hasOutputFileSupport(),
|
s.hasOutputFileSupport(),
|
||||||
s.Option.string(optionReloadSignal, ""),
|
s.Option.string(optionReloadSignal, ""),
|
||||||
s.Option.string(optionPIDFile, ""),
|
s.Option.string(optionPIDFile, ""),
|
||||||
|
s.Option.string(optionRestart, "always"),
|
||||||
|
s.Option.string(optionSuccessExitStatus, ""),
|
||||||
s.Option.bool(optionLogOutput, optionLogOutputDefault),
|
s.Option.bool(optionLogOutput, optionLogOutputDefault),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +264,8 @@ ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}}
|
|||||||
StandardOutput=file:/var/log/{{.Name}}.out
|
StandardOutput=file:/var/log/{{.Name}}.out
|
||||||
StandardError=file:/var/log/{{.Name}}.err
|
StandardError=file:/var/log/{{.Name}}.err
|
||||||
{{- end}}
|
{{- end}}
|
||||||
Restart=always
|
{{if .Restart}}Restart={{.Restart}}{{end}}
|
||||||
|
{{if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{end}}
|
||||||
RestartSec=120
|
RestartSec=120
|
||||||
EnvironmentFile=-/etc/sysconfig/{{.Name}}
|
EnvironmentFile=-/etc/sysconfig/{{.Name}}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user