Skip to content

Commit

Permalink
Merge pull request #589 from jnummelin/backport-fix-systemd-killmode
Browse files Browse the repository at this point in the history
Backport #588 into release-0.9
  • Loading branch information
jnummelin authored Dec 29, 2020
2 parents 09d315f + 9c30a01 commit 6ba1866
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion pkg/install/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func EnsureService(args []string) error {
case "linux-openrc":
deps = []string{"need net", "use dns", "after firewall"}
case "linux-systemd":
deps = []string{"After=network.target", "KillMode=process"}
deps = []string{"After=network.target"}
svcConfig.Option = map[string]interface{}{
"SystemdScript": systemdScript,
}
default:
}

Expand All @@ -72,3 +75,34 @@ func EnsureService(args []string) error {
}
return nil
}

// Upstream kardianos/service does not support all the options we want to set to the systemd unit, hence we override the template
// Currently mostly for KillMode=process so we get systemd to only send the sigterm to the main process
const systemdScript = `[Unit]
Description={{.Description}}
ConditionFileIsExecutable={{.Path|cmdEscape}}
{{range $i, $dep := .Dependencies}}
{{$dep}} {{end}}
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}}
{{if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{end}}
{{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{end}}
{{if .UserName}}User={{.UserName}}{{end}}
{{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}}
{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}}
{{if and .LogOutput .HasOutputFileSupport -}}
StandardOutput=file:/var/log/{{.Name}}.out
StandardError=file:/var/log/{{.Name}}.err
{{- end}}
{{if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{end}}
{{if .Restart}}Restart={{.Restart}}{{end}}
{{if .SuccessExitStatus}}SuccessExitStatus={{.SuccessExitStatus}}{{end}}
RestartSec=120
EnvironmentFile=-/etc/sysconfig/{{.Name}}
KillMode=process
[Install]
WantedBy=multi-user.target
`

0 comments on commit 6ba1866

Please sign in to comment.