Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate systemd: set --stop-timeout for stopping containers #16176

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}}}}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this for rm? The container should already be stopped here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. ExecStop is not being executed when the mainPID got killed, so in theory the container should be dead at that point. In practice, it doesn't hurt to make extra sure.

// 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