Enable user lingering so the systemd user bus survives sessions#73
Open
robobryce wants to merge 1 commit into
Open
Enable user lingering so the systemd user bus survives sessions#73robobryce wants to merge 1 commit into
robobryce wants to merge 1 commit into
Conversation
Run `loginctl enable-linger` for the bootstrapping user as part of host setup. Without it the per-user systemd instance — and its bus at $XDG_RUNTIME_DIR/bus — is torn down when the login session ends, so an agent reconnecting over a fresh SSH session finds no user bus. Unattended workloads that wrap commands in `systemd-run --user --scope` depend on that bus. autocuda's `run slice`, which caps each build's CPU/memory in a per-worker scope, exits 2 with "user systemd bus not found" and points the operator at `loginctl enable-linger` — making every autocuda host re-run the same manual fix. Doing it here removes that step. enable_user_linger skips cleanly where the setup cannot or need not run: no loginctl (bare container), lingering already on (idempotent re-run), or a non-root user without passwordless sudo (warns with the manual command). Covered by bats unit tests for every branch and an e2e assertion whose skip conditions mirror the function's.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Enable user lingering (
loginctl enable-linger <user>) as a default host-setup step, in a newenable_user_lingerfunction called frommain()right afterinstall_base_deps.Why
AAB sets up hosts where an agent runs unattended across SSH sessions that come and go. Without lingering, the per-user systemd instance — and its bus at
$XDG_RUNTIME_DIR/bus— is torn down when the login session ends, so the next session finds no user bus.Workloads that wrap commands in
systemd-run --user --scopeneed that bus.autocuda run slicecaps each build's CPU/memory in a per-worker scope; with no user bus it exits 2 withuser systemd bus not found at /run/user/<uid>/busand points the operator atsudo loginctl enable-linger $USER. That makes every autocuda host re-run the same manual fix on first use. Doing it in the bootstrap removes the step — slice-mode builds work out of the box, while exclusive-mode commands (which don't need the bus) were already fine.How
enable_user_lingeris idempotent and degrades gracefully — it mirrors the sudo-awareness ofinstall_base_deps/update_etc_environment:loginctl(bare container, no systemd): logs and skips.Running as root or with passwordless sudo (the documented AAB requirement), it just enables lingering.
Test plan
./test.bash(lint + unit) — shellcheck clean; 113/113 bats pass, including 5 newenable_user_lingertests (one per branch above):./test.bash --docker— full bootstrap end-to-end in a freshubuntu:22.04(no systemd), run + re-run for idempotency. The skip path fires on both runs and the new assertion Add unit tests and GitHub actions for CI #14 passes both times:./test.bash --secrets(gitleaks v8.18.4) — both history and working-tree passes clean:bootstrap.bashand ranenable_user_lingerdirectly on a host where lingering is already on (the no-op branch), plus assertion Add unit tests and GitHub actions for CI #14's positive branch:./test.bash --smoke— N/A: no inference-path or launcher change; this PR only adds a host-setup step and its tests.Docs
README.mdupdated in the same change: a new item in What It Sets Up (with the bare-container caveat) and a/var/lib/systemd/linger/<user>row in What the Script Touches.