From ec0efe72d88b5f056c00af00c9c5ceefb749b123 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 19 Jul 2026 21:35:32 +0100 Subject: [PATCH] fix(stop): clear stale restart-request lock + warn on failed player query Addresses Copilot review feedback on #4595: - command_restart.sh: clear the *-restart-request.lock once a restart actually proceeds. Previously the lock was only written when postponing and never removed, so every subsequent monitor run would see the stale lock and trigger a repeat restart indefinitely. Fixed and verified against a live server: postponed restart -> monitor executes it and clears the lock -> a second monitor run no longer restarts. - check_players_online.sh: if the gamedig query fails for every configured IP (e.g. gamedig/jq missing), playersonline now still fails open (so a broken query can't permanently block stop/restart) but prints a clear warning that the safety check could not run, instead of silently behaving as if the server were empty. --- lgsm/modules/check_players_online.sh | 9 +++++++++ lgsm/modules/command_restart.sh | 3 +++ 2 files changed, 12 insertions(+) diff --git a/lgsm/modules/check_players_online.sh b/lgsm/modules/check_players_online.sh index a3dd18680..b38de1f70 100755 --- a/lgsm/modules/check_players_online.sh +++ b/lgsm/modules/check_players_online.sh @@ -12,14 +12,23 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" playersonline="" if [ "${stoponlyifnoplayers}" == "on" ]; then if [ "${querymode}" == "2" ] || [ "${querymode}" == "3" ]; then + querysucceeded="0" for queryip in "${queryips[@]}"; do query_gamedig.sh if [ "${querystatus}" == "0" ]; then + querysucceeded="1" if [ -n "${gdplayers}" ] && [ "${gdplayers}" -ne 0 ]; then playersonline="${gdplayers}" break fi fi done + # The query failed for every configured IP, so the player count could not be + # determined. Fail open (proceed as if empty) rather than block the server + # indefinitely, but warn clearly since the safety check did not actually run. + if [ "${querysucceeded}" == "0" ]; then + fn_print_warn_nl "Unable to determine player count: stoponlyifnoplayers check skipped" + fn_script_log_warn "Unable to determine player count via gamedig: stoponlyifnoplayers check skipped" + fi fi fi diff --git a/lgsm/modules/command_restart.sh b/lgsm/modules/command_restart.sh index 209064310..245c0d52d 100755 --- a/lgsm/modules/command_restart.sh +++ b/lgsm/modules/command_restart.sh @@ -20,6 +20,9 @@ if [ -n "${playersonline}" ]; then date '+%s' > "${lockdir:?}/${selfname}-restart-request.lock" core_exit.sh fi +# Clear any pending restart request now that the restart is actually proceeding, +# so a stale lock doesn't trigger a repeat restart on the next monitor run. +rm -f "${lockdir:?}/${selfname}-restart-request.lock" exitbypass=1 command_stop.sh command_start.sh