Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom RestartSec option on POSIX #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const (
optionLimitNOFILE = "LimitNOFILE"
optionLimitNOFILEDefault = -1 // -1 = don't set in configuration
optionRestart = "Restart"
optionRestartSec = "RestartSec"
optionRestartSecDefault = 120

optionSuccessExitStatus = "SuccessExitStatus"

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion service_systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (s *systemd) Install() error {
SuccessExitStatus string
LogOutput bool
LogDirectory string
RestartSec int
}{
s.Config,
path,
Expand All @@ -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)
Expand Down Expand Up @@ -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 -}}
Expand Down