mirror of
https://github.com/kardianos/service.git
synced 2025-10-18 22:54:46 +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.")
|
||||
flag.Parse()
|
||||
|
||||
options := make(service.KeyValue)
|
||||
options["Restart"] = "on-success"
|
||||
options["SuccessExitStatus"] = "1 2 8 SIGKILL"
|
||||
svcConfig := &service.Config{
|
||||
Name: "GoServiceExampleLogging",
|
||||
DisplayName: "Go Service Example for Logging",
|
||||
@@ -70,6 +73,7 @@ func main() {
|
||||
Dependencies: []string{
|
||||
"Requires=network.target",
|
||||
"After=network-online.target syslog.target"},
|
||||
Option: options,
|
||||
}
|
||||
|
||||
prg := &program{}
|
||||
|
@@ -81,6 +81,9 @@ const (
|
||||
optionRunWait = "RunWait"
|
||||
optionReloadSignal = "ReloadSignal"
|
||||
optionPIDFile = "PIDFile"
|
||||
optionRestart = "Restart"
|
||||
|
||||
optionSuccessExitStatus = "SuccessExitStatus"
|
||||
|
||||
optionSystemdScript = "SystemdScript"
|
||||
optionSysvScript = "SysvScript"
|
||||
@@ -139,6 +142,9 @@ type Config struct {
|
||||
// - ReloadSignal string () [USR1, ...] - Signal to send on reaload.
|
||||
// - PIDFile string () [/run/prog.pid] - Location of the PID file.
|
||||
// - 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
|
||||
}
|
||||
|
||||
|
@@ -149,6 +149,8 @@ func (s *systemd) Install() error {
|
||||
HasOutputFileSupport bool
|
||||
ReloadSignal string
|
||||
PIDFile string
|
||||
Restart string
|
||||
SuccessExitStatus string
|
||||
LogOutput bool
|
||||
}{
|
||||
s.Config,
|
||||
@@ -156,6 +158,8 @@ func (s *systemd) Install() error {
|
||||
s.hasOutputFileSupport(),
|
||||
s.Option.string(optionReloadSignal, ""),
|
||||
s.Option.string(optionPIDFile, ""),
|
||||
s.Option.string(optionRestart, "always"),
|
||||
s.Option.string(optionSuccessExitStatus, ""),
|
||||
s.Option.bool(optionLogOutput, optionLogOutputDefault),
|
||||
}
|
||||
|
||||
@@ -260,7 +264,8 @@ ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}}
|
||||
StandardOutput=file:/var/log/{{.Name}}.out
|
||||
StandardError=file:/var/log/{{.Name}}.err
|
||||
{{- end}}
|
||||
Restart=always
|
||||
{{if .Restart}}Restart={{.Restart}}{{end}}
|
||||
{{if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{end}}
|
||||
RestartSec=120
|
||||
EnvironmentFile=-/etc/sysconfig/{{.Name}}
|
||||
|
||||
|
Reference in New Issue
Block a user