Repository navigation
agmsgd: supervise the sync engine as one child process per connected team - #2130
Merged
Merged
Conversation
…team, behind run/sync-mode
… that ignores SIGTERM, scopes a refusal to its own engine and never copies a server's code
… and starts nothing once it is stopping, switched or disconnected
…o feat/agmsgd-sync-supervisor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
First step of running the sync engine under agmsgd: agmsgd supervises the existing engine as a child process, one per connected team. Nothing changes for an existing install: the supervisor is inert unless
run/sync-modesaysagmsgd, and the default (file absent) isstandalone.scripts/daemon/sync-supervisor.mjs, added to agmsgd's channel list. Each poll it readsrun/sync-mode; inagmsgdmode it starts, for every connected team,bash scripts/remote-sync.sh run --team <team>(the programremote.sh sync startstarts, so its environment set-up, storage driver and rules are unchanged), restarts it after a failure with a doubling backoff from 5 s capped at 5 min, and ends and restarts one that has completed no cycle for 15 min (SIGTERM, then SIGKILL after 5 s; the kill deadline is set by the first request and is enforced whatever the mode or team list says). Nothing else stops by itself: a failing engine keeps being restarted and the state andagmsgd.logkeep saying so (a line per change, repeated every 30 min while it is not running).remote.sh sync starttakes (teams/<team>/.config.lockwith its.ownermarker and holder record): the check for a running engine, the spawn and the pidfile write happen under it, so a command starting an engine at the same moment cannot produce a second writer. If the lock is held the start waits (bounded) and is reported as a backoff; a pidfile that cannot be published ends the just-started child at once. One engine per team is kept by the factsremote.shalready uses: the supervisor writesrun/remote-sync.<team>.pidfor its child, removes only a pidfile it wrote, and does not start a second engine when that pidfile names a live engine for the team that it did not start (held_elsewhere, asked again every 30 s).awaiting_unlock(the engine ends with exit status 12, new, when the team has no sync configuration; started again when the team config changes, else asked every 5 min),fenced_awaiting_bundle(a key rotated elsewhere),over_limit(402/413/429 or a limit code),refused(any other answer, with its status and code; only an HTTP status number and a short plain-alphabet code are ever shown, anything else the server sent is replaced by a generic phrase, so a server-supplied value never reaches a state file oragmsgd.log),removed. In all butawaiting_unlockthe engine keeps running and asks at its longest interval itself; the stalled-progress kill is not applied to them.removed by the server: ... Run remote.sh connect or pull to connect this machine again. Only a reconnect (it rewrites the team config) puts the team back. This is a stop by itself, listed as such for §10 review. An answer recorded by an earlier run (before the engine was started) is not about this connection and is ignored.run/sync-supervisor/<team>.json(state, reason, pid, start time, restart and failure counts, next retry,last_progress_atcopied from the engine's own cycle record,updated_at), refreshed at least every minute, so a CLI can read progress timestamps when agmsgd is down. The CLI views come in the next PR.refusal.json,cycles.json. No new channel to the child; its output is never parsed.AGMSG_AGE_IDENTITY*/AGMSG_SYNC_AGE_IDENTITY*/AGMSG_SYNC_TOKEN*, plusAGMSG_SYNC_SUPERVISED=agmsgd(used by the next PR). No secret is on its command line, and nothing here reads or writes a capability URL: only team names, states, pids and timestamps reach a log line or a state file.EXIT_SYNC_CONFIG_MISSING) instead of 1 when the team has no sync configuration; every other exit is as before.Known gap, not in this PR
A team that relied on
CURL_CA_BUNDLE/NODE_EXTRA_CA_CERTSexported in the shell that started its engine would lose it under agmsgd (the child inherits agmsgd's environment, not that shell's) and fail TLS. Recording those two paths (path only) in the team's sync config at connect/start, so the supervised child gets them, is planned for the next PR.Process spawns
standalone: one small file read, no process.agmsgd: per team, reads of the team config, the cycle record and the refusal record (no process); a process starts only when an engine is started or restarted (bashthenexec node, assync startdoes today). The pidfile liveness check of a foreign pid runspsonce per start attempt on macOS (/procon Linux).Tests
tests/agmsgd_sync_supervisor.test.mjs(25, wrapped bytests/test_agmsgd_sync_supervisor.bats): standalone starts nothing; one child per connected team with exactlybash <scripts>/remote-sync.sh run --team <team>; no secret on argv or in the environment and no capability URL in a log line or state file; doubling backoff to the 5-minute cap; a restart storm in one team does not delay another; a team whose engine cannot be started is reported and the other runs; stall deadline ends, then kills, then restarts; refusal labels leave a running engine alone;removedstops for good and only a reconnect clears it;awaiting_unlockby exit status 12, not on every backoff;held_elsewhereand a pidfile naming some other process; stop and a switch back to standalone end the children; the state file's contents; and one test with a real child process (its pidfile, a kill, the backoff, the stop); and regression tests for: an engine that ignores SIGTERM is killed after the grace in standalone mode and for a disconnected team, with the deadline set once; a refusal left by an earlier run does not remove a reconnected team; a hostile refusal code (URL, secret-shaped, free text) is never copied; the team lock is respected and released; a pidfile that cannot be written ends the child; a program that cannot be run is one failed start (itserrorevent is handled from the moment of the spawn); a stop, a mode switch or a disconnect that arrives while a start waits for the lock means nothing is started afterwards.tests/remote_sync_engine.test.mjs: the missing-config error carries the code behind exit status 12.AGMSG_HOMEandAGMSG_INSTALL_HOMEunset: the engine, fence, supervisor and daemon-main node tests (224). The four.github/scripts/check-*.shpass at their baselines.