feat(pi-bots): the bot service as a launchd user agent, with alert rules (#9) #17
No reviewers
Labels
No labels
ready-for-agent
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bryan/nix-configs!17
Loading…
Reference in a new issue
No description provided.
Delete branch "n9-1-pi-bots-service"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #9 (piece N9.1).
What
services.pi-bots(modules/services/pi-bots.nix), enabled on Studio: the bot service (bryan/pi-bots) as one launchd user agent,org.nixos.pi-bots.nodeon<checkout>/src/cli.ts service runfrom the checkout (~/code/pi-bots),RunAtLoad+KeepAlive,ExitTimeOut30. A code change in the checkout needs alaunchctl kickstart -k, not a rebuild. As a Homebrew-node agent it joinsbase/homebrew.nix's re-pin.HOME, aPATHwith Homebrew,PI_BOTS_HOMESERVER,PI_BOTS_STATE_DIR,PI_BOTS_METRICS_DIR. No token or owner: the service reads its own files.KeepAliveretries it, so the agent takes over within seconds of another copy stopping.pi-bots.promfrom the metrics directory. Rules:PiBotsServiceDown(critical): the service stopped cleanly (pi_bots_service_up 0) for 5 min.PiBotsServiceSilent(critical): the file is over 2 min stale or missing, for 5 min (a crash).PiBotsBotDown: a bot's runner or Pi down for 5 min.PiBotsBotCrashLooping: a bot's Pi down most of 15 min and dropping more than once (a crash loop never satisfiesBotDown'sfor; one outage isBotDown's).PiBotsAccountNotSyncing: 10 min.PiBotsMessagesWaiting: an owner's message unanswered for 30 min.pi-bots-backuparchives.Not here: a "clock silent" rule. The service has no clock metric yet (pi-bots W32.4 adds it); its rule follows then.
Tests
python3 scripts/test_pi_bots_service.py(23): the agent's command, environment and logs; node_exporter wiring; the Homebrew re-pin; refusals; disabled declares nothing;promtool check metricson the service's file shape;promtool test rulesfor each rule, firing and quiet, including a clean stop vs a crash, a short restart, a crash loop and nothing per bot while the service is down. Mutations of each guard fail a test.darwin-rebuild build --flake .#studiobuilds; the neighbouring monitoring, backup, NAS, content-probe, listener and Dashy suites pass.The agent's exact command and environment were run by hand: against the live state it refuses with exit 1 while another service holds the lock; on a scratch state it starts, writes its file, and on SIGTERM exits 0 having written
pi_bots_service_up 0.Review
An independent Pi reviewer found one should-fix: the crash-loop rule fired after a single outage ended. That is fixed (
resetscounts drops), and a stale file now also holds the bot rules back. Both are covered by tests that fail without them, and the reviewer approved the fix. Left as a follow-up: the shared Homebrew re-pin waits about 2 s afterbootout, which a slow stop can outlast.After
update-systemThe service now runs by hand in a Rex tab. The agent waits on its lock until that copy stops; then it takes over.