feat(docker): add opt-in boot and shutdown units for hosts that run Docker with live-restore #371

Open
Dragonish wants to merge 1 commits from feat/369-docker-boot-shutdown-units into main
pull from: feat/369-docker-boot-shutdown-units
Collaborator

What and why

Adds two opt-in inputs to the docker role for a host that runs Docker with live-restore. Both default to false, so a host that does not set them is unchanged.

  • docker_start_missed (with docker_start_missed_settle_seconds): a boot unit, docker-start-missed.service, starts the containers dockerd's restore pass skipped after a reboot of the whole host. It starts a container only if its restart policy is unless-stopped or always, it exited with code 255, and it finished after this boot began, so a container stopped on purpose stays stopped. Type=simple, so it never delays or fails the boot.
  • docker_stop_at_shutdown (with docker_stop_at_shutdown_timeout): a RemainAfterExit unit whose stop action runs at shutdown after docker.service has stopped and before the network and remote file systems. It sends SIGTERM to every container process, waits up to the timeout, then SIGKILL. It never calls docker stop or docker kill (both set the manually-stopped marker). The role starts the unit, because systemd runs a stop action only for an active unit.

Both units carry ConditionPathExists=/usr/bin/docker, are installed only on a host the docker role is applied to, and are removed when their input goes back to false or with docker_remove. The role never stops a running shutdown unit, because stopping it runs its stop action and ends every container. Both scripts are in roles/docker/files/.

Both scripts are commands installed on the host and run by systemd, so ansible-test sanity rejects their shebang as non-module: two entries with that reason are added to tests/sanity/ignore-common.txt (under CODEOWNERS, so they need your review).

Closes #369

Verified

  • pre-commit hooks on the commit: yamllint, ruff, shellcheck, REUSE, changelog fragment lint, ansible-lint, conventional commit, agent trailer.
  • python3 -m unittest discover -s tests/scripts -p 'test_docker_files.py': 23 tests, covering which containers docker-start-missed selects (policy, exit code, finish time against the boot time, nanosecond timestamps, restarting and never-started containers), its exit codes when Docker fails or answers oddly, and that docker-stop-at-shutdown has no docker stop or docker kill outside comments.
  • The process listing of the shutdown script on a fake cgroup tree: PID 0 is dropped, processes in child cgroups are included.
  • An independent read-only review of this diff; its findings (a Molecule task that could signal the wrong processes, PID 0, child cgroups, the boot ordering, unproven claims about when a changed unit takes effect) are fixed in this commit.
  • The Molecule scenario is extended (units installed, enabled, ordered against docker.service, shutdown unit active, timeout in the unit, a unit removed when its input is false, removal with docker_remove, docker_stop_at_shutdown_timeout: 0 refused). Its result is the Molecule check on this PR.

Not verified

  • What the units do at a real boot or shutdown. The Molecule container has no dockerd, no NFS shares and no reboot, and the shutdown script is not run there because the container shares the runner's cgroup tree. An earlier version of the shutdown unit, before the review fixes in this commit, ran on a Docker host with live-restore outside this repository: a shutdown that took 181.6 s with a container holding NFS mounts took about 8 s with it. The version in this PR was not run there.
  • What systemd does with an active unit whose file is removed or changed. The role never stops it, and the docs say so without claiming more.
  • The shutdown script reads the systemd cgroup driver's layout on cgroup v2. On another layout it finds nothing and logs that; this is stated in the README.
  • Ordering the shutdown unit before docker.service also applies at boot (Docker waits for network-online.target and remote-fs.target). Documented, not measured.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code

## What and why Adds two opt-in inputs to the `docker` role for a host that runs Docker with `live-restore`. Both default to `false`, so a host that does not set them is unchanged. - `docker_start_missed` (with `docker_start_missed_settle_seconds`): a boot unit, `docker-start-missed.service`, starts the containers dockerd's restore pass skipped after a reboot of the whole host. It starts a container only if its restart policy is `unless-stopped` or `always`, it exited with code 255, and it finished after this boot began, so a container stopped on purpose stays stopped. `Type=simple`, so it never delays or fails the boot. - `docker_stop_at_shutdown` (with `docker_stop_at_shutdown_timeout`): a `RemainAfterExit` unit whose stop action runs at shutdown after `docker.service` has stopped and before the network and remote file systems. It sends SIGTERM to every container process, waits up to the timeout, then SIGKILL. It never calls `docker stop` or `docker kill` (both set the manually-stopped marker). The role starts the unit, because systemd runs a stop action only for an active unit. Both units carry `ConditionPathExists=/usr/bin/docker`, are installed only on a host the `docker` role is applied to, and are removed when their input goes back to `false` or with `docker_remove`. The role never stops a running shutdown unit, because stopping it runs its stop action and ends every container. Both scripts are in `roles/docker/files/`. Both scripts are commands installed on the host and run by systemd, so `ansible-test sanity` rejects their shebang as non-module: two entries with that reason are added to `tests/sanity/ignore-common.txt` (under `CODEOWNERS`, so they need your review). Closes #369 ## Verified - `pre-commit` hooks on the commit: yamllint, ruff, shellcheck, REUSE, changelog fragment lint, ansible-lint, conventional commit, agent trailer. - `python3 -m unittest discover -s tests/scripts -p 'test_docker_files.py'`: 23 tests, covering which containers `docker-start-missed` selects (policy, exit code, finish time against the boot time, nanosecond timestamps, restarting and never-started containers), its exit codes when Docker fails or answers oddly, and that `docker-stop-at-shutdown` has no `docker stop` or `docker kill` outside comments. - The process listing of the shutdown script on a fake cgroup tree: PID 0 is dropped, processes in child cgroups are included. - An independent read-only review of this diff; its findings (a Molecule task that could signal the wrong processes, PID 0, child cgroups, the boot ordering, unproven claims about when a changed unit takes effect) are fixed in this commit. - The Molecule scenario is extended (units installed, enabled, ordered against `docker.service`, shutdown unit active, timeout in the unit, a unit removed when its input is `false`, removal with `docker_remove`, `docker_stop_at_shutdown_timeout: 0` refused). Its result is the Molecule check on this PR. ## Not verified - What the units do at a real boot or shutdown. The Molecule container has no dockerd, no NFS shares and no reboot, and the shutdown script is not run there because the container shares the runner's cgroup tree. An earlier version of the shutdown unit, before the review fixes in this commit, ran on a Docker host with `live-restore` outside this repository: a shutdown that took 181.6 s with a container holding NFS mounts took about 8 s with it. The version in this PR was not run there. - What systemd does with an active unit whose file is removed or changed. The role never stops it, and the docs say so without claiming more. - The shutdown script reads the systemd cgroup driver's layout on cgroup v2. On another layout it finds nothing and logs that; this is stated in the README. - Ordering the shutdown unit before `docker.service` also applies at boot (Docker waits for `network-online.target` and `remote-fs.target`). Documented, not measured. --- - [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code
Dragonish added 1 commit 2026-11-25 17:32:31 +00:00
feat(docker): add opt-in boot and shutdown units for hosts that run Docker with live-restore
Build / build (pull_request) Successful in 27s
Lint / lint (pull_request) Successful in 2m15s
Molecule / molecule (pull_request) Successful in 4m17s
567e9cca7c
docker_start_missed installs a boot unit that starts the containers dockerd's
restore pass skipped after a reboot of the whole host. docker_stop_at_shutdown
installs a unit that ends container processes at shutdown while the network and
NFS shares are still up, so a container holding an NFS mount no longer stalls
the shutdown. Both default to false and do nothing without /usr/bin/docker.

Refs #369

Assisted-by: Claude Code
CODEOWNERS rules requested review from Defame1297 2026-11-25 17:32:31 +00:00
All checks were successful
Build / build (pull_request) Successful in 27s
Required
Details
Lint / lint (pull_request) Successful in 2m15s
Required
Details
Molecule / molecule (pull_request) Successful in 4m17s
Required
Details
This pull request has official review requests.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/369-docker-boot-shutdown-units:feat/369-docker-boot-shutdown-units
git checkout feat/369-docker-boot-shutdown-units
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#371