Skip to content

Commit

Permalink
generate systemd: set --stop-timeout for stopping containers
Browse files Browse the repository at this point in the history
Make sure to always the stop timeout for unit generated via `--new`.

Fixes: containers#16149
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Oct 14, 2022
1 parent 0321165 commit ba276e1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions pkg/systemd/generate/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst
info.PIDFile = ""
info.ContainerIDFile = "%t/%n.ctr-id"
info.ExecStartPre = formatOptionsString("/bin/rm -f {{{{.ContainerIDFile}}}}")
info.ExecStop = formatOptionsString("{{{{.Executable}}}} stop --ignore --cidfile={{{{.ContainerIDFile}}}}")
info.ExecStopPost = formatOptionsString("{{{{.Executable}}}} rm -f --ignore --cidfile={{{{.ContainerIDFile}}}}")
info.ExecStop = formatOptionsString("{{{{.Executable}}}} stop --ignore {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} --cidfile={{{{.ContainerIDFile}}}}")
info.ExecStopPost = formatOptionsString("{{{{.Executable}}}} rm -f --ignore {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} --cidfile={{{{.ContainerIDFile}}}}")
// The create command must at least have three arguments:
// /usr/bin/podman run $IMAGE
index := 0
Expand Down
76 changes: 38 additions & 38 deletions pkg/systemd/generate/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ ExecStart=/usr/bin/podman container run \
--name jadda-jadda \
--hostname hello-world awesome-image:latest command arg1 ... argN "foo=arg \"with \" space"
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -333,11 +333,11 @@ ExecStart=/usr/bin/podman container run \
--name jadda-jadda \
--hostname hello-world awesome-image:latest command arg1 ... argN "foo=arg \"with \" space"
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -372,11 +372,11 @@ ExecStart=/usr/bin/podman container run \
--name jadda-jadda \
--hostname hello-world awesome-image:latest command arg1 ... argN "foo=arg \"with \" space"
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -411,11 +411,11 @@ ExecStart=/usr/bin/podman run \
--name jadda-jadda \
--hostname hello-world awesome-image:latest command arg1 ... argN
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -451,11 +451,11 @@ ExecStart=/usr/bin/podman run \
--name jadda-jadda \
--hostname hello-world awesome-image:latest command arg1 ... argN
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -490,11 +490,11 @@ ExecStart=/usr/bin/podman run \
--name jadda-jadda \
--hostname hello-world awesome-image:latest command arg1 ... argN
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -526,11 +526,11 @@ ExecStart=/usr/bin/podman run \
--sdnotify=conmon \
-d awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -565,11 +565,11 @@ ExecStart=/usr/bin/podman run \
detachparam +
` awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 42 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 42 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -607,11 +607,11 @@ ExecStart=/usr/bin/podman run \
-p 80:80 awesome-image:latest somecmd \
--detach=false
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 42 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 42 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -645,11 +645,11 @@ ExecStart=/usr/bin/podman \
--sdnotify=conmon \
-d awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 42 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 42 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -681,11 +681,11 @@ ExecStart=/usr/bin/podman container run \
--sdnotify=conmon \
-d awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -721,11 +721,11 @@ ExecStart=/usr/bin/podman run \
--log-driver=journald \
--log-opt=tag={{.Name}} awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -760,11 +760,11 @@ ExecStart=/usr/bin/podman run \
--name test awesome-image:latest sh \
-c "kill $$$$ && echo %%\\"
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -800,11 +800,11 @@ ExecStart=/usr/bin/podman run \
--conmon-pidfile=foo \
--cidfile=foo alpine
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -842,11 +842,11 @@ ExecStart=/usr/bin/podman run \
--cidfile=foo \
--pod-id-file /tmp/pod-foobar.pod-id-file alpine
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -883,11 +883,11 @@ ExecStart=/usr/bin/podman run \
--env=MYENV=2 \
-e USER awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -949,11 +949,11 @@ ExecStart=/usr/bin/podman run \
--sdnotify=conmon \
-d awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -986,11 +986,11 @@ ExecStart=/usr/bin/podman run \
-d \
-h hostname awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down Expand Up @@ -1024,11 +1024,11 @@ ExecStart=/usr/bin/podman run \
--sdnotify=conmon \
-d awesome-image:latest
ExecStop=/usr/bin/podman stop \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
-f \
--ignore \
--ignore -t 10 \
--cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
Expand Down

0 comments on commit ba276e1

Please sign in to comment.