summaryrefslogtreecommitdiff
path: root/pkg/systemd/generate/containers.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/systemd/generate/containers.go')
-rw-r--r--pkg/systemd/generate/containers.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go
index 78b81b54b..66cf5ca44 100644
--- a/pkg/systemd/generate/containers.go
+++ b/pkg/systemd/generate/containers.go
@@ -16,6 +16,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
+ "golang.org/x/sys/unix"
)
// containerInfo contains data required for generating a container's systemd
@@ -32,6 +33,8 @@ type containerInfo struct {
// StopTimeout sets the timeout Podman waits before killing the container
// during service stop.
StopTimeout uint
+ // KillSignal of the container.
+ KillSignal string
// RestartPolicy of the systemd unit (e.g., no, on-failure, always).
RestartPolicy string
// PIDFile of the service. Required for forking services. Must point to the
@@ -102,6 +105,9 @@ Environment={{{{- range $index, $value := .ExtraEnvs -}}}}{{{{if $index}}}} {{{{
{{{{- end}}}}
Restart={{{{.RestartPolicy}}}}
TimeoutStopSec={{{{.TimeoutStopSec}}}}
+{{{{- if .KillSignal}}}}
+KillSignal={{{{.KillSignal}}}}
+{{{{- end}}}}
{{{{- if .ExecStartPre}}}}
ExecStartPre={{{{.ExecStartPre}}}}
{{{{- end}}}}
@@ -184,6 +190,13 @@ func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSyste
containerEnv: envs,
}
+ // Set a custom kill signal for non SIGTERM (already default in
+ // systemd) signals.
+ stopSignal := ctr.StopSignal()
+ if stopSignal != uint(unix.SIGTERM) {
+ info.KillSignal = fmt.Sprintf("%d", stopSignal)
+ }
+
return &info, nil
}
@@ -359,7 +372,15 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst
info.ExecStart = strings.Join(startCommand, " ")
}
- info.TimeoutStopSec = minTimeoutStopSec + info.StopTimeout
+ info.TimeoutStopSec = info.StopTimeout
+
+ // For units without --new add an additional 60 seconds to the stop
+ // timeout to make sure that Podman stop has enough time to properly
+ // shutdown and cleanup the container before systemd starts to nuke
+ // everything in the cgroup.
+ if !options.New {
+ info.TimeoutStopSec += minTimeoutStopSec
+ }
if info.PodmanVersion == "" {
info.PodmanVersion = version.Version.String()