N7: Dedicated server packaging, health endpoint and graceful shutdown

- packaging/server/tidewall-server: a wrapper that turns SIGTERM and SIGINT
  into a clean stop through the server's new --stop-file, since the engine
  can't catch signals. The server tells everyone it shut down, logs its
  statistics and exits 0; the wrapper kills it only after 15 s.
- --config=PATH reads options from a file (packaging/server/server.cfg);
  options after it on the command line win.
- --health-port answers GET /health with JSON (phase, players, tick, uptime)
  on loopback by default. HealthServer is non-blocking and bounded.
- packaging/docker: a debian:13 image that checks the engine against
  tools/engine.sha512, imports the game at build time, runs as an unprivileged
  user, and works with a read-only root and a small /tmp. compose.yaml is
  project and container tidewall-server, read-only, no capabilities.
- packaging/systemd: a hardened unit with a dynamic user.
- make server-package-check: compose up, healthy, non-root, read-only, a real
  headless client joins over UDP into the drop, then SIGTERM stops it cleanly.

This also covers H7 (graceful shutdown on SIGTERM).

Closes #38
Closes #70

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 22:07:24 -05:00
co-authored by Claude Opus 5.5
parent 05c7568ec1
commit 8eb6e587fb
17 changed files with 644 additions and 2 deletions
+34
View File
@@ -119,3 +119,37 @@ func test_soak_options() -> void:
assert_false(_parse(["--server", "--world-hash-every=300"]).is_valid(), "hashes are only logged when listening")
assert_false(_parse(["--server", "--matches=-1"]).is_valid())
func test_config_file_and_command_line_order() -> void:
var path: String = "user://test_server.cfg"
var file: FileAccess = FileAccess.open(path, FileAccess.WRITE)
file.store_string("# a comment\n\nlisten\nport = 24700\nname = Harbour Light\nhealth-port = 24700\nno-lan\n")
file.close()
var config: ServerConfig = _parse(["--server", "--config=" + path, "--port=24702"])
assert_true(config.is_valid(), str(config.errors))
assert_true(config.listen)
assert_false(config.lan)
assert_eq(config.port, 24702, "the command line after --config wins")
assert_eq(config.server_name, "Harbour Light")
assert_eq(config.health_port, 24700)
assert_eq(config.health_bind, "127.0.0.1")
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
func test_config_file_problems_are_errors() -> void:
assert_false(_parse(["--server", "--config=user://no_such_file.cfg"]).is_valid())
var path: String = "user://test_bad_server.cfg"
var file: FileAccess = FileAccess.open(path, FileAccess.WRITE)
file.store_string("listen\nprot = 5\nconfig = other.cfg\n")
file.close()
var config: ServerConfig = _parse(["--server", "--config=" + path])
assert_eq(config.errors.size(), 2, str(config.errors))
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
func test_health_and_stop_options() -> void:
var config: ServerConfig = _parse(["--server", "--listen", "--health-port=8080", "--health-bind=0.0.0.0", "--stop-file=/tmp/x"])
assert_true(config.is_valid(), str(config.errors))
assert_eq([config.health_port, config.health_bind, config.stop_file], [8080, "0.0.0.0", "/tmp/x"])
assert_false(_parse(["--server", "--health-bind=localhost"]).is_valid())
assert_false(_parse(["--server", "--health-port=70000"]).is_valid())