Settings: restart the daemon with POST /v1/restart and simlock daemon restart
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 705
- 派生
- 40
- 平均合并
- 12 小时 9 分钟
- 30 天内合并 PR
- 376
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
callstackincubator/simlock 的其他 Issue
-
request:new
难度 2/5 1-3 小时 新手友好度 72/100
callstackincubator/simlock#1806 ·
维护者通常 1 天内回复
-
bug:new
难度 2/5 1-3 小时 新手友好度 78/100
callstackincubator/simlock#1780 · 1 条评论 ·
维护者通常 1 天内回复
-
task:draft
难度 2/5 1-3 小时 新手友好度 72/100
callstackincubator/simlock#1441 ·
维护者通常 1 天内回复
-
bug:new
难度 2/5 1-3 小时 新手友好度 45/100
callstackincubator/simlock#1805 · 1 条评论 ·
维护者通常 1 天内回复
-
bug:new
难度 2/5 1-3 小时 新手友好度 45/100
callstackincubator/simlock#1804 · 1 条评论 ·
维护者通常 1 天内回复
查看 callstackincubator/simlock 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
Update project links after the repository renames可能已有人在做 @JonathanTSilva 今天认领。 未关闭ai-generated priority: p2 size: xs type: bug
难度 2/5 1-3 小时 新手友好度 85/100
JonathanTSilva/jts-website#119 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 74/100
promplate/code-review#158 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
[Docs] CONTRIBUTING points the Backend Remake milestone at a branch that does not exist可能已有人在做 @franpts2 今天认领。 未关闭docs
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 3 天内回复