From 4417c3fb0ac52ace3b5ba35410daabb1b60c622b Mon Sep 17 00:00:00 2001 From: avoidik Date: Thu, 28 Dec 2023 14:04:20 +0000 Subject: [PATCH] systemd on linux - add KillMode, KillSignal and TimeoutStopSec --- service.go | 3 +++ service_systemd_linux.go | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index 904835e0..0c93fa49 100644 --- a/service.go +++ b/service.go @@ -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" diff --git a/service_systemd_linux.go b/service_systemd_linux.go index 0b1b0594..c0c8db16 100644 --- a/service_systemd_linux.go +++ b/service_systemd_linux.go @@ -172,6 +172,9 @@ func (s *systemd) Install() error { SuccessExitStatus string LogOutput bool LogDirectory string + KillMode string + KillSignal string + TimeoutStopSec string }{ s.Config, path, @@ -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) @@ -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] @@ -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}}