Skip to content

Commit

Permalink
systemd on linux - add KillMode, KillSignal and TimeoutStopSec
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidik committed Dec 28, 2023
1 parent 9832e01 commit a645239
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit a645239

Please sign in to comment.