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

systemd on linux - add KillMode, KillSignal and TimeoutStopSec #387

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions service.go
Expand Up @@ -86,6 +86,9 @@ const (
optionLimitNOFILE = "LimitNOFILE"
optionLimitNOFILEDefault = -1 // -1 = don't set in configuration
optionRestart = "Restart"
optionKillMode = "KillMode"
optionKillSignal = "KillSignal"
optionTimeoutStopSec = "TimeoutStopSec"

optionSuccessExitStatus = "SuccessExitStatus"

Expand Down
11 changes: 10 additions & 1 deletion service_systemd_linux.go
Expand Up @@ -172,6 +172,9 @@ func (s *systemd) Install() error {
SuccessExitStatus string
LogOutput bool
LogDirectory string
KillMode string
KillSignal string
TimeoutStopSec string
}{
s.Config,
path,
Expand All @@ -183,6 +186,9 @@ func (s *systemd) Install() error {
s.Option.string(optionSuccessExitStatus, ""),
s.Option.bool(optionLogOutput, optionLogOutputDefault),
s.Option.string(optionLogDirectory, defaultLogDirectory),
s.Option.string(optionKillMode, ""),
s.Option.string(optionKillSignal, ""),
s.Option.string(optionTimeoutStopSec, ""),
}

err = s.template().Execute(f, to)
Expand Down Expand Up @@ -301,7 +307,7 @@ func (s *systemd) runAction(action string) error {
const systemdScript = `[Unit]
Description={{.Description}}
ConditionFileIsExecutable={{.Path|cmdEscape}}
{{range $i, $dep := .Dependencies}}
{{range $i, $dep := .Dependencies}}
{{$dep}} {{end}}

[Service]
Expand All @@ -322,6 +328,9 @@ StandardError=file:{{.LogDirectory}}/{{.Name}}.err
{{if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{end}}
RestartSec=120
EnvironmentFile=-/etc/sysconfig/{{.Name}}
{{if .KillMode }}KillMode={{.KillMode}}{{end}}
{{if .KillSignal }}KillSignal={{.KillSignal}}{{end}}
{{if .TimeoutStopSec }}TimeoutStopSec={{.TimeoutStopSec}}{{end}}

{{range $k, $v := .EnvVars -}}
Environment={{$k}}={{$v}}
Expand Down