mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-11-25 05:40:57 +01:00
fix(update): activate new binaries without a supervisor
This commit is contained in:
1 parent
b30443387b
commit
9ed4e19f5e
17 files changed
+406
-179
No files matched your search
@@ -87,11 +87,12 @@ data/ config.yaml` - is put aside and restored, and the result names every file
|
||||
is modified locally or the local history has diverged from the source it refuses and says why
|
||||
instead of forcing. See [the developer guide](developer-guide.md) for the full semantics.
|
||||
|
||||
When a supervisor is detected (systemd/launchd startup markers in the environment), the "exit after
|
||||
updating" tick is pre-ticked: the process stands down after a successful update, the supervisor brings
|
||||
the new binary back, and the page reloads itself once the service answers (sessions live in memory, so
|
||||
one fresh login follows). Forgot the tick, or swapped the binary from the CLI? The console carries a
|
||||
persistent banner with **Restart now** - no shell login needed.
|
||||
On macOS and Linux, when started from the `cyberstrike-ai` binary alongside its config, the console
|
||||
defaults to switching to the new binary after a successful build. The old service remains available
|
||||
during the build. Connections briefly drop at the switch and the page reloads when the new service
|
||||
answers. Sign in again afterward because sessions live in memory. A supervisor is still useful for
|
||||
starting at boot and recovering from crashes. If you defer the switch or replace the binary from the
|
||||
CLI, the console offers **Restart now** on installations that support the switch.
|
||||
|
||||
The update source is a single repository address in the `update` section of `config.yaml` (`repo`),
|
||||
or right on the console page: the official repository, your own fork, somebody else's repository or a
|
||||
|
||||
@@ -48,7 +48,7 @@ disagree about why an update was refused.
|
||||
|
||||
| entry | how it is used |
|
||||
|---|---|
|
||||
| console | System settings -> One-click update (`#system-update`, the old deep link still works). Opening this section reads the local tree only and does not go online; **Check** is what performs the fetch; **Update** starts a job the page polls; the "exit after updating" tick is pre-ticked when a supervisor is detected (launchd/systemd startup markers), and while the process is down the page watches for its return and reloads itself (sessions live in memory, so a fresh login follows); a rollback button sits below |
|
||||
| console | System settings -> One-click update (`#system-update`, the old deep link still works). **Update** starts a job the page polls. Supported installations switch to the newly built binary by default, and the page reloads once the service comes back. A rollback button sits below. |
|
||||
| REST | `GET /api/system/update` (state on disk, no network), `POST /api/system/update/check` (fetch, then report the gap), `POST /api/system/update/apply` (`202` with `job_id`, polled through `GET /api/system/update/job`), `POST /api/system/update/rollback` |
|
||||
| CLI | `./cyberstrike-ai -check-update`, `./cyberstrike-ai -update`, `./cyberstrike-ai -update-rollback`. The install root is the directory holding `--config`, or the current directory when `--config` was not given |
|
||||
|
||||
@@ -150,28 +150,24 @@ again after an interruption to finish recovery; the console reports `rollbackPen
|
||||
updates. Keep the recovery record, backup directory and `.prev` file. If recorded binary hashes do not
|
||||
match the files on disk, recovery refuses to overwrite them.
|
||||
|
||||
### The two restart cases
|
||||
### Switching to the new binary
|
||||
|
||||
The process only stands down (graceful `Shutdown`, then exit 0) when the request explicitly says
|
||||
`restart: true` **and** a restart hook was wired at startup. Whether it actually comes back is up to a
|
||||
supervisor (systemd, `run.sh`), and the page says exactly that rather than promising a boot that may
|
||||
not happen. Asking for a restart with no hook wired is a `400`, instead of stopping the service and
|
||||
claiming it restarted.
|
||||
On macOS and Linux, when started from the `cyberstrike-ai` binary alongside its config, the console
|
||||
sends `restart: true` by default. After a successful build and binary swap, the service closes its
|
||||
application resources and executes the new binary with the same PID, arguments, environment and
|
||||
working directory. Installations that cannot switch in place return `400` on an explicit restart
|
||||
request. CLI updates and REST updates without `restart: true` only replace files on disk.
|
||||
|
||||
**A pending binary is a durable state, and it can be activated later.** The status endpoint compares
|
||||
the binary identity captured at startup (size + nanosecond mtime) with what is on disk now: after an
|
||||
update, a rollback or a CLI run swapped the file without a restart, `needsRestart` is true,
|
||||
`binaryBuiltAt` says when it was built, and the console grows a persistent banner with **Restart now**
|
||||
(`POST /api/system/update/restart`; `409 nothing_pending` when there is nothing to activate, `409`
|
||||
while a job runs, `400` without a hook). The `supervised` field comes from environment markers
|
||||
(launchd's `XPC_SERVICE_NAME`, systemd's `INVOCATION_ID`/`JOURNAL_STREAM`) and only decides the tick's
|
||||
default.
|
||||
while a job runs, `400` when unavailable). The console uses the `autoRestart` field as its default.
|
||||
|
||||
**And the page recovers by itself.** While the process is down the console becomes a recovery view
|
||||
that probes the status endpoint every 2 seconds: a 200 means the old process is still answering (keep
|
||||
waiting), a dead connection means it is on its way out, and a 401 from a process that no longer knows
|
||||
the session is the proof the restart happened - the page then `location.replace`s itself back to
|
||||
`#system-update`. Leaving the console stops the watching instead of yanking the user back.
|
||||
**The page reloads automatically.** The console polls the session validation endpoint every two
|
||||
seconds for the new boot marker. Sessions live in memory, so users sign in again after the switch.
|
||||
Leaving the console stops the polling.
|
||||
|
||||
## Adding a Business Module
|
||||
|
||||
|
||||
@@ -189,9 +189,10 @@ SQLite 热备份时最好先停止服务,或至少复制 `*.db`、`*.db-wal`
|
||||
并被页面标出,装好 go 后再点一次「一键更新」即补编译。
|
||||
细节见 [开发者指南](developer-guide.md) 的「一键更新」一节。
|
||||
|
||||
检测到 systemd/launchd(环境里有对应启动标记)时,"更新完成后退出进程"默认勾选:更新成功后进程退出、
|
||||
由守护拉起新二进制,页面会在服务回来时自动刷新(会话在内存里,需要重新登录一次)。忘勾、或在命令行
|
||||
换过二进制时,控制台顶部有常驻横幅和「立即重启服务」补上这一步——不必再登录服务器手动重启。
|
||||
在 macOS/Linux 上,从配置文件同目录的 `cyberstrike-ai` 启动时,控制台默认在构建成功后自动切换到新二进制。
|
||||
构建期间旧服务继续提供服务;切换时连接会短暂中断,页面在新服务应答后自动刷新(内存中的登录会话需重新登录)。
|
||||
这一步不依赖 systemd 或 launchd;长期部署仍建议用守护进程做开机自启和异常恢复。取消自动切换、或在命令行换过
|
||||
二进制后,可以在支持自动切换的安装上用控制台的「立即重启服务」启用磁盘上的版本。
|
||||
|
||||
更新源是 `config.yaml` `update` 段里的**一个仓库地址**(`repo`),也可以直接在控制台「一键更新」页填写保存:
|
||||
想跟随官方仓库、自己的二开、别人的二开或镜像,改的都是这一处;不写就是官方仓库。**用 Release 包解压安装、
|
||||
|
||||
@@ -54,7 +54,7 @@ go run ./cmd/server --config config.yaml
|
||||
|
||||
| 入口 | 怎么用 |
|
||||
|---|---|
|
||||
| 控制台 | 「系统设置 → 一键更新」(`#system-update` 老深链仍可用)。打开这一区只读本机状态、不联网;点「检查更新」才去 fetch;「一键更新」发起任务并轮询进度;"更新完成后退出进程"在检测到守护进程(launchd/systemd 的启动标记)时默认勾选,重启期间页面守着重连、新进程一应答就自动刷新(会话在内存里,刷新后需重新登录);另有回滚按钮 |
|
||||
| 控制台 | 「系统设置 → 一键更新」(`#system-update` 老深链仍可用)。「一键更新」发起任务并轮询进度;支持自动切换的安装默认在构建成功后切到新二进制,页面在服务恢复后自动刷新;另有回滚按钮 |
|
||||
| REST | `GET /api/system/update`(磁盘现状,不联网)、`POST /api/system/update/check`(fetch 后报告差集)、`POST /api/system/update/apply`(`202` 返回 `job_id`,用 `GET /api/system/update/job` 轮询)、`POST /api/system/update/rollback` |
|
||||
| CLI | `./cyberstrike-ai -check-update`、`./cyberstrike-ai -update`、`./cyberstrike-ai -update-rollback`。安装目录 = `--config` 所在目录,未给 `--config` 时是当前目录 |
|
||||
|
||||
@@ -141,21 +141,19 @@ update:
|
||||
`rollbackPending` 提示会暂停新更新。保留恢复记录、备份目录和 `.prev`,不要手动删除它们。
|
||||
如果记录中的二进制哈希无法与现场对应,会拒绝覆盖并保留现场。
|
||||
|
||||
### 重启的两种情形
|
||||
### 切换到新二进制
|
||||
|
||||
进程只有在请求显式带 `restart: true`、且启动时装配了重启钩子时才会优雅退出(`Shutdown` 后退出码 0)。
|
||||
能不能被拉起来取决于外部守护(systemd、`run.sh`),页面如实这么写,而不是承诺一次可能不发生的启动;
|
||||
没装配钩子时要求重启是 `400`,而不是先停掉服务再自称重启了。
|
||||
macOS/Linux 上,从配置文件同目录的 `cyberstrike-ai` 启动时,控制台默认发送 `restart: true`。
|
||||
只有成功构建并换入二进制才会切换:服务先关闭应用资源,再用相同 PID、启动参数、环境和工作目录执行新二进制。
|
||||
不支持的启动方式不提供自动切换;REST 显式请求重启时返回 `400`。REST 不传该字段和 CLI 更新都只换磁盘文件。
|
||||
|
||||
**待生效状态是持久的、可补重启。** 状态接口对比"启动时记下的二进制身份(大小 + 纳秒 mtime)"与磁盘
|
||||
现值:更新、回滚或 CLI 换过二进制而没重启时,`needsRestart` 为真、`binaryBuiltAt` 给出构建时间,
|
||||
控制台顶部出现常驻横幅与「立即重启服务」(`POST /api/system/update/restart`;没有待生效版本时
|
||||
`409 nothing_pending`、有任务在跑 `409`、没钩子 `400`)。`supervised` 字段来自环境标记(launchd 的
|
||||
`XPC_SERVICE_NAME`、systemd 的 `INVOCATION_ID`/`JOURNAL_STREAM`),只用来决定勾选框的默认值。
|
||||
`409 nothing_pending`、有任务在跑 `409`、不支持时 `400`)。控制台根据 `autoRestart` 决定默认值。
|
||||
|
||||
**重启后页面自己回来。** 重启期间控制台换成自恢复视图,每 2 秒探一次状态接口:旧进程还在应答(200)
|
||||
就继续等;连不上说明正在退出;新进程接客但对旧会话只回 401——这就是"重启已完成"的判据,页面随即
|
||||
`location.replace` 回 `#system-update` 整页刷新。离开控制台则静默停表,不把已经走开的用户拽回来。
|
||||
**重启后页面自动刷新。** 控制台每 2 秒通过会话验证接口探测服务启动标记,收到新标记才刷新。
|
||||
现有登录会话保存在内存中,切换后需要重新登录。离开控制台则停止探测。
|
||||
|
||||
## 数据库
|
||||
|
||||
|
||||
Reference in new issue
Block a user