Settings: restart the daemon with POST /v1/restart and simlock daemon restart
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- node.js, typescript
Línea de trabajo
Start with ADR 0057 and the update flow in src/daemon/update-coordinator.ts, then trace the operation through src/contract/operations.ts, src/daemon/server.ts, and the dispatchers. Run the named coordinator, server, HTTP, updater, launcher, and CLI tests as you work. Done means the CLI and POST /v1/restart launch restart mode once, with the specified update conflicts and failure behavior, and the updater restarts without installing or rolling back.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Part of #1151.
Scope
An admin restarts the daemon without a terminal: POST /v1/restart, the daemon.restart operation, or simlock daemon restart. The daemon hands the restart to the updater process, run in a restart mode that stops the daemon and starts it again, with no install. Leases are kept, as for any restart.
In short
After this PR simlock daemon restart prints Daemon restarting and returns; a few seconds later the same daemon role answers again, having read config.json afresh. POST /v1/restart answers 202 { "restarting": true }. During an update it answers 503 DAEMON_UPDATING. A lease request still waiting in the queue fails with today's restart message (The daemon restarted before this lease request settled; send it again with a new key).
$ simlock daemon restart
{"error":{"code":"USAGE","message":"Unknown daemon command: restart"}} (today, exit 2)
Daemon restarting (after)
$ simlock daemon restart --json
{"status":"restarting"} (after)
sequenceDiagram
participant C as CLI or HTTP
participant D as Daemon
participant U as Updater, restart mode (new)
C->>D: daemon.restart (new)
D-->>C: { restarting: true }
D->>U: launch detached: --restart --pid --gateway?
U->>D: daemon.stop
U->>U: wait until the socket is free (10 min, then SIGKILL the pid)
U->>U: daemon start (2 min)
alt running
U-->>U: exit 0
else not started
U-->>U: one stderr line in daemon.log, exit 1
end
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
Facts
Commit bcedd2fa.
| # | Fact | Source |
|---|---|---|
| F1 | runUpdater: install, {"stage":"restarting"}, probe.stop(), wait for the pid (SIGKILL when it does not exit), back up the databases, daemon start, rollback on a failed start |
src/updater/index.ts:96-140 |
| F2 | The updater's arguments are --from, --to, --pid and --gateway; anything else throws bad updater arguments |
src/updater/index.ts:247-272 |
| F3 | Limits: daemon start 2 min, each probe call 30 s |
src/updater/index.ts:40-41 |
| F4 | UpdaterLaunch carries entry, from, to, role, pid, simlockHome, logPath; NodeUpdaterLauncher spawns it detached, stdout a pipe, stderr appended to the log |
src/ports/updater-launcher.ts:9-69 |
| F5 | FakeUpdaterLauncher records launches |
src/ports/updater-launcher.ts:71-80 |
| F6 | The update coordinator launches the updater from dist/updater/main.js with the role, pid, home and log path, and keeps the running update in #run |
src/daemon/update-coordinator.ts:111, :212-223 |
| F7 | DAEMON_UPDATING is CLI exit 1, HTTP 503 |
src/contract/errors.ts:384 |
| F8 | daemon.stop is admin, write, { stopping: true } |
src/contract/operations.ts:634-640 |
| F9 | simlock daemon has start, stop, status, logs, install, uninstall; stop connects with launch: false and prints Daemon stopping |
src/cli/commands/daemon.ts:120-125, :191-201 |
| F10 | POST /v1/update is declared with status 202 and served through deps.dispatch |
src/http/admin-declarations.ts:73-89, src/http/app.ts:655-662 |
| F11 | A waiting lease request fails at the next start with the "daemon restarted" message | src/leasing/lease-startup.ts:39 |
| F12 | The page the restart section lives on today | website/src/content/docs/docs/worker/running-the-daemon.mdx:123-130 |
| F13 | The updater test table drives runUpdater with fakes and checks stdout and stderr lines |
src/updater/index.test.ts:500-610 |
| F14 | DaemonServer routes each socket request by an explicit case; an operation with none answers UNKNOWN_REQUEST |
src/daemon/server.ts:1287-1294 |
| F15 | The launcher's argv is built in NodeUpdaterLauncher and asserted in its own test; the fake records options only |
src/ports/updater-launcher.ts:33-44, :81-82, src/ports/updater-launcher.test.ts:16, :46 |
| F16 | A second daemon.update during an update answers { started: false, update }; only leasing throws DAEMON_UPDATING |
src/daemon/update-coordinator.ts:141-147, src/leasing/lease-acquisition-coordinator.ts:99 |
| F17 | daemon.update {query} is how the gateway, simlock update and the updater probe read a daemon |
src/gateway/worker-link.ts:370-381, src/cli/commands/update.ts:85-95, src/updater/probe.ts:55 |
| F18 | The coordinator's update state (#run) is what status.get, the gateway's worker view and daemon status show; a failed run emits daemon.update-failed and sets lastUpdateFailure |
src/daemon/update-coordinator.ts:124-130, :233-268 |
| F19 | The updater waits for running at version to, and stops a started daemon before a rollback |
src/updater/index.ts:111-114, :206-215 |
| F20 | Update calls run one at a time through the coordinator's call chain; #run is set only after npm view and checkInstall |
src/daemon/update-coordinator.ts:133-157, :189-193 |
Modules touched
Searches: UpdaterLaunch, parseUpdaterArgs, runUpdater, launcher.launch, daemon.stop, "stop" in src/cli/commands/daemon.ts, updateRoute, restart in website/.
src/contract/operations.ts,src/contract/protocol.ts:daemon.restart.src/ports/updater-launcher.ts: a restart launch (--restart, no--from,--to).src/updater/index.ts,src/updater/main.ts:parseUpdaterArgstakes--restart --pid [--gateway];runUpdaterin restart mode skips the install, the backup and the rollback.src/daemon/update-coordinator.ts:restart(), on the same call chain asdaemon.update(F20): refuses while an update is running, launches once, and keeps its own restarting flag apart from the update state (F18), sostatus.get, the worker view anddaemon statusshow no update and a failed restart emits nodaemon.update-failed. While the flag is set, adaemon.updatethat would start an update answersDAEMON_STOPPING;queryanswers as today (F17).src/daemon/server.ts: acase "daemon.restart"in the socket router (F14).src/ports/updater-launcher.test.ts: the restart argv (F15).src/daemon/dispatcher.ts,src/gateway/dispatcher.ts: thedaemon.restarthandler (the gateway through itsupdateoption).src/simlock-client/client.ts,src/simlock-client/types.ts,src/admin/index.ts:restartDaemon().src/cli/commands/daemon.ts:restart.src/http/admin-declarations.ts,src/http/app.ts:POST /v1/restart.website/src/content/docs/docs/reference/cli.mdx,website/src/content/docs/docs/worker/running-the-daemon.mdx.
flowchart LR
CLI["cli daemon *"] --> CL["client *"]
H["http app *"] --> DI["dispatchers *"]
CL --> DI
DI --> UC["update-coordinator *"]
UC --> L["ports updater-launcher *"]
L -.spawns.-> UP["updater *"]
Contract and event changes
This PR bumps the protocol by one.
daemon.restart: admin, write; input{}; output{ restarting: true }.POST /v1/restart: no body; 202 with the output; 503DAEMON_UPDATING.daemon.update's shapes do not change; it may answerDAEMON_STOPPING, an error code every route already declares.- No new event, so no
EVENTS.mdentry: the restart shows as today'sdaemon.stoppinganddaemon.startedentries.
Other code on the same state
Searches: users of the update coordinator's #run and of launcher.launch (1 launch site, src/daemon/update-coordinator.ts:215), writers of update-result.json and update-backup (src/updater/index.ts only), callers of daemon.stop (CLI daemon stop, daemon install, daemon uninstall, the updater).
- An update
waitingorinstalling:daemon.restartanswersDAEMON_UPDATING; the update goes on. - A restart running, then a
daemon.updatethat would start an update:DAEMON_STOPPING(the daemon is about to stop);daemon.update {query}answers as today, so the gateway,simlock updateand the updater probe keep reading it (F17). An update call already in its version check when the restart arrives finishes first: both run on one call chain (F20). One updater process at a time. - A restart running, then a second
daemon.restart:{ restarting: true }, no second launch. simlock daemon stopduring a restart: stops the daemon; the updater's start brings it back. Said in the CLI reference.- A service manager (launchd, systemd): the updater's
daemon startgoes through it as an update's does (launcherFor); nothing new. update-result.jsonandupdate-backup: a restart writes neither.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
| launch the updater | ok | { restarting: true }; the daemon is stopped by it |
— |
| launch the updater | throws | daemon.restart answers INTERNAL with the reason; the daemon keeps running; a later call may try again |
— |
updater daemon.stop |
no answer | counted as stopped after the wait | 30 s per call, from the call |
| updater wait for the pid | still running | SIGKILL the pid, as an update does | 10 min, from daemon.stop |
updater daemon start |
not running in time, at any version | one stderr line restart failed: <reason> (lands in daemon.log), exit 1; nothing rolled back, nothing stopped |
2 min, from the start |
| updater process | exits non-zero before it stopped the daemon | the coordinator clears its restarting flag and logs one warn line; no daemon.update-failed, no lastUpdateFailure; the next daemon.restart launches again |
— |
Rules in play
- ADR 0057 §5: "launches the updater process in a restart mode ... No install, no database copy, no rollback"; "During an update it answers
DAEMON_UPDATING"; "A second call while one runs answers{ restarting: true }again and starts nothing". - ADR 0042: one detached updater restarts the daemon;
daemon.update's shape is frozen, so the restart is a new operation, not an option ondaemon.update. src/updater/AGENTS.md:main.tsimports everything statically; the restart mode keeps that.src/contract/AGENTS.md, "Adding an operation": matrices, protocol bump, both dispatchers, client, CLI, HTTP, website.- Documentation rule 9: the CLI reference and the restart section of running the daemon change in this PR.
Tests
Seam: startDaemon with FakeUpdaterLauncher through daemon.dispatch (model: src/daemon/main.test.ts), the socket (model: src/daemon/server.test.ts), the route in src/http/app.test.ts, runUpdater (model: src/updater/index.test.ts:500-610), the launcher's argv (model: src/ports/updater-launcher.test.ts) and runCli (model: src/cli/index.test.ts).
- An admin restarts the daemon with
POST /v1/restartand the daemon launches the updater once in restart mode: first call 202 and one launch in restart mode with the pid and the role; a second call 202, no second launch; the same call over the daemon socket; during an update 503DAEMON_UPDATING; a newdaemon.updateduring a restartDAEMON_STOPPING, whiledaemon.update {query}answers as today; the launch throws: 500INTERNAL, the daemon keeps running and a later call launches again; the updater exits non-zero before stopping the daemon: a later call launches again, nodaemon.update-failed; an agent 403. - 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; starts (running at any version): exit 0, no npm call, no backup, no result file; does not start in 2 minutes: one stderr line, exit 1, no reinstall, nothing stopped;--gatewaystarts the gateway. simlock daemon restartasks the running daemon to restart: running: printsDaemon restarting,--json{"status":"restarting"}; none running: fails asdaemon stopdoes.
Done when
daemon.restartis in the role and effect matrices, and the protocol range is one higher.parseUpdaterArgs(["--restart", "--pid", "42"])parses;["--restart", "--from", "1.0.0", "--to", "1.0.1", "--pid", "42"]throws.- A restart-mode run calls no
npm.installand writes noupdate-backuporupdate-result.json. simlock daemon --helplistsrestart; the CLI reference and running the daemon describe it.
Out of scope
- Restarting a worker through the gateway.
- Waiting for leases to end before a restart (leases survive it).
- A restart event of its own.
Depends on
- #1154
Written by an agent.
- Lenguaje dominante
- TypeScript
- Estrellas
- 705
- Forks
- 40
- Merge medio
- 12 h 9 min
- PR fusionados (30 d)
- 376
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de callstackincubator/simlock
-
request:new
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
callstackincubator/simlock#1806 ·
Los mantenedores suelen responder en 1 día
-
bug:new
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
callstackincubator/simlock#1780 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
task:draft
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
callstackincubator/simlock#1441 ·
Los mantenedores suelen responder en 1 día
-
bug:new
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
callstackincubator/simlock#1805 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug:new
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
callstackincubator/simlock#1804 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de callstackincubator/simlock
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Update project links after the repository renamesPosiblemente ocupada @JonathanTSilva la tomó hoy. Abiertoai-generated priority: p2 size: xs type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
JonathanTSilva/jts-website#119 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
promplate/code-review#158 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
[Docs] CONTRIBUTING points the Backend Remake milestone at a branch that does not existPosiblemente ocupada @franpts2 la tomó hoy. Abiertodocs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
Los mantenedores suelen responder en 3 días