Let a server service carry helper scripts and timers, starting with UseSend's cert refresh

This commit is contained in:
Gabriel Brown committed 2026-10-30 13:44:29 -04:00
1 parent a987cbab66
commit 95fa480469
9 files changed
+304 -59

No files matched your search

+33 -3
View File
@@ -6,9 +6,10 @@
# * enable seeds .env from .env.example and REFUSES to start while a
# CHANGE_ME placeholder survives -- a service brought up with the
# placeholder as its database password runs, wrongly, forever
# * a completed enable links exactly the tracked files (compose.yml and the
# unit), reloads systemd, and enables the unit
# * disable removes the unit and nothing else: the .env and data stay
# * a completed enable links the tracked files (compose.yml, helper scripts,
# the unit and any helper units), reloads systemd, enables the unit and
# each helper timer, and never links .env.example
# * disable removes the units and nothing else: the .env and data stay
# * relink refreshes links for enabled services only, and names a service
# whose definition changed since the machine last looked -- without
# restarting anything
@@ -55,6 +56,21 @@ RemainAfterExit=yes
[Install]
WantedBy=default.target
UNIT
cat >"$catalog/Example/refresh-example" <<'SH'
#!/usr/bin/env bash
SH
chmod +x "$catalog/Example/refresh-example"
cat >"$catalog/Example/example-refresh.service" <<'UNIT'
[Service]
Type=oneshot
ExecStart=%h/Server/Example/refresh-example
UNIT
cat >"$catalog/Example/example-refresh.timer" <<'UNIT'
[Timer]
OnCalendar=daily
[Install]
WantedBy=timers.target
UNIT
# The stub records every invocation; is-active answers 'inactive' so nothing
# here depends on a real systemd.
@@ -81,6 +97,8 @@ run() {
}
unit_link="$home/.config/systemd/user/podman-example.service"
helper_link="$home/.config/systemd/user/example-refresh.service"
timer_link="$home/.config/systemd/user/example-refresh.timer"
# ── enable stops on placeholders ─────────────────────────────────────────────
@@ -111,6 +129,14 @@ grep -q 'systemctl --user enable --now podman-example.service' "$calls" \
|| note 'enable did not enable --now the unit'
[[ "$(cat "$home/Server/Example/.env")" == "DB_PASSWORD=s3cret" ]] \
|| note 'enable rewrote an .env that already existed'
[[ -L "$home/Server/Example/refresh-example" ]] \
|| note 'enable did not link the helper script into ~/Server'
[[ -e "$home/Server/Example/.env.example" ]] \
&& note 'enable linked .env.example into ~/Server'
[[ -L "$helper_link" && -L "$timer_link" ]] \
|| note 'enable did not link the helper units'
grep -q 'systemctl --user enable --now example-refresh.timer' "$calls" \
|| note 'enable did not enable the helper timer'
# ── relink names a changed definition, restarts nothing ──────────────────────
@@ -136,6 +162,10 @@ run disable Example >/dev/null 2>&1 || note 'disable failed'
[[ -e "$unit_link" ]] \
&& note 'disable left the unit installed'
[[ -e "$helper_link" || -e "$timer_link" ]] \
&& note 'disable left a helper unit installed'
grep -q 'systemctl --user disable --now example-refresh.timer' "$calls" \
|| note 'disable did not stop the helper timer'
grep -q 'systemctl --user disable --now podman-example.service' "$calls" \
|| note 'disable did not stop the unit'
[[ -f "$home/Server/Example/.env" ]] \