From b5e934fdbaeb57858799c23f1577572ab03c90ad Mon Sep 17 00:00:00 2001 From: wuxinfei Date: Sun, 8 May 2022 12:48:35 +0800 Subject: [PATCH] feat: support custom RestartSec option on POSIX --- service.go | 4 +++- service_systemd_linux.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/service.go b/service.go index 5b564ea8..b893e4c7 100644 --- a/service.go +++ b/service.go @@ -86,6 +86,8 @@ const ( optionLimitNOFILE = "LimitNOFILE" optionLimitNOFILEDefault = -1 // -1 = don't set in configuration optionRestart = "Restart" + optionRestartSec = "RestartSec" + optionRestartSecDefault = 120 optionSuccessExitStatus = "SuccessExitStatus" @@ -186,6 +188,7 @@ func New(i Interface, c *Config) (Service, error) { // - PIDFile string () [/run/prog.pid] - Location of the PID file. // - LogOutput bool (false) - Redirect StdErr & StandardOutPath to files. // - Restart string (always) - How shall service be restarted. +// - RestartSec int (120) - Delay seconds before restarting the service. // - SuccessExitStatus string () - The list of exit status that shall be considered as successful, // in addition to the default ones. // - LogDirectory string(/var/log) - The path to the log files directory @@ -197,7 +200,6 @@ func New(i Interface, c *Config) (Service, error) { // - DelayedAutoStart bool (false) - After booting, start this service after some delay. // - Password string () - Password to use when interfacing with the system service manager. // - Interactive bool (false) - The service can interact with the desktop. (more information https://docs.microsoft.com/en-us/windows/win32/services/interactive-services) -// - DelayedAutoStart bool (false) - after booting start this service after some delay. // - StartType string ("automatic") - Start service type. (automatic | manual | disabled) // - OnFailure string ("restart" ) - Action to perform on service failure. (restart | reboot | noaction) // - OnFailureDelayDuration string ( "1s" ) - Delay before restarting the service, time.Duration string. diff --git a/service_systemd_linux.go b/service_systemd_linux.go index 45eafe3e..4607f0c0 100644 --- a/service_systemd_linux.go +++ b/service_systemd_linux.go @@ -168,6 +168,7 @@ func (s *systemd) Install() error { SuccessExitStatus string LogOutput bool LogDirectory string + RestartSec int }{ s.Config, path, @@ -179,6 +180,7 @@ func (s *systemd) Install() error { s.Option.string(optionSuccessExitStatus, ""), s.Option.bool(optionLogOutput, optionLogOutputDefault), s.Option.string(optionLogDirectory, defaultLogDirectory), + s.Option.int(optionRestartSec, optionRestartSecDefault), } err = s.template().Execute(f, to) @@ -316,7 +318,7 @@ StandardError=file:{{.LogDirectory}}/{{.Name}}.err {{if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{end}} {{if .Restart}}Restart={{.Restart}}{{end}} {{if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{end}} -RestartSec=120 +RestartSec={{.RestartSec}} EnvironmentFile=-/etc/sysconfig/{{.Name}} {{range $k, $v := .EnvVars -}}