Files
fleet/scripts/hetzner/install-fleet-reconciler-timer.sh
CatoandClaude Opus 5 083aadc130 fix(reconciler): the clock reported healthy and would never have ticked again (#93)
The timer I installed an hour ago was active, enabled, and dead.

    systemctl is-active   -> active
    systemctl is-enabled  -> enabled
    NextElapseUSecMonotonic -> infinity

OnBootSec=5min and OnUnitActiveSec=15min are MONOTONIC. It ran fine while it
was left alone, but I stopped it to investigate a false dispatch, and on
restart systemd had no next elapse to compute: OnBootSec's trigger point was
hours in the past, and OnUnitActiveSec re-arms from an activation the restarted
timer no longer had. Persistent=true does nothing for a monotonic timer, so it
did not save it either.

So the mechanism built to end "reports healthy, does nothing" failures was
itself one, and would have gone on saying `active` indefinitely while the fleet
stopped being reconciled. Caught only because I read NextElapse instead of
trusting the word `active`.

OnCalendar=*:0/15 is absolute — :00, :15, :30, :45, computable without
reference to boot time or to any previous run, and unaffected by stop/start.
Persistent=true is now meaningful and catches up a tick missed to downtime.
RandomizedDelaySec=45 keeps it off the exact quarter hour.

And the installer no longer reports success without proving the thing will
tick: it reads NextElapseUSecRealtime and fails if there is none. It caught this
class on its first run. The check retries briefly, because the property is not
populated the instant `enable --now` returns and a guard that false-alarms is a
guard that gets ignored.

Verified on bitbaum: next elapse 13:00:44 UTC, and the 12:54 tick dispatched a
run that proved its guards (24 + 34 assertions), surveyed 21 repos and correctly
dispatched nothing.


Claude-Session: https://claude.ai/code/session_01NLZ6vs1jsWw2kKbpWTZHf2

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 05:57:10 -07:00

47 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Install the fleet reconciler's clock on the box. Idempotent — safe to re-run
# after editing the script or the units.
#
# scp the repo to the box (or run from a checkout on it), then:
# sudo bash scripts/hetzner/install-fleet-reconciler-timer.sh
#
# Verify afterwards:
# systemctl list-timers fleet-reconciler.timer
# journalctl -t fleet-reconciler-tick -n 20
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
[ "$(id -u)" -eq 0 ] || { echo "run with sudo" >&2; exit 1; }
install -d -m 0755 /opt/fleet
install -m 0755 "$here/deploy-reconciler-tick.sh" /opt/fleet/deploy-reconciler-tick.sh
install -m 0644 "$here/fleet-reconciler.service" /etc/systemd/system/fleet-reconciler.service
install -m 0644 "$here/fleet-reconciler.timer" /etc/systemd/system/fleet-reconciler.timer
systemctl daemon-reload
systemctl enable --now fleet-reconciler.timer
# A timer that reports active+enabled and has NO next elapse is the failure this
# whole mechanism exists to end, and the first version of this unit did exactly
# that after a stop/start: monotonic triggers (OnBootSec/OnUnitActiveSec) left
# NextElapseUSecMonotonic=infinity while systemctl cheerfully said "active".
# Never let the installer report success without proving the thing will tick.
# Retried, because the property is not populated the instant `enable --now`
# returns and a guard that false-alarms is a guard that gets ignored.
next_elapse=""
for _ in 1 2 3 4 5; do
next_elapse="$(systemctl show fleet-reconciler.timer -p NextElapseUSecRealtime --value)"
[ -n "$next_elapse" ] && [ "$next_elapse" != "n/a" ] && break
sleep 1
done
if [ -z "$next_elapse" ] || [ "$next_elapse" = "n/a" ]; then
echo "FAILED: the timer is installed but has NO next elapse — it would never fire." >&2
systemctl show fleet-reconciler.timer -p NextElapseUSecRealtime -p NextElapseUSecMonotonic >&2
exit 1
fi
echo "installed, and it will tick. next run:"
systemctl list-timers fleet-reconciler.timer --no-pager