Skip to content

rootless: prevent the service hanging when stopping (set systemd KillMode to mixed)#41947

Merged
thaJeztah merged 1 commit into
moby:masterfrom
AkihiroSuda:rootless-kill-mode-mixed
Jan 28, 2021
Merged

rootless: prevent the service hanging when stopping (set systemd KillMode to mixed)#41947
thaJeztah merged 1 commit into
moby:masterfrom
AkihiroSuda:rootless-kill-mode-mixed

Conversation

@AkihiroSuda

@AkihiroSuda AkihiroSuda commented Jan 28, 2021

Copy link
Copy Markdown
Member

- What I did
Fix #41944 ("Docker rootless does not exit properly if containers are running")

Now systemctl --user stop docker completes just with in 1 or 2 seconds.

- How I did it
Changed the KillMode from "control-group" (default) to "mixed"

See systemd.kill(5) https://www.freedesktop.org/software/systemd/man/systemd.kill.html

Specifies how processes of this unit shall be killed. One of control-group, mixed, process, none.

If set to control-group, all remaining processes in the control group of this unit will be killed on unit stop (for services: after the stop command is executed, as configured with ExecStop=). If set to mixed, the SIGTERM signal (see below) is sent to the main process while the subsequent SIGKILL signal (see below) is sent to all remaining processes of the unit's control group. If set to process, only the main process itself is killed (not recommended!). If set to none, no process is killed (strongly recommended against!). In this case, only the stop command will be executed on unit stop, but no process will be killed otherwise. Processes remaining alive after stop are left in their control group and the control group continues to exist after stop unless empty.

Note that it is not recommended to set KillMode= to process or even none, as this allows processes to escape the service manager's lifecycle and resource management, and to remain running even while their service is considered stopped and is assumed to not consume any resources.

Processes will first be terminated via SIGTERM (unless the signal to send is changed via KillSignal= or RestartKillSignal=). Optionally, this is immediately followed by a SIGHUP (if enabled with SendSIGHUP=). If processes still remain after the main process of a unit has exited or the delay configured via the TimeoutStopSec= has passed, the termination request is repeated with the SIGKILL signal or the signal specified via FinalKillSignal= (unless this is disabled via the SendSIGKILL= option). See kill(2) for more information.

Defaults to control-group.

"mixed" is available since systemd 209 (2014-02-20) https://github.com/systemd/systemd/blob/57353d2909e503e3e5c7e69251ba95a31e1a72ce/NEWS#L9318

- How to verify it

Run some containers with rootless, and make sure systemctl --user stop docker.service completes in a few seconds.

$ docker --context=rootless run --name nginx -d -p 8080:80 --restart=always nginx:alpine
$ time systemctl --user stop docker

real    0m1.266s
user    0m0.005s
sys     0m0.000s

- Description for the changelog

rootless: prevent the service hanging when stopping (set systemd KillMode to mixed)

- A picture of a cute animal (not mandatory but encouraged)

🐧

Now `systemctl --user stop docker` completes just with in 1 or 2 seconds.

Fix issue 41944 ("Docker rootless does not exit properly if containers are running")

See systemd.kill(5) https://www.freedesktop.org/software/systemd/man/systemd.kill.html

Signed-off-by: Akihiro Suda <[email protected]>
TasksMax=infinity
Delegate=yes
Type=simple
KillMode=mixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does/should rootless mode support "live-restore"? ISTR we use "process" in the regular systemd unit because of that; https://github.com/docker/docker-ce-packaging/blob/master/systemd/docker.service#L43

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, at least for now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"process" does seem more correct eventually, but mixed sounds good for now 👍

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@tianon ptal

@WhyNotHugo

Copy link
Copy Markdown
Contributor

Minor nitpick: the changelog entry should describe what is done, not how it's done. E.g.:

rootless: prevent the service hanging when stopping

@AkihiroSuda AkihiroSuda changed the title rootless: set systemd KillMode to mixed rootless: prevent the service hanging when stopping (set systemd KillMode to mixed) Jan 28, 2021
@AkihiroSuda

Copy link
Copy Markdown
Member Author

updated PR description, thanks for suggestion

@tianon tianon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@thaJeztah

Copy link
Copy Markdown
Member

s390x failure is unrelated; rootless CI is green. I consider it not worth restarting CI for that

@thaJeztah
thaJeztah merged commit 3c3a2ff into moby:master Jan 28, 2021
@WhyNotHugo

Copy link
Copy Markdown
Contributor

Thanks!

@AkihiroSuda

Copy link
Copy Markdown
Member Author

This was not included in v20.10.3. Proposing to v20.10.4 in #41956.

@thaJeztah thaJeztah added this to the 21.xx milestone Feb 2, 2021
pastleo pushed a commit to pastleo/aur-docker-rootless-extra-bin that referenced this pull request Jul 16, 2021
The service was not stopping correctly when containers are running.

See upstream:

- moby/moby#41944
- moby/moby#41947
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker rootless does not exit properly if containers are running

4 participants