From e5c3432944245a740ed443803c654dcc9c3757f0 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 17 Jun 2020 14:48:19 +0200 Subject: generate systemd: `ExecStopPost` for all units Add an `ExecStopPost` run even for units generated without `--new`. Although it may seem redundant to run `container/pod stop` twice at first glance, we really need the post run. If the main PID (i.e., conmon) is killed, systemd will not execute `ExecStop` but only the post one. We made this obeservation in a customer issue and could reproduce the behavior consistently. Hence, the post run is needed to properly clean up when conmon is killed and it's pretty much a NOP in all other cases. Credits to Ulrich Obergfell for throrough and detailed analyses, which ultimately lead to this fix. Signed-off-by: Valentin Rothberg --- pkg/systemd/generate/containers.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pkg/systemd/generate/containers.go') diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index 4180022cb..16ff0b821 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -83,9 +83,7 @@ ExecStartPre={{.ExecStartPre}} {{- end}} ExecStart={{.ExecStart}} ExecStop={{.ExecStop}} -{{- if .ExecStopPost}} ExecStopPost={{.ExecStopPost}} -{{- end}} PIDFile={{.PIDFile}} KillMode=none Type=forking @@ -170,6 +168,7 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst info.EnvVariable = EnvVariable info.ExecStart = "{{.Executable}} start {{.ContainerNameOrID}}" info.ExecStop = "{{.Executable}} stop {{if (ge .StopTimeout 0)}}-t {{.StopTimeout}}{{end}} {{.ContainerNameOrID}}" + info.ExecStopPost = "{{.Executable}} stop {{if (ge .StopTimeout 0)}}-t {{.StopTimeout}}{{end}} {{.ContainerNameOrID}}" // Assemble the ExecStart command when creating a new container. // -- cgit v1.2.3-54-g00ecf