Make the systemd units declarative - #22
Merged
Merged
Conversation
update.sh reloaded the code but never reinstalled the units, so a pull that changed how the bot is run - its sandboxing, resource caps, the updater schedule - left the old configuration in place while the repo said otherwise. Silent drift, and it bit during the last deploy: dropping EnvironmentFile from the unit needed setup.sh re-run by hand. Copying the definition into update.sh would have created two sources of truth, so it moves to install-units.sh instead and both scripts call it. Writing two files and reloading is cheap enough to do on every update, which makes the running configuration match the commit by construction. Two guards, both verified non-vacuous: - No deploy script may declare EnvironmentFile. It now scans every script rather than one by name - the previous version pointed at setup.sh and would have silently stopped checking anything when the unit moved out of it. - The service unit must be defined exactly once. Confirmed by injecting a duplicate definition and watching it fail.
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.
Why
update.shreloaded the code but never reinstalled the units. A pull that changed how the bot is run — its sandboxing, resource caps, the updater schedule — left the old configuration running while the repo said otherwise.Silent drift, and it is not hypothetical: it bit during the last deploy. Dropping
EnvironmentFilein #21 neededsetup.shre-run by hand, becauseupdate.shwould happily have restarted the bot with the old unit and reported success.Why not just copy the unit into update.sh
That creates two sources of truth that drift apart, and the deployed configuration then depends on which script ran last — a worse version of the bug being fixed.
The definitions move to
deploy/install-units.sh, and bothsetup.shandupdate.shcall it. Writing two small files and runningdaemon-reloadis cheap enough to do on every update, which makes the running configuration match the commit by construction rather than by remembering.Verification
The drift test, on the live host
Corrupted the installed unit, then ran
update.sh:Drift introduced, drift corrected, without being asked.
Two guards, both confirmed non-vacuous
EnvironmentFile. The previous version of this test pointed atsetup.shby name — moving the unit out of that file would have silently turned the guard off while it kept reporting green. It now scans everydeploy/*.shand asserts it found scripts to scan at all.Description=LoopifyBot Discord Music Botintoupdate.sh, watching the test fail, then restoring and watching it pass.232 passed.shellcheck -S style deploy/*.shclean across all five scripts.Note
install-units.shderives the run-as user from the checkout's owner (stat -c '%U') rather than$SUDO_USER/$USER, so it behaves the same whether it is invoked bysetup.sh, byupdate.sh, or directly.