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:
@@ -0,0 +1,34 @@
|
||||
# Tidewall dedicated server configuration. Read with --config=PATH; each line is one
|
||||
# of the server's command-line options without the leading dashes (see
|
||||
# src/server/server_config.gd for all of them). Options given on the command line
|
||||
# after --config win over these.
|
||||
|
||||
# Take players over the network. Without this the server plays a bot-only match.
|
||||
listen
|
||||
|
||||
# UDP port players connect to. LAN discovery answers on this port plus one.
|
||||
port = 24650
|
||||
|
||||
# Fill each match's empty places with bots (any number above 0 turns it on).
|
||||
bots = 1
|
||||
# bot-difficulty = mixed
|
||||
|
||||
# The name shown in server browsers.
|
||||
name = Tidewall server
|
||||
|
||||
# Register with a list server so people outside the LAN can find this one.
|
||||
# list = lists.example.org:24660
|
||||
|
||||
# Don't answer LAN discovery broadcasts.
|
||||
# no-lan
|
||||
|
||||
# Answer GET /health on this TCP port, on loopback unless health-bind says otherwise.
|
||||
health-port = 24650
|
||||
# health-bind = 127.0.0.1
|
||||
|
||||
# A progress line in the log every this many ticks (30 a second). 0 for none.
|
||||
log-every = 9000
|
||||
|
||||
# A fixed seed makes every match on the island sequence repeatable. Leave it out for a
|
||||
# fresh one each start.
|
||||
# seed = 12345
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# Runs a Tidewall dedicated server and turns SIGTERM or SIGINT into a clean stop: the
|
||||
# server tells everyone connected it is shutting down, logs its statistics and exits 0.
|
||||
# The engine can't catch signals itself, so this wrapper creates the server's
|
||||
# --stop-file when one arrives, and kills the server only if it hasn't gone after
|
||||
# TIDEWALL_STOP_SECONDS (default 15).
|
||||
#
|
||||
# tidewall-server [server options...] e.g. --config=/etc/tidewall/server.cfg
|
||||
#
|
||||
# Where things are, overridable from the environment:
|
||||
# TIDEWALL_HOME the install: engine/godot and game/ (default /opt/tidewall)
|
||||
# TIDEWALL_ENGINE the engine binary (default $TIDEWALL_HOME/engine/godot)
|
||||
# TIDEWALL_GAME the game's project directory (default $TIDEWALL_HOME/game)
|
||||
# TIDEWALL_STATE a writable directory for the engine's own files and the stop file
|
||||
# (default $RUNTIME_DIRECTORY under systemd, else /tmp/tidewall-server)
|
||||
set -u
|
||||
|
||||
home="${TIDEWALL_HOME:-/opt/tidewall}"
|
||||
engine="${TIDEWALL_ENGINE:-$home/engine/godot}"
|
||||
game="${TIDEWALL_GAME:-$home/game}"
|
||||
state="${TIDEWALL_STATE:-${RUNTIME_DIRECTORY:-/tmp/tidewall-server}}"
|
||||
grace="${TIDEWALL_STOP_SECONDS:-15}"
|
||||
stop_file="$state/stop"
|
||||
|
||||
mkdir -p "$state/data" "$state/config" "$state/cache"
|
||||
rm -f "$stop_file"
|
||||
# The engine writes its user data and caches here, so the install can stay read-only.
|
||||
export XDG_DATA_HOME="$state/data" XDG_CONFIG_HOME="$state/config" XDG_CACHE_HOME="$state/cache"
|
||||
|
||||
"$engine" --headless --path "$game" -- --server --stop-file="$stop_file" "$@" &
|
||||
child=$!
|
||||
|
||||
request_stop() {
|
||||
touch "$stop_file"
|
||||
# If it hasn't stopped in time, stop it the hard way.
|
||||
( sleep "$grace"; kill -KILL "$child" 2>/dev/null ) &
|
||||
}
|
||||
trap request_stop TERM INT
|
||||
|
||||
wait "$child"
|
||||
code=$?
|
||||
# A trapped signal interrupts wait; keep waiting until the server has really gone.
|
||||
while kill -0 "$child" 2>/dev/null; do
|
||||
wait "$child"
|
||||
code=$?
|
||||
done
|
||||
exit "$code"
|
||||
Reference in New Issue
Block a user