[PR #552] [MERGED] horizon-server: start, stop, status, cmd and logs through a local control API #2638

Closed
opened 2026-11-02 15:57:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: feat/horizon-server-control


📝 Commits (4)

  • 9d21209 horizon-server: server.toml, init, and a supervisor that runs the game
  • e883219 horizon-server: start, stop, status, cmd and logs through a local control API
  • 07f7e3a Merge remote-tracking branch 'origin/main' into srv-fix
  • 2483f90 Merge feat/horizon-server into feat/horizon-server-control

📊 Changes

24 files changed (+2830 additions, -6 deletions)

View changed files

📝 Cargo.lock (+26 -0)
📝 Cargo.toml (+1 -1)
📝 crates/horizon-client/Cargo.toml (+2 -0)
📝 crates/horizon-client/src/game/dedicated.rs (+30 -0)
➕ crates/horizon-client/src/game/dedicated/status.rs (+100 -0)
📝 crates/horizon-client/src/lib.rs (+1 -1)
➕ crates/horizon-server-files/Cargo.toml (+16 -0)
📝 crates/horizon-server-files/src/eula.rs (+6 -1)
📝 crates/horizon-server-files/src/java_properties.rs (+0 -0)
📝 crates/horizon-server-files/src/json.rs (+0 -0)
📝 crates/horizon-server-files/src/lib.rs (+3 -3)
📝 crates/horizon-server-files/src/properties.rs (+0 -0)
📝 crates/horizon-server-files/src/user_lists.rs (+0 -0)
➕ crates/horizon-server/Cargo.toml (+27 -0)
➕ crates/horizon-server/src/api.rs (+378 -0)
➕ crates/horizon-server/src/cli.rs (+329 -0)
➕ crates/horizon-server/src/config.rs (+515 -0)
➕ crates/horizon-server/src/engine.rs (+182 -0)
➕ crates/horizon-server/src/http.rs (+219 -0)
➕ crates/horizon-server/src/init.rs (+276 -0)

...and 4 more files

📄 Description

PR 2b of docs/server.md (section 11), stacked on #551: manage a server that runs in the background.

What it does

  • Control API. The supervisor serves a small HTTP/JSON API (hand-written on std::net, with no runtime and no new dependency).
    • It listens on 127.0.0.1 at a port the system picks, with a random token in .horizon/api.json (mode 0600), and checks the Host header.
    • Routes: GET status, GET logs?since=, POST command, POST stop, POST restart.
  • CLI.
    • start runs the server in the background and returns once the game is up.
    • stop saves and waits; restart waits until the new game is up.
    • status [--json] shows TPS, MSPT (average and P95), players, RAM and CPU.
    • cmd COMMAND... runs one console command and prints its output. It waits for a game that is starting.
    • logs [-f] [-n N].
    • op, deop and whitelist go through the running game when there is one.
  • Engine side (game/dedicated.rs, additive, about 30 lines, plus a new game/dedicated/status.rs). On the existing control endpoint (--control-socket), the dedicated loop answers:
    • server-status: TPS over 5 s, MSPT average/P50/P95/P99, players with ping, chunks, paused;
    • console <line>: the lines the command logged.
  • Fix: the dedicated loop never recorded its tick times in the game clock (only the windowed loop did), so /tick query on a dedicated server always said 0 ms. It now reports real numbers, as vanilla does. The bot benchmark (#556) relies on that to measure Horizon and vanilla the same way.

perf-ticks-2's #544/#545 touch dedicated.rs in another place (listen: true); the hunks don't overlap.

Tested by hand

On a real world: start, status, cmd list, cmd tick query, op while running, logs, restart (12 s, back up), stop (saves, 5 s). A server run with stdin closed (Docker, services) keeps running.

$ horizon-server status
Running, up 17 s
TPS 20.0, MSPT 1.6 ms average, 7.4 ms P95
RAM 1.39 GB, CPU 2 % of a core
$ horizon-server cmd tick query
The game is running normally
Target tick rate: 20.0 per second.
Average time per tick: 1.3ms (Target: 50.0ms)
Percentiles: P50: 0.7ms P95: 5.6ms P99: 8.8ms. Sample: 100

Checks

  • cargo fmt --all --check: clean.
  • cargo clippy --workspace --all-targets -- -D warnings: clean on every branch of the stack.
  • Tests: cargo test -p horizon-server -p horizon-server-files pass on every branch (16 server tests in 2a, 24 at the tip). horizon-server also passes clippy and its tests on Linux (the ThinkPad).
  • Parity at the stack's tip (2a–3), rebased on b4ad6538:
    • tools/parity.py dedicated_server online_mode server_files server_player_combat server_player_damage: 5 passed, 0 failed. dedicated_server includes vanilla's protocol client joining Horizon's server.
    • The full --changed origin/main set (309 harnesses, because the client crate changes) had 60 passed, 0 failed when it was stopped. The Mac mini was running out of disk, and at about 1 harness a minute the run needed 4 more hours. CI's parity covers the rest.

🤖 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/552 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/horizon-server-control` --- ### 📝 Commits (4) - [`9d21209`](https://github.com/horizon-rust/horizon/commit/9d21209ae8c4e6f788955abab69e7b96d1ef3237) horizon-server: server.toml, init, and a supervisor that runs the game - [`e883219`](https://github.com/horizon-rust/horizon/commit/e8832190d1017de6d23eb66c0b8dc75ca35cc95f) horizon-server: start, stop, status, cmd and logs through a local control API - [`07f7e3a`](https://github.com/horizon-rust/horizon/commit/07f7e3aeab80a1d3d3c76ef5b643eaaf1fa48fde) Merge remote-tracking branch 'origin/main' into srv-fix - [`2483f90`](https://github.com/horizon-rust/horizon/commit/2483f90779fa37882f4a3ceb3073fb9947e5e22b) Merge feat/horizon-server into feat/horizon-server-control ### 📊 Changes **24 files changed** (+2830 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+26 -0) 📝 `Cargo.toml` (+1 -1) 📝 `crates/horizon-client/Cargo.toml` (+2 -0) 📝 `crates/horizon-client/src/game/dedicated.rs` (+30 -0) ➕ `crates/horizon-client/src/game/dedicated/status.rs` (+100 -0) 📝 `crates/horizon-client/src/lib.rs` (+1 -1) ➕ `crates/horizon-server-files/Cargo.toml` (+16 -0) 📝 `crates/horizon-server-files/src/eula.rs` (+6 -1) 📝 `crates/horizon-server-files/src/java_properties.rs` (+0 -0) 📝 `crates/horizon-server-files/src/json.rs` (+0 -0) 📝 `crates/horizon-server-files/src/lib.rs` (+3 -3) 📝 `crates/horizon-server-files/src/properties.rs` (+0 -0) 📝 `crates/horizon-server-files/src/user_lists.rs` (+0 -0) ➕ `crates/horizon-server/Cargo.toml` (+27 -0) ➕ `crates/horizon-server/src/api.rs` (+378 -0) ➕ `crates/horizon-server/src/cli.rs` (+329 -0) ➕ `crates/horizon-server/src/config.rs` (+515 -0) ➕ `crates/horizon-server/src/engine.rs` (+182 -0) ➕ `crates/horizon-server/src/http.rs` (+219 -0) ➕ `crates/horizon-server/src/init.rs` (+276 -0) _...and 4 more files_ </details> ### 📄 Description PR 2b of [docs/server.md](https://github.com/ludovic111/horizon/pull/557) (section 11), stacked on #551: manage a server that runs in the background. ## What it does - **Control API.** The supervisor serves a small HTTP/JSON API (hand-written on `std::net`, with no runtime and no new dependency). - It listens on `127.0.0.1` at a port the system picks, with a random token in `.horizon/api.json` (mode 0600), and checks the Host header. - Routes: `GET status`, `GET logs?since=`, `POST command`, `POST stop`, `POST restart`. - **CLI.** - `start` runs the server in the background and returns once the game is up. - `stop` saves and waits; `restart` waits until the new game is up. - `status [--json]` shows TPS, MSPT (average and P95), players, RAM and CPU. - `cmd COMMAND...` runs one console command and prints its output. It waits for a game that is starting. - `logs [-f] [-n N]`. - `op`, `deop` and `whitelist` go through the running game when there is one. - **Engine side** (`game/dedicated.rs`, additive, about 30 lines, plus a new `game/dedicated/status.rs`). On the existing control endpoint (`--control-socket`), the dedicated loop answers: - `server-status`: TPS over 5 s, MSPT average/P50/P95/P99, players with ping, chunks, paused; - `console <line>`: the lines the command logged. - **Fix:** the dedicated loop never recorded its tick times in the game clock (only the windowed loop did), so `/tick query` on a dedicated server always said 0 ms. It now reports real numbers, as vanilla does. The bot benchmark (#556) relies on that to measure Horizon and vanilla the same way. perf-ticks-2's #544/#545 touch `dedicated.rs` in another place (`listen: true`); the hunks don't overlap. ## Tested by hand On a real world: `start`, `status`, `cmd list`, `cmd tick query`, `op` while running, `logs`, `restart` (12 s, back up), `stop` (saves, 5 s). A server run with stdin closed (Docker, services) keeps running. ``` $ horizon-server status Running, up 17 s TPS 20.0, MSPT 1.6 ms average, 7.4 ms P95 RAM 1.39 GB, CPU 2 % of a core $ horizon-server cmd tick query The game is running normally Target tick rate: 20.0 per second. Average time per tick: 1.3ms (Target: 50.0ms) Percentiles: P50: 0.7ms P95: 5.6ms P99: 8.8ms. Sample: 100 ``` ## Checks - `cargo fmt --all --check`: clean. - `cargo clippy --workspace --all-targets -- -D warnings`: clean on every branch of the stack. - Tests: `cargo test -p horizon-server -p horizon-server-files` pass on every branch (16 server tests in 2a, 24 at the tip). horizon-server also passes clippy and its tests on Linux (the ThinkPad). - Parity at the stack's tip (2a–3), rebased on b4ad6538: - `tools/parity.py dedicated_server online_mode server_files server_player_combat server_player_damage`: **5 passed, 0 failed**. `dedicated_server` includes vanilla's protocol client joining Horizon's server. - The full `--changed origin/main` set (309 harnesses, because the client crate changes) had **60 passed, 0 failed** when it was stopped. The Mac mini was running out of disk, and at about 1 harness a minute the run needed 4 more hours. CI's parity covers the rest. 🤖 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 15:57:50 +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#2638
No description provided.