[PR #966] [MERGED] horizon-server update and rollback: switch releases, roll back by itself when the game doesn't come up #2948

Closed
opened 2026-11-02 16:00:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/966
Author: @ludovic111
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/19/2026
Merged by: @ludovic111

Base: main ← Head: feat/server-update


📝 Commits (4)

  • a8682eb horizon-server: give the game its folders whole when --dir is relative
  • 857a883 horizon-server update and rollback: switch releases, roll back by itself when the game doesn't come up
  • bf2c5e7 horizon-server update: wait for the old game after a rollback; document updates
  • 3ce89eb horizon-server update: report a switch without an install instead of staying busy

📊 Changes

14 files changed (+1452 additions, -33 deletions)

View changed files

📝 Cargo.lock (+2 -0)
📝 crates/horizon-server/Cargo.toml (+4 -0)
📝 crates/horizon-server/panel/index.html (+5 -0)
📝 crates/horizon-server/panel/panel.css (+14 -0)
📝 crates/horizon-server/panel/panel.js (+21 -0)
📝 crates/horizon-server/src/api.rs (+137 -2)
📝 crates/horizon-server/src/cli.rs (+22 -0)
📝 crates/horizon-server/src/engine.rs (+55 -6)
📝 crates/horizon-server/src/main.rs (+8 -0)
📝 crates/horizon-server/src/panel.rs (+1 -1)
📝 crates/horizon-server/src/supervisor.rs (+365 -6)
➕ crates/horizon-server/src/update.rs (+763 -0)
📝 docs/hosting.md (+22 -3)
📝 docs/server.md (+33 -15)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Stacked on #965 (its one commit is the first here): merge #965 first.

What

horizon-server update and horizon-server rollback (docs/server.md section 7), for a server installed by install.sh / install.ps1 (<dir>/releases/<tag>, <dir>/current):

  • update downloads the newest release's archive for this computer (on Linux the server build) and checks it against the SHA-256 GitHub publishes. It unpacks the archive into releases/<tag> with the game files linked, as the installers do. A running server then restarts through its supervisor:
    1. it stops the game;
    2. it backs up the world (backups/<time>-before-<tag>.zip);
    3. it records the release in use in <dir>/previous and points current at the new one;
    4. it checks that the new game loads (--help) and starts it;
    5. it waits until the game has logged Done and answered a status request from this process (300 s, --timeout).
  • Rolls back by itself if the new game won't load, crashes, stops, or isn't up in time. current goes back, previous is left as it was (so a later rollback doesn't pick the broken release), and the world comes back from the pre-switch backup. The world the new game left is kept in backups/replaced-<time>/. The old game then starts again, and the CLI returns once it is up.
  • rollback switches to previous by hand through the same path. It backs the world up first and keeps it as it is.
  • update --check; --version vX.Y.Z; --archive FILE --version NAME for an archive you have.
  • A stopped server is backed up, switched and its new game checked to load. Outside a server folder, only the install is switched.
  • Update check: a running installed server looks for a newer release a minute after start and every 6 h, and only reports it: in its log, in status (Horizon vX is out…) and in the panel. HORIZON_NO_UPDATE_CHECK=1 turns it off.
  • Panel: a notice with an Update button when a release is out (POST /api/v1/update {}: the supervisor downloads, then the same path). It shows what's under way, and a failed update's outcome.
  • API: POST /api/v1/update {tag?, timeout?}; status gets an update object (installed, previous, available, busy, last, ok, finished).
  • engine::program now looks in the install's current (not beside the running supervisor binary), and the supervisor re-resolves the program before every start. That is what makes a switch apply.

Design choice: the supervisor process keeps running through an update. The health check and the rollback therefore run in the known-good old code. The new horizon-server binary itself takes over at the next full start (stop/start, or the service restart), and the docs say so.

Deps: sha2 and ureq (both already in the lockfile; ureq was already linked through horizon-server-files). .tar.gz unpacks with the system tar, as install.sh does; .zip uses the zip crate the backups use.

How tested

Unit tests (37 pass): tag ordering; picking this computer's asset with its digest; switch/switch_back keeping previous; unpacking a real tar.gz beside the others (exec bits, game-files link, the release in use refused, an archive without horizon-server refused, no scratch left); the supervisor's switch (backup made, current moved, a game that can't load never switched to); roll_back (release and previous restored, world restored, the new game's world kept); up (needs Done and a status reply from this engine pid).

End to end on the Mac mini (macOS arm64, real game): a v2026.10.19 release archive repackaged with this branch's horizon-server, installed with install.sh --archive, init, start:

=== start on v2026.10.18.1 / wait 70 s for the update check
Horizon v2026.10.19.01 is out (this server runs v2026.10.18.1): `horizon-server update` installs it
=== update to B (healthy)
Restarting the server on v2026.10.18.2...........................
Now on v2026.10.18.2 (was v2026.10.18.1): the game is up
=== update to C (a game that exits 3 after --help)
horizon-server: Rolled back to v2026.10.18.5: v2026.10.18.6 didn't come up (the game stopped (exit status: 3)); the world is back as it was before the switch (the one v2026.10.18.6 left is in srv/backups/replaced-2026-10-19_03-28-41/world). The game is up again.
=== update to D (a game that never logs Done), --timeout 20
horizon-server: Rolled back to v2026.10.18.2: v2026.10.18.4 didn't come up (the game wasn't up in time); the world is back as it was before the switch (...)
=== rollback by hand
Now on v2026.10.18.1 (was v2026.10.18.2): the game is up      (previous = v2026.10.18.2, not the broken ones)
=== POST /api/v1/update {} (the panel's path: real download of v2026.10.19.01 from GitHub, SHA-256 checked)
Now on v2026.10.19.01 (was v2026.10.18.1): the game is up
=== stopped server: rollback, then update --archive
Switched from v2026.10.19.01 to v2026.10.18.1. The world is backed up in backups/…-before-v2026-10-18-1.zip. The server is stopped: …

(The C line comes from a rerun after the last commit, so its tags are higher.) Five before-<tag> backups were left in backups/. The ThinkPad (Linux, server archive) run comes as a comment once the benchmark that is using the ThinkPad finishes.

Self-check: cargo fmt -p horizon-server -- --check, cargo clippy -p horizon-server --all-targets -- -D warnings: clean. cargo test -p horizon-server: 37 passed. No game code changed, so no harness covers this crate (tools/parity.py --changed lists all 323; CI runs them).

Not checked: Windows (the mklink /J switch is written to match install.ps1's junctions, but has not run on Windows).

Needs nothing from Ludovic.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/966 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/server-update` --- ### 📝 Commits (4) - [`a8682eb`](https://github.com/horizon-rust/horizon/commit/a8682eb4c55c5b9032902ec5ff71ee2a0b52b380) horizon-server: give the game its folders whole when --dir is relative - [`857a883`](https://github.com/horizon-rust/horizon/commit/857a88351fc354bd597a6fdbf0b9a46c863b9a1e) horizon-server update and rollback: switch releases, roll back by itself when the game doesn't come up - [`bf2c5e7`](https://github.com/horizon-rust/horizon/commit/bf2c5e79465acd7854a200c9692af84303e69a3c) horizon-server update: wait for the old game after a rollback; document updates - [`3ce89eb`](https://github.com/horizon-rust/horizon/commit/3ce89ebb8a0fb3ce21e999f81b0a417cae5267a9) horizon-server update: report a switch without an install instead of staying busy ### 📊 Changes **14 files changed** (+1452 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+2 -0) 📝 `crates/horizon-server/Cargo.toml` (+4 -0) 📝 `crates/horizon-server/panel/index.html` (+5 -0) 📝 `crates/horizon-server/panel/panel.css` (+14 -0) 📝 `crates/horizon-server/panel/panel.js` (+21 -0) 📝 `crates/horizon-server/src/api.rs` (+137 -2) 📝 `crates/horizon-server/src/cli.rs` (+22 -0) 📝 `crates/horizon-server/src/engine.rs` (+55 -6) 📝 `crates/horizon-server/src/main.rs` (+8 -0) 📝 `crates/horizon-server/src/panel.rs` (+1 -1) 📝 `crates/horizon-server/src/supervisor.rs` (+365 -6) ➕ `crates/horizon-server/src/update.rs` (+763 -0) 📝 `docs/hosting.md` (+22 -3) 📝 `docs/server.md` (+33 -15) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #965 (its one commit is the first here): merge #965 first. ## What `horizon-server update` and `horizon-server rollback` (docs/server.md section 7), for a server installed by `install.sh` / `install.ps1` (`<dir>/releases/<tag>`, `<dir>/current`): - **`update`** downloads the newest release's archive for this computer (on Linux the server build) and checks it against the SHA-256 GitHub publishes. It unpacks the archive into `releases/<tag>` with the game files linked, as the installers do. A running server then restarts through its supervisor: 1. it stops the game; 2. it backs up the world (`backups/<time>-before-<tag>.zip`); 3. it records the release in use in `<dir>/previous` and points `current` at the new one; 4. it checks that the new game loads (`--help`) and starts it; 5. it waits until the game has logged `Done` **and** answered a status request from this process (300 s, `--timeout`). - **Rolls back by itself** if the new game won't load, crashes, stops, or isn't up in time. `current` goes back, `previous` is left as it was (so a later `rollback` doesn't pick the broken release), and the world comes back from the pre-switch backup. The world the new game left is kept in `backups/replaced-<time>/`. The old game then starts again, and the CLI returns once it is up. - **`rollback`** switches to `previous` by hand through the same path. It backs the world up first and keeps it as it is. - `update --check`; `--version vX.Y.Z`; `--archive FILE --version NAME` for an archive you have. - A stopped server is backed up, switched and its new game checked to load. Outside a server folder, only the install is switched. - **Update check:** a running installed server looks for a newer release a minute after start and every 6 h, and only reports it: in its log, in `status` (`Horizon vX is out…`) and in the panel. `HORIZON_NO_UPDATE_CHECK=1` turns it off. - **Panel:** a notice with an **Update** button when a release is out (`POST /api/v1/update {}`: the supervisor downloads, then the same path). It shows what's under way, and a failed update's outcome. - API: `POST /api/v1/update {tag?, timeout?}`; `status` gets an `update` object (`installed`, `previous`, `available`, `busy`, `last`, `ok`, `finished`). - `engine::program` now looks in the install's `current` (not beside the running supervisor binary), and the supervisor re-resolves the program before every start. That is what makes a switch apply. **Design choice:** the supervisor process keeps running through an update. The health check and the rollback therefore run in the known-good old code. The new `horizon-server` binary itself takes over at the next full start (`stop`/`start`, or the service restart), and the docs say so. Deps: `sha2` and `ureq` (both already in the lockfile; `ureq` was already linked through `horizon-server-files`). `.tar.gz` unpacks with the system `tar`, as install.sh does; `.zip` uses the `zip` crate the backups use. ## How tested **Unit tests** (37 pass): tag ordering; picking this computer's asset with its digest; `switch`/`switch_back` keeping `previous`; unpacking a real tar.gz beside the others (exec bits, game-files link, the release in use refused, an archive without `horizon-server` refused, no scratch left); the supervisor's `switch` (backup made, `current` moved, a game that can't load never switched to); `roll_back` (release and `previous` restored, world restored, the new game's world kept); `up` (needs `Done` *and* a status reply from *this* engine pid). **End to end on the Mac mini** (macOS arm64, real game): a v2026.10.19 release archive repackaged with this branch's `horizon-server`, installed with `install.sh --archive`, `init`, `start`: ``` === start on v2026.10.18.1 / wait 70 s for the update check Horizon v2026.10.19.01 is out (this server runs v2026.10.18.1): `horizon-server update` installs it === update to B (healthy) Restarting the server on v2026.10.18.2........................... Now on v2026.10.18.2 (was v2026.10.18.1): the game is up === update to C (a game that exits 3 after --help) horizon-server: Rolled back to v2026.10.18.5: v2026.10.18.6 didn't come up (the game stopped (exit status: 3)); the world is back as it was before the switch (the one v2026.10.18.6 left is in srv/backups/replaced-2026-10-19_03-28-41/world). The game is up again. === update to D (a game that never logs Done), --timeout 20 horizon-server: Rolled back to v2026.10.18.2: v2026.10.18.4 didn't come up (the game wasn't up in time); the world is back as it was before the switch (...) === rollback by hand Now on v2026.10.18.1 (was v2026.10.18.2): the game is up (previous = v2026.10.18.2, not the broken ones) === POST /api/v1/update {} (the panel's path: real download of v2026.10.19.01 from GitHub, SHA-256 checked) Now on v2026.10.19.01 (was v2026.10.18.1): the game is up === stopped server: rollback, then update --archive Switched from v2026.10.19.01 to v2026.10.18.1. The world is backed up in backups/…-before-v2026-10-18-1.zip. The server is stopped: … ``` (The C line comes from a rerun after the last commit, so its tags are higher.) Five `before-<tag>` backups were left in `backups/`. The ThinkPad (Linux, server archive) run comes as a comment once the benchmark that is using the ThinkPad finishes. Self-check: `cargo fmt -p horizon-server -- --check`, `cargo clippy -p horizon-server --all-targets -- -D warnings`: clean. `cargo test -p horizon-server`: 37 passed. No game code changed, so no harness covers this crate (`tools/parity.py --changed` lists all 323; CI runs them). **Not checked:** Windows (the `mklink /J` switch is written to match install.ps1's junctions, but has not run on Windows). Needs nothing from Ludovic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 16:00:20 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2948
No description provided.