Skip to content

Commit ec0efe7

Browse files
committed
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.
1 parent 84cde95 commit ec0efe7

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎lgsm/modules/check_players_online.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1212
playersonline=""
1313
if [ "${stoponlyifnoplayers}" == "on" ]; then
1414
if [ "${querymode}" == "2" ] || [ "${querymode}" == "3" ]; then
15+
querysucceeded="0"
1516
for queryip in "${queryips[@]}"; do
1617
query_gamedig.sh
1718
if [ "${querystatus}" == "0" ]; then
19+
querysucceeded="1"
1820
if [ -n "${gdplayers}" ] && [ "${gdplayers}" -ne 0 ]; then
1921
playersonline="${gdplayers}"
2022
break
2123
fi
2224
fi
2325
done
26+
# The query failed for every configured IP, so the player count could not be
27+
# determined. Fail open (proceed as if empty) rather than block the server
28+
# indefinitely, but warn clearly since the safety check did not actually run.
29+
if [ "${querysucceeded}" == "0" ]; then
30+
fn_print_warn_nl "Unable to determine player count: stoponlyifnoplayers check skipped"
31+
fn_script_log_warn "Unable to determine player count via gamedig: stoponlyifnoplayers check skipped"
32+
fi
2433
fi
2534
fi

‎lgsm/modules/command_restart.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ if [ -n "${playersonline}" ]; then
2020
date '+%s' > "${lockdir:?}/${selfname}-restart-request.lock"
2121
core_exit.sh
2222
fi
23+
# Clear any pending restart request now that the restart is actually proceeding,
24+
# so a stale lock doesn't trigger a repeat restart on the next monitor run.
25+
rm -f "${lockdir:?}/${selfname}-restart-request.lock"
2326
exitbypass=1
2427
command_stop.sh
2528
command_start.sh

0 commit comments

Comments
 (0)