Skip to content

Make the systemd units declarative - #22

Merged
Isma-L154 merged 1 commit into
mainfrom
refactor/declarative-systemd-units
Aug 21, 2026
Merged

Make the systemd units declarative#22
Isma-L154 merged 1 commit into
mainfrom
refactor/declarative-systemd-units

Conversation

@Isma-L154

Copy link
Copy Markdown
Owner

Why

update.sh reloaded 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 EnvironmentFile in #21 needed setup.sh re-run by hand, because update.sh would 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 both setup.sh and update.sh call it. Writing two small files and running daemon-reload is 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:

$ sudo sed -i "s/^MemoryMax=768M/MemoryMax=64M/" /etc/systemd/system/loopify-bot.service
  unit ahora dice: MemoryMax=64M

$ bash deploy/update.sh
==> Installing systemd units (user: ubuntu, dir: /home/ubuntu/LoopifyBot)
==> Restarting loopify-bot...
==> Running commit 0e46a99.

$ grep MemoryMax /etc/systemd/system/loopify-bot.service
MemoryMax=768M
  activo: 768 MB

Drift introduced, drift corrected, without being asked.

Two guards, both confirmed non-vacuous

  • No deploy script may declare EnvironmentFile. The previous version of this test pointed at setup.sh by name — moving the unit out of that file would have silently turned the guard off while it kept reporting green. It now scans every deploy/*.sh and asserts it found scripts to scan at all.
  • The service unit must be defined exactly once. Verified by injecting a duplicate Description=LoopifyBot Discord Music Bot into update.sh, watching the test fail, then restoring and watching it pass.

232 passed. shellcheck -S style deploy/*.sh clean across all five scripts.

Note

install-units.sh derives 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 by setup.sh, by update.sh, or directly.

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.
@Isma-L154
Isma-L154 merged commit 4e91584 into main Aug 21, 2026
3 checks passed
@Isma-L154
Isma-L154 deleted the refactor/declarative-systemd-units branch August 21, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant