testsAndMisc/docs/superpowers/evidence/atomic-install-live-scripts-2026-11-12.json
Krzysztof kuhy Rudnicki b57d5f9064 Install live scripts by atomic rename
The periodic setup wrote /usr/local/bin scripts with sed > target,
truncating the file in place. bash reads scripts lazily, so the running
hosts-file-monitor could execute a half-new file.

New lib/atomic_install.sh renders into a temp file beside the target,
syntax-checks it, sets mode/owner and renames it over the target (new
inode). A bad template fails closed and leaves the live file untouched.
Applied to the maintenance script, hosts monitor, browser wrapper and
auto-update script; the hosts monitor service is restarted if running.

Test: test_services_atomic_install.sh (inode changes, old inode keeps
old bytes, syntax error and missing template leave target untouched).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWYWDKuhbBAoNETfoB9
2026-11-12 12:59:59 +01:00

41 lines
1.7 KiB
JSON

{
"intent": "The periodic setup replaces live /usr/local/bin scripts by atomic rename, so a running hosts-file-monitor never executes a half-written file.",
"scope": [
"linux_configuration/periodic_background/lib/atomic_install.sh",
"linux_configuration/periodic_background/setup_periodic_system.sh",
"linux_configuration/periodic_background/lib/periodic_browser.sh",
"linux_configuration/periodic_background/lib/tests/test_services_atomic_install.sh",
"Non-goal: re-running the installer on the host"
],
"changes": [
"install_rendered_script renders to a temp file beside the target, bash -n, chmod/chown, mv -f",
"Maintenance script, hosts monitor, browser wrapper and auto-update script use it",
"restart_if_active restarts hosts-file-monitor.service after install"
],
"verification": [
{
"command": "lib/tests/test_services_atomic_install.sh",
"result": "pass",
"evidence": "red against in-place write (inode kept, old fd saw new bytes), 12 passed after"
},
{
"command": "vm run atomichosts guest_check.sh",
"result": "pass",
"evidence": "real hosts-file-monitor template under systemd: inode 85520 -> 85524, MainPID 745 -> 768, service active"
},
{
"command": "lib/tests/run_all.sh",
"result": "pass",
"evidence": "all check_and_enable_services test files passed"
}
],
"risks": [
"Temp file left in /usr/local/bin if the installer is killed between mktemp and mv",
"Restart briefly interrupts the hosts monitor"
],
"rollback": [
"git revert the commit; the old installer overwrites in place again",
"Check systemctl is-active hosts-file-monitor.service"
]
}