Repository navigation
Keep Dropbear alive during Supervisor and Docker shutdown - #4923
Conversation
๐ WalkthroughWalkthroughThe Dropbear systemd override adds ordering constraints so Dropbear stops after the supervisor and Docker services during teardown. ChangesDropbear shutdown ordering
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: Poem
๐ฅ Pre-merge checks | โ 5โ Passed checks (5 passed)
โจ Finishing Touches๐ Generate docstrings
๐งช Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
๐ค Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@buildroot-external/rootfs-overlay/usr/lib/systemd/system/dropbear.service.d/haos.conf`:
- Around line 4-8: Keep the existing Before=haos-supervisor.service
docker.service ordering, but revise the preceding comment to state that it
primarily preserves reverse shutdown ordering and does not serialize boot unless
the units start in the same transaction. Remove the claim that the shared mounts
add no boot work, and accurately describe the differing mount requirements
instead.
- Around line 17-21: Rewrite the comment above TimeoutStopSec=10s so it
describes only a 10-second upper bound or fallback for service shutdown, not a
guaranteed grace period for active sessions. Accurately note that KillMode=mixed
may terminate remaining session processes when Dropbear exits before the
timeout.
๐ช Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
โน๏ธ Review info
โ๏ธ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 07d3f285-7f24-45b0-8736-e791cda0dc26
๐ Files selected for processing (1)
buildroot-external/rootfs-overlay/usr/lib/systemd/system/dropbear.service.d/haos.conf
| # Systemd stops units in reverse start order, so ordering dropbear before the | ||
| # Supervisor and Docker keeps SSH available while their (potentially minutes | ||
| # long) teardown runs. Both already require the same mounts dropbear needs, so | ||
| # this adds no extra work to boot. | ||
| Before=haos-supervisor.service docker.service |
There was a problem hiding this comment.
๐ Performance & Scalability | ๐ก Minor | โก Quick win
๐งฉ Analysis chain
๐ Script executed:
#!/bin/sh
set -eu
echo "== repo files =="
git ls-files | rg 'dropbear|haos-supervisor|docker|systemd|buildroot-external/rootfs-overlay/usr/lib/systemd' || true
echo "== target file =="
if [ -f buildroot-external/rootfs-overlay/usr/lib/systemd/system/dropbear.service.d/haos.conf ]; then
cat -n buildroot-external/rootfs-overlay/usr/lib/systemd/system/dropbear.service.d/haos.conf
fi
echo "== related unit excerpts =="
for f in $(git ls-files | rg 'usr/lib/systemd/system/(dropbear|haos-supervisor|docker).service|buildroot-external/rootfs-overlay/usr/lib/systemd/system/(dropbear|haos-supervisor|docker).service'); do
if [ -f "$f" ]; then
echo "--- $f ---"
cat -n "$f"
fi
done
echo "== search RequiresMountsFor for mounts =="
rg -n "RequiresMountsFor|dropbear|haos-supervisor|docker.service|Before=|After=" buildroot-external/rootfs-overlay usr 2>/dev/null || trueRepository: home-assistant/operating-system
Length of output: 24905
Keep the order, adjust the boot rationale.
Before=haos-supervisor.service docker.service does not serialize those services unless they all need to start in the same systemd transaction; otherwise it only affects shutdown ordering. The โadds no extra work to bootโ wording is therefore misleading. Also, Dropbearโs mount is /etc/dropbear; Supervisor only requires /mnt/data, /mnt/boot, and /mnt/overlay, while Docker includes /etc/docker and /mnt/data.
๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@buildroot-external/rootfs-overlay/usr/lib/systemd/system/dropbear.service.d/haos.conf`
around lines 4 - 8, Keep the existing Before=haos-supervisor.service
docker.service ordering, but revise the preceding comment to state that it
primarily preserves reverse shutdown ordering and does not serialize boot unless
the units start in the same transaction. Remove the claim that the shared mounts
add no boot work, and accurately describe the differing mount requirements
instead.
| # With KillMode=mixed only the listener gets SIGTERM, so an open session keeps | ||
| # the cgroup alive until the stop timeout expires. Since dropbear is now the | ||
| # last thing stopped, that wait sits on the critical path of shutdown: keep it | ||
| # short instead of the default 90s. | ||
| TimeoutStopSec=10s |
There was a problem hiding this comment.
๐ฉบ Stability & Availability | ๐ก Minor | โก Quick win
๐งฉ Analysis chain
๐ Script executed:
#!/bin/sh
set -eu
echo "Files matching haos.conf:"
fd -a 'haos\.conf$' . || true
file="$(fd 'haos\.conf$' . | head -n1)"
if [ -n "${file:-}" ]; then
echo
echo "Content of $file:"
cat -n "$file"
fi
echo
echo "Search for dropbear systemd units/configs:"
rg -n "dropbear|KillMode|TimeoutStopSec|TimeoutStopUSec" . -g '!*.log' 2>/dev/null || true
echo
echo "Relevant file tree around possible systemd overlay path:"
fd . buildroot-external/rootfs-overlay/usr/lib/systemd/system 2>/dev/null | sed -n '1,80p' || trueRepository: home-assistant/operating-system
Length of output: 10772
๐ Web query:
man systemd.kill 5 KillMode mixed behavior SIGTERM TimeoutStopSec
๐ก Result:
When KillMode=mixed is configured in a systemd unit, the termination process follows a specific sequence designed to gracefully stop the main process while cleaning up any lingering processes within the unit's control group [1][2][3]. 1. Initial Signal: systemd sends the KillSignal (defaulting to SIGTERM) to the main process of the unit [1][2][3]. 2. Transition to SIGKILL: A subsequent SIGKILL (or the signal configured via FinalKillSignal) is sent to all remaining processes in the unit's control group if either of the following conditions is met [1][2][3]: - The main process exits [1][2][3]. - The time duration configured in TimeoutStopSec= has elapsed [1][2][3]. This behavior allows the main process to perform a clean shutdown upon receiving the initial signal, while ensuring that all other processes associated with the service are forcibly terminated either immediately upon the main process's exit or after the specified timeout period [1][2][3]. If SendSIGKILL= is enabled (the default), systemd ensures that any processes remaining in the control group are cleaned up [4][1][2]. If disabled, systemd will not necessarily restart the service if processes from the prior instance are still detected in the control group [4][1][2].
Citations:
- 1: https://dokk.org/manpages/debian/13/systemd/systemd.kill.5.en
- 2: https://manpages.ubuntu.com/manpages/resolute/man5/systemd.kill.5.html
- 3: https://manned.org/man/ubuntu-plucky/systemd.kill.5
- 4: https://man7.org/linux/man-pages/man5/systemd.kill.5.html
Do not describe TimeoutStopSec=10s as a guaranteed session grace period.
With KillMode=mixed, systemd sends SIGTERM to Dropbearโs main process and can forcibly terminate remaining cgroup processes as soon as that process exits; TimeoutStopSec is only the fallback when shutdown has not completed. Active SSH sessions may therefore be killed immediately rather than after 10 seconds.
If the intent is only a 10-second upper bound, rewrite the comment accordingly. If a 10-second graceful window is required, verify Dropbearโs shutdown behavior and consider a kill mode that signals session processes as well.
๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@buildroot-external/rootfs-overlay/usr/lib/systemd/system/dropbear.service.d/haos.conf`
around lines 17 - 21, Rewrite the comment above TimeoutStopSec=10s so it
describes only a 10-second upper bound or fallback for service shutdown, not a
guaranteed grace period for active sessions. Accurately note that KillMode=mixed
may terminate remaining session processes when Dropbear exits before the
timeout.
Dropbear has no ordering relationship to haos-supervisor.service or docker.service, so systemd schedules all three stop jobs in the same batch and runs them concurrently. Dropbear exits within milliseconds while the Supervisor gets up to 450s to stop containers, which means an SSH session is dropped right when the interesting part of shutdown starts. That makes it needlessly hard to debug slow shutdowns. Order Dropbear before both units. Since stop order is the reverse of start order, systemd now stops it only once the Supervisor and Docker are gone. This is an ordering-only dependency: if Dropbear fails, is masked or is skipped by its ConditionFileNotEmpty=, the ordering counts as satisfied and both units start as before. It adds no boot latency either, as docker.service already waits for the overlay partition that Dropbear needs for /etc/dropbear. Verified on a generic-x86-64 VM: an SSH session now survives the full 22.4s Supervisor teardown, and systemd stops Dropbear last, 3ms after docker.service is gone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
f95e5fc to
8d6bbc7
Compare
Verification on hardwareTested on a generic-x86-64 VM with an SSH session on port 22222 running Stop orderingFrom the persisted journal of the previous boot ( Both ordering edges hold: Dropbear is stopped last, 3ms after Timings
All 22.4s of the Supervisor teardown is now observable over SSH. An earlier revision of this PR also set
|
There was a problem hiding this comment.
Pull request overview
This PR adjusts systemd unit ordering so dropbear.service remains running until haos-supervisor.service and docker.service have stopped, keeping SSH available during potentially long container/supervisor shutdown. It also reduces Dropbearโs shutdown critical-path time by lowering its stop timeout.
Changes:
- Add an ordering-only relationship:
dropbear.serviceis ordered before Supervisor and Docker so it stops after them at shutdown. - Set
TimeoutStopSec=10sfor Dropbear to avoid long shutdown delays when active SSH sessions keep the unit cgroup populated underKillMode=mixed.
๐ก Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Dropbear has no ordering relationship to haos-supervisor.service or docker.service, so systemd schedules all three stop jobs in the same batch and runs them concurrently. Dropbear exits within milliseconds while the Supervisor gets up to 450s to stop containers, which means an SSH session is dropped right when the interesting part of shutdown starts. That makes it needlessly hard to debug slow shutdowns. Order Dropbear before both units. Since stop order is the reverse of start order, systemd now stops it only once the Supervisor and Docker are gone. This is an ordering-only dependency: if Dropbear fails, is masked or is skipped by its ConditionFileNotEmpty=, the ordering counts as satisfied and both units start as before. It adds no boot latency either, as docker.service already waits for the overlay partition that Dropbear needs for /etc/dropbear. Verified on a generic-x86-64 VM: an SSH session now survives the full 22.4s Supervisor teardown, and systemd stops Dropbear last, 3ms after docker.service is gone. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Description
dropbear.servicehas no ordering relationship tohaos-supervisor.serviceordocker.service, so systemd schedules all three stop jobs in the same batch and runs them concurrently. Dropbear exits within milliseconds while the Supervisor gets up to 450s to stop containers (ExecStop=docker stop -t 420), so an SSH session is dropped right when the interesting part of shutdown starts. That makes it needlessly hard to debug slow shutdowns.This orders Dropbear before both units. Since stop order is the reverse of start order, systemd now stops it only once the Supervisor and Docker are gone.
Notes on safety:
ConditionFileNotEmpty=/root/.ssh/authorized_keys, the ordering counts as satisfied and both units start as before.docker.servicealready waits for the overlay partition that Dropbear needs for/etc/dropbear./mnt/overlayis a separate partition withDefaultDependencies=no, and nothing below it depends on Docker. Verified withsystemd-analyze verifyagainst a built rootfs.This only covers the unit-stop phase. Unmounting
/mnt/dataand the finalsystemd-shutdownphase still happen after Dropbear is gone, since its own mount dependencies have to be released first. Covering those would needDefaultDependencies=no+IgnoreOnIsolate=yes(debug-shell style), which is both riskier and a poor instrument โ the live session's cwd on/mnt/datawould itself become an unmount blocker. That phase is better observed on the console withsystemd.log_level=debug.Verified on hardware โ see the comment below for the timings.
๐ค Generated with Claude Code
Summary by CodeRabbit