diff --git a/deploy/cosmic-clash-server b/deploy/cosmic-clash-server index bb0152a0..96fbe9d6 100644 --- a/deploy/cosmic-clash-server +++ b/deploy/cosmic-clash-server @@ -3,4 +3,21 @@ # is baked into the dedicated artifact during the Docker export stage. set -eu +# Godot's stdout is fully (block) buffered rather than line-buffered whenever +# it isn't attached to a TTY -- true of every real deployment of this script: +# `docker run -d` (Docker's log driver presents a pipe, not a TTY), a plain +# `docker run` even without -d, and systemd's journal capture (also a pipe). +# Verified directly: a `docker run -d` container sat for 20+ seconds with +# `docker logs` showing nothing at all, including the startup line, while the +# process was confirmed alive and running; docker stop's SIGTERM (Godot has +# no SIGTERM hook, see SERVER.md) then killed it without ever flushing that +# buffered output, losing it permanently rather than merely delaying it. +# `stdbuf -oL -eL` forces line buffering via LD_PRELOAD without touching the +# binary; re-verified the same scenario then shows the startup line within +# 3s. Fall back to running unwrapped if stdbuf isn't available (e.g. a +# minimal image without GNU coreutils) rather than failing to start at all -- +# a server with delayed logs is still far better than no server. +if command -v stdbuf >/dev/null 2>&1; then + exec stdbuf -oL -eL "$(dirname "$0")/CosmicClashServer.x86_64" --headless -- "$@" +fi exec "$(dirname "$0")/CosmicClashServer.x86_64" --headless -- "$@"