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

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
This commit is contained in:
Dragonish committed 2026-11-25 17:31:37 +00:00
1 parent 4a7189c067
commit 567e9cca7c
16 files changed
+917 -6

No files matched your search

+118 -1
View File
@@ -90,6 +90,119 @@
that: "'docker' in docker_verify_groups.stdout.split()"
quiet: true
# The two units: installed, enabled, ordered as the role promises, and the shutdown unit running (its stop action runs only for an
# active unit). Their behaviour at a real boot or shutdown cannot be shown here: the container has no dockerd, no NFS and no reboot, and the
# shutdown script is not run because the container shares the runner's cgroup tree.
- name: Verify the boot and shutdown units
hosts: all
gather_facts: false
vars:
docker_verify_units: [docker-start-missed, docker-stop-at-shutdown]
tasks:
- name: Stat the scripts and the unit files
ansible.builtin.stat:
path: "{{ item }}"
loop:
- /usr/local/sbin/docker-start-missed
- /usr/local/sbin/docker-stop-at-shutdown
- /etc/systemd/system/docker-start-missed.service
- /etc/systemd/system/docker-stop-at-shutdown.service
register: docker_verify_unit_files
- name: The scripts are executable and the unit files are not
ansible.builtin.assert:
that:
- docker_verify_unit_files.results | map(attribute='stat.exists') | unique | list == [true]
- docker_verify_unit_files.results[0].stat.mode == "0755"
- docker_verify_unit_files.results[1].stat.mode == "0755"
- docker_verify_unit_files.results[2].stat.mode == "0644"
- docker_verify_unit_files.results[3].stat.mode == "0644"
quiet: true
- name: Ask systemd about the units
ansible.builtin.command:
argv:
- systemctl
- show
- --property=UnitFileState,ActiveState,After,Before
- "{{ item }}.service"
loop: "{{ docker_verify_units }}"
register: docker_verify_unit_show
changed_when: false
- name: Both units are enabled
ansible.builtin.assert:
that: "'UnitFileState=enabled' in item.stdout"
quiet: true
loop: "{{ docker_verify_unit_show.results }}"
- name: The boot unit starts after docker, the shutdown unit stops before it
ansible.builtin.assert:
that:
- "'docker.service' in (docker_verify_unit_show.results[0].stdout | regex_search('After=.*'))"
- "'docker.service' in (docker_verify_unit_show.results[1].stdout | regex_search('Before=.*'))"
- "'network-online.target' in (docker_verify_unit_show.results[1].stdout | regex_search('After=.*'))"
- "'remote-fs.target' in (docker_verify_unit_show.results[1].stdout | regex_search('After=.*'))"
quiet: true
- name: The shutdown unit is active, which is what lets its stop action run
ansible.builtin.assert:
that: "'ActiveState=active' in docker_verify_unit_show.results[1].stdout"
quiet: true
- name: Read the shutdown unit
ansible.builtin.slurp:
src: /etc/systemd/system/docker-stop-at-shutdown.service
register: docker_verify_stop_unit
- name: The timeout the converge set reaches the unit
ansible.builtin.assert:
that:
- "'Environment=DOCKER_STOP_TIMEOUT=20' in (docker_verify_stop_unit.content | b64decode)"
- "'TimeoutStopSec=50' in (docker_verify_stop_unit.content | b64decode)"
quiet: true
- name: The start script refuses an option it does not know
ansible.builtin.command: /usr/local/sbin/docker-start-missed --no-such-option
register: docker_verify_start_run
changed_when: false
failed_when: docker_verify_start_run.rc != 2
# Switching an input back to false removes that unit and script and leaves the other alone.
- name: Verify that a unit is removed when its input is false
hosts: all
vars:
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
docker_repo_base_url: file:///srv/docker-stub-repo
docker_users: [moleculeuser]
docker_start_missed: false
docker_stop_at_shutdown: true
docker_stop_at_shutdown_timeout: 20
tasks:
- name: Apply the role with the boot unit off
ansible.builtin.include_role:
name: mortis.kamino.docker
- name: Stat the boot unit's files and the shutdown unit's script
ansible.builtin.stat:
path: "{{ item }}"
loop:
- /usr/local/sbin/docker-start-missed
- /etc/systemd/system/docker-start-missed.service
- /usr/local/sbin/docker-stop-at-shutdown
register: docker_verify_off
- name: The boot unit is gone and the shutdown unit is still there
ansible.builtin.assert:
that: docker_verify_off.results | map(attribute='stat.exists') | list == [false, false, true]
quiet: true
- name: Apply the role again with both inputs on
ansible.builtin.include_role:
name: mortis.kamino.docker
vars:
docker_start_missed: true
# docker_remove_data is set, so this also covers the destructive path: the packages are
# purged and /var/lib/docker, seeded in prepare.yml, is deleted. The removal stops the unit
# before the package takes it away, so it can only run once; a second run would fail on the
@@ -114,9 +227,13 @@
- /etc/apt/keyrings/docker.asc
- /var/lib/docker
- /usr/lib/systemd/system/docker.service
- /usr/local/sbin/docker-start-missed
- /usr/local/sbin/docker-stop-at-shutdown
- /etc/systemd/system/docker-start-missed.service
- /etc/systemd/system/docker-stop-at-shutdown.service
register: docker_verify_gone
- name: The source list, the keyring, the data and the unit are gone
- name: The source list, the keyring, the data, the unit and the two extra units are gone
ansible.builtin.assert:
that: docker_verify_gone.results | map(attribute='stat.exists') | unique | list == [false]
quiet: true