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

+13 -9
View File
@@ -3,9 +3,12 @@
# Every service in the catalog has the same shape, because panama-server and
# the update timer both depend on it blindly:
#
# * a compose.yml, which is the only file enable symlinks into ~/Server
# * a compose.yml, linked into ~/Server along with any helper script
# * exactly one podman-*.service unit -- its filename is the unit's
# identity, so two would be an ambiguity and zero an unenableable service
# identity, so two would be an ambiguity and zero an unenableable service.
# Other *.service and *.timer files are helpers (a cert refresh, say)
# that enable links beside it; each helper service needs a timer or a
# unit that pulls it in, so an orphan helper is flagged
# * a WorkingDirectory of %h/Server/<Name>, matching the directory enable
# creates -- a unit pointing anywhere else starts compose against a
# directory that has no .env and no data
@@ -31,20 +34,21 @@ for dir in "$containers_dir"/*/; do
[[ -f "$dir/compose.yml" ]] || note "$name has no compose.yml"
units=("$dir"/*.service)
units=("$dir"/podman-*.service)
if (( ${#units[@]} == 0 )); then
note "$name has no unit file"
note "$name has no podman-<name>.service unit"
continue
elif (( ${#units[@]} > 1 )); then
note "$name has ${#units[@]} unit files; its identity is ambiguous"
note "$name has ${#units[@]} podman-*.service units; its identity is ambiguous"
continue
fi
unit="${units[0]}"
case "$(basename "$unit")" in
podman-*.service) ;;
*) note "$name's unit is not named podman-<name>.service: $(basename "$unit")" ;;
esac
for helper in "$dir"/*.service; do
[[ "$helper" == "$unit" ]] && continue
[[ -f "${helper%.service}.timer" ]] \
|| note "$name's helper $(basename "$helper") has no matching .timer"
done
grep -q "^WorkingDirectory=%h/Server/$name\$" "$unit" \
|| note "$name's unit does not work in %h/Server/$name"
+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" ]] \