Repository navigation
Description
Part of #1151.
Scope
An admin restarts the daemon without a terminal on its machine: POST /v1/restart, daemon.restart, or simlock daemon restart. The daemon hands the restart to the updater process, which stops it and starts it again with no install. Leases are kept, as for any restart.
If this goes wrong, a daemon stops and does not come back, an update and a restart run at once, or a restart installs or rolls back a version.
Technical spec
Commit 096519b.
Rows
- Behaviours: B12, B13, B14
- Interfaces: I17, I18, I19
- Existing code: X5, X15, X17, X18, X19, X20, X21, X22, X23, X24, X35, X38, X39
Facts
none
Modules touched
Searches: UpdaterLaunch, launcher.launch, parseUpdaterArgs, runUpdater, updateOptionsFor, stopRunningDaemon, REMOTE_REFUSED_PATHS, daemon stop in src and website.
src/contract/operations-admin.ts,src/contract/operations.ts,src/contract/protocol.ts,src/daemon/dispatcher.tsand its parts,src/daemon/server-requests.ts,src/gateway/dispatcher.ts.src/daemon/update-coordinator.ts,src/daemon/settings.ts,src/daemon/worker-composition.ts,src/daemon/main.ts.src/updater/index.ts,src/updater/main.ts,src/ports/updater-launcher.ts.src/simlock-client/client-api.ts,src/simlock-client/client-impl.ts,src/simlock-client/client-degraded.ts,src/simlock-client/types.ts,src/admin/index.ts,website/src/content/docs/docs/reference/node-client.mdx:restartDaemon().src/cli/commands/daemon.ts,src/cli/daemon-service.ts,src/cli/tree.ts,src/cli/index.ts, with Settings: change settings through the daemon with PATCH /v1/settings, live where it can #1154's wait limit reused.src/http/admin-declarations.ts,src/http/app.ts.src/updater/AGENTS.md,website/src/content/docs/docs/reference/cli.mdx,website/src/content/docs/docs/worker/daemon.mdx,website/src/content/docs/docs/worker/change-a-setting.mdx,website/src/content/docs/docs/getting-started/existing-farm.mdx.
flowchart LR
CLI["cli daemon *"] --> D["dispatchers *"]
H["http *"] --> D
D --> U["update-coordinator *"]
U --> L["ports updater-launcher *"]
U --> S["daemon/settings *"]
L -.spawns.-> P["updater *"]
Rules in play
- ADR 0099 §6: stop, wait, start; refused while the file does not load; no update field, no update event.
- ADR 0042: one detached updater;
daemon.update's shape is frozen and does not change. src/updater/AGENTS.md:main.tsimports everything statically, and both ends of the updater's lines change together.src/contract/AGENTS.md, "Adding an operation": matrices, protocol, both dispatchers, client, HTTP, website.- Architecture rule 11: the CLI's wait is bounded.
- Documentation rule 9: the CLI reference and the daemon page.
Tests
Seam: startDaemon with FakeUpdaterLauncher (model: src/daemon/main-update.test.ts), createHttpApp (model: src/http/app-updates.test.ts), runUpdater (model: src/updater/index.test.ts), the launcher (model: src/ports/updater-launcher.test.ts) and runCli (model: src/cli/index-daemon-service.test.ts).
- B12: An admin restarts the daemon with
POST /v1/restartand the daemon launches the updater once in restart mode: first call 202 and one launch with the pid and the role; a second call 202, no second launch; during an update, waiting included, 503DAEMON_UPDATING; a newdaemon.updateduring a restartDAEMON_STOPPING, whiledaemon.update {query}answers as today;config.jsondoes not load: 400 and no launch; the launch throws: 500INTERNALand a later call launches again; the updater exits non-zero before the stop: a later call launches again, nodaemon.update-failed, no update field set; an agent 403 - B13: The updater in restart mode stops the daemon and starts it again, with no install: the launcher's arguments are
--restart --pid <pid>, plus--gatewayfor a gateway;--restartwith--fromis refused; running at any version: exit 0, no npm call, no backup, no result file; the old pid still alive after 10 minutes: SIGKILL; not started in 2 minutes: one stderr line, exit 1, nothing reinstalled; a worker's start passes--local, in an update too - B14:
simlock daemon restartasks the running daemon to restart: running: printsDaemon restarting,--json{"status":"restarting"}; none running: printsDaemon not running,--json{"status":"not-running"}, exit 0, asdaemon stopdoes; a daemon that never answers: I19's error after 30 s, the connection closed; a refusal printed, exit by its code;--url: refused asdaemon stopis;--gatewaywith no gateway:GATEWAY_NOT_PRESENT
Done when
daemon.restartis in the role and effect matrices ofsrc/contract/operations.test.ts;daemon.update's pinned schemas there are unchanged.- A restart-mode run calls no
npm.installand writes noupdate-backupand noupdate-result.json. - The website build and its HTTP API check pass, and the HTTP reference lists
POST /v1/restart.
Out of scope
- Restarting a worker through its gateway.
- Waiting for leases to end, and an event of its own.
Depends on
- Settings: read every setting through GET /v1/settings #1153 because: the settings handle in
src/daemon/settings.tsit adds to - Settings: change settings through the daemon with PATCH /v1/settings, live where it can #1154 because: the protocol range in
src/contract/protocol.ts,createConfigSettings, and the wait limit insrc/cli/environment.ts
Written by an agent.
Activity
test: a second restart call answers like the first and launches no se…
feat(daemon): a restart already launched answers the same and launche…
test: a restart whose launch throws or whose updater exits before the…
feat(daemon): a failed launch answers INTERNAL, and an updater that e…
test: a restart is refused during an update and an update during a re…
feat(daemon): a restart is refused while an update runs and an update…
test: a restart is refused with BAD_REQUEST and nothing launched whil…
feat(daemon): a restart is refused while config.json does not load (#…
test: POST /v1/restart answers 202, refuses an agent and maps a refus…
feat(http): POST /v1/restart restarts the daemon (#1155)
7 remaining items
feat(updater): the updater parses its restart mode (#1155)
test: the launcher passes --restart --pid, with --gateway, for a rest…
feat(ports): the launcher starts the updater with --restart --pid for…
test: simlock daemon restart asks the running daemon to restart and p…
feat(cli): simlock daemon restart asks the running daemon to restart (#…
test: daemon restart with no daemon prints Daemon not running, a refu…
feat(cli): daemon restart with no daemon running says so, and is refu…
test: daemon.restart over the socket launches the updater in restart …
docs: the daemon restart in the daemon manual, the updater manual, th…
chore: the last cycle's push runs every hook (#1155)
docs(ports): the update launch says what it asks of the updater (#1155)
refactor(updater): the argument reader and its checks are two functio…
test: the daemon restart's 30 s limit is straddled, so a shorter limi…
docs(daemon): the restart manual lines keep what the code cannot say (#…