horizon-server update: wait for the old game after a rollback; document updates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-19 05:30:21 +02:00
parent 857a88351f
commit bf2c5e7946
3 changed files with 75 additions and 23 deletions
+21 -6
View File
@@ -505,15 +505,30 @@ fn switch_to(dir: &Path, install: &Install, tag: &str, timeout: Duration) -> Res
std::thread::sleep(Duration::from_millis(500));
let status = client.call("GET", "/api/v1/status", None)?;
if finished(&status) > before {
println!();
let update = &status["update"];
let last = update["last"].as_str().unwrap_or_default().to_owned();
return if update["ok"] == true {
println!("{last}");
Ok(())
if update["ok"] == true {
println!("\n{last}");
return Ok(());
}
// Rolled back (or stayed): say so once the game is up again on the release it went back to.
let mut phase = status["phase"].as_str().unwrap_or_default().to_owned();
let until = Instant::now() + crate::api::UPDATE_TIMEOUT;
while phase != "running" && phase != "stopping" && Instant::now() < until {
std::thread::sleep(Duration::from_millis(500));
print!(".");
let _ = std::io::Write::flush(&mut std::io::stdout());
phase = client.call("GET", "/api/v1/status", None)?["phase"]
.as_str()
.unwrap_or_default()
.to_owned();
}
println!();
return Err(if phase == "running" {
format!("{last}. The game is up again.")
} else {
Err(last)
};
last
});
}
if Instant::now() > deadline {
println!();
+22 -3
View File
@@ -204,6 +204,8 @@ horizon-server restore BACKUP [--yes]
horizon-server service install|uninstall|print [--system]
horizon-server panel a one-time login link for the web panel
horizon-server import FILE server.toml from a vanilla server.properties
horizon-server update [--check] install the newest release and restart on it (below)
horizon-server rollback back to the release before
```
While the server runs, `op`, `whitelist` and `cmd` go to the game's console, so they act exactly as vanilla's
@@ -213,14 +215,31 @@ console commands do. While it's stopped, they edit vanilla's files directly. Any
The server restarts the game by itself if it crashes: after 5 s, then waiting longer each time, up to 5
minutes. It keeps the crash report and gives up after 5 crashes in 10 minutes, and `status` says why.
Coming: `update` and `rollback`, `console` (attach to a server running in the background), `ban` and
`pardon` as their own commands, and `mcp` (an MCP server so an AI assistant can run the server).
**Updates** (a server installed with the install script). The server checks for a newer release a minute
after it starts and every 6 hours after, and says so in its log, in `status` and in the panel; it never
updates by itself. `horizon-server update --check` asks once. `horizon-server update`:
1. downloads the newest release and checks it against the SHA-256 GitHub publishes for it;
2. stops the game, backs up the world (`backups/<time>-before-<release>.zip`) and switches to the new
release;
3. starts the game on it and waits up to 5 minutes (`--timeout SECONDS`) for it to come up.
If the new game crashes or doesn't come up in time, the server goes back to the release it was on by itself
and puts the world back as it was just before the switch (the world the new game left is kept in
`backups/`). `horizon-server rollback` goes back to the release before by hand, keeping the world as it is
(it backs it up first). `--version vX.Y.Z` installs a given release, and `--archive FILE --version NAME` an
archive you have, such as your own build. A stopped server is switched and starts on the new release next
time. Set `HORIZON_NO_UPDATE_CHECK=1` in the server's environment to turn the check off.
Coming: `console` (attach to a server running in the background), `ban` and `pardon` as their own
commands, and `mcp` (an MCP server so an AI assistant can run the server).
## 6. Web panel
The panel runs inside `horizon-server` while the server runs. It shows live TPS, MSPT, RAM and CPU graphs for
the last 10 minutes, the players with their ping (and a kick button), the console with a command line, and the
backups (back up now, restore with a confirmation), with Restart and Stop.
backups (back up now, restore with a confirmation), with Restart and Stop. When a newer release is out it says
so, with an Update button that runs `horizon-server update` (section 5), and shows how it went.
```sh
horizon-server panel
+32 -14
View File
@@ -325,11 +325,12 @@ horizon-server backup [NAME] backups restore <backup> [-
horizon-server import <server.properties>
horizon-server service install|uninstall|print [--system]
horizon-server panel the panel's address and a one-time login link
horizon-server update [--check] [--version vX.Y.Z] [--timeout S] rollback [--timeout S]
horizon-server update --archive FILE --version NAME an archive you have (your own build)
Planned:
horizon-server console attach: the live log, and send commands (Ctrl-D detaches)
horizon-server ban|pardon <player> [reason] ban-ip|pardon-ip <address> (`cmd ban …` works now)
horizon-server update [--check] [--version vX.Y.Z] rollback
horizon-server import-resources <dir> prepare --server-jar PATH
horizon-server mcp MCP server on stdio (section 8)
```
@@ -350,8 +351,11 @@ line), and backups (list, back up now, restore with confirmation), with restart
the supervisor, so it is up exactly when the server is: starting a stopped server stays a command (or the
service manager's job). Whitelist and bans go through the console for now.
**Later:** bans and IP bans, worlds, updates with rollback, `server.properties` import, logs and crash
reports, and modpacks (with the modpack work).
**Updates:** when a newer release is out, the panel says so with an Update button, which runs the same
path as `horizon-server update` (section 7) and then shows how it went.
**Later:** bans and IP bans, worlds, `server.properties` import, logs and crash reports, and modpacks (with
the modpack work).
**Tech:** one HTML page with plain JS and CSS (`crates/horizon-server/panel/`), embedded in the binary with
`include_str!`. No build step, no framework, no CDN. It uses Horizon's design system tokens (`horizon-theme`'s
@@ -393,16 +397,29 @@ runtime or new dependency. Server-sent events can replace the polling later if a
lines and the engine's crash report (`crash-reports/`), restarts it after 5 s, and doubles the wait up to
5 minutes. It gives up after 5 crashes in 10 minutes, so it doesn't loop on a broken world, and shows the
reason in `status` and the panel.
- **Updates.** `update --check` compares with the latest GitHub release. `update`:
1. downloads the server archive and checks its SHA-256;
2. backs up the world;
3. keeps the current binaries as `.horizon/previous/`;
4. swaps in the new ones and restarts;
5. watches for `Done` within the start timeout and a first status reply.
- **Updates** (`crates/horizon-server/src/update.rs`), for a `horizon-server` installed by `install.sh` or
`install.ps1`. Releases ship often (release-flow.md), so updates stay opt-in: a running server looks for a
newer release a minute after it starts and then every 6 hours, and only says so, in its log, in `status`
and in the panel (`HORIZON_NO_UPDATE_CHECK=1` turns the check off). `update --check` asks GitHub once.
`update`:
1. downloads the release archive for this computer (on Linux the server build) and checks it against the
SHA-256 GitHub publishes for it;
2. unpacks it into `<dir>/releases/<tag>`, beside the others, with its game files linked to
`<dir>/game-files` as the installers do;
3. stops the game, backs up the world (`backups/<time>-before-<tag>.zip`), records the release in use in
`<dir>/previous` and points `<dir>/current` at the new one;
4. checks that the new game loads on this system (`--help`), then starts it;
5. waits until it has logged `Done` and answered a status request, for 300 s (`--timeout`).
If that check fails, it puts the previous binaries back, restores the world if the new engine touched it,
and restarts. `rollback` does the same by hand. Releases ship often (release-flow.md), so updates stay
opt-in, with `update --check` in `status` and a notice in the panel.
If the new game doesn't load, stops, or isn't up in time, the supervisor goes back by itself: `current`
points at the release before, `previous` is left as it was, the world is put back from the backup (the
one the new game left is kept in `backups/replaced-<time>/`), and the game starts again on the old
release. `rollback` switches to `previous` by hand, through the same path (the world is backed up first
and kept as it is). The supervisor keeps running as it was: the new `horizon-server` itself takes over
the next time the server starts (`stop` and `start`, or the service's restart). A stopped server is
switched and its new game checked to load; it starts on the new release next time. One install serves
every server folder on the machine, so each one runs the new release from its next start. Old releases
stay in `<dir>/releases/` until they are deleted by hand (keep `current` and `previous`).
## 8. Control API and MCP
@@ -411,7 +428,9 @@ runtime or new dependency. Server-sent events can replace the polling later if a
`.horizon/api.json`. It's plain HTTP/1.1 on `std::net` (`crates/horizon-server/src/http.rs`), no runtime.
- built (PR 2b, 2c): `GET status` (phase, uptime, crashes, RSS, CPU, and the engine's TPS, MSPT
average/P50/P95/P99, players, chunks), `GET logs?since=`, `POST command {line}` (returns the output),
`POST stop`, `POST restart`, `GET backups`, `POST backups {name}`, `POST restore {name}`;
`POST stop`, `POST restart`, `GET backups`, `POST backups {name}`, `POST restore {name}`, `POST update
{tag, timeout}` (without a tag: the newest release, downloaded first; `status` has an `update` object
that says how it went);
- planned: `GET metrics?since=` (the panel's graphs), `GET events` (SSE: log lines and metrics),
`GET`/`PATCH config` (server.toml fields, validated).
- **Auth.** Every call needs `Authorization: Bearer <token from .horizon/api.json>` (file mode 0600), and the
@@ -553,7 +572,6 @@ machine, then published in `benchmarks/`; and item 5.
- the Nether and End for remote players;
- the headless engine and its RAM win;
- a server-only prepare without a JDK;
- updates and rollback (the design is above; they ship right after);
- a Windows service, hot reload, modpacks in the panel;
- Paper and Fabric + Lithium in the benchmark;
- the website's "host a server" page;