Repository navigation
feat(stop): warn players in-game before stop, restart and update, and retry postponed updates - #5025
Merged
Merged
Conversation
… retry postponed updates
…keep module modes
11 of 14 tasks
…date's lockfile, retry forced updates as forced
This was referenced Oct 14, 2026
Merged
Merged
This was
linked to
issues
Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Warns players in-game before LinuxGSM stops, restarts or updates a server, and makes updates that were postponed because players were online run automatically once the server is empty. Part of #674 (the console tier; telnet and RCON are not included).
Player warnings
15warns at 15, 10, 5, 3, 1;10at 10, 5, 3, 1;7at 7, 5, 3, 1.Server stopping|restarting|updating in N minute(s), sent with the game's own chat command. The command for each game is set infn_stop_warn_players_command(command_stop.sh), not in the config, as it is game data rather than a setting.stop,restart,backup(withstoponbackup, "restarting"),updateandworkshop-updatewhen they stop a running server. Never formonitorcrash restarts,force-updateorvalidate.querymodeis not 2/3), it warns anyway.consoleinteract="yes"and a known chat command (78 servers). Others printWarning players: not supported by <game>: skipped.Server <action> cancelled.<selfname>-warning.lockholding the PID. A lock left by a dead process is removed.%s= message)say %sservermsg "%s"c_announce("%s")/bc 10 %s/announce %salert %s%sWhen players can't be counted
Counting players needs gamedig (optional, installed only when Node.js 16+ is present) and
querymode2 or 3.query_gsquery.pyonly reports whether the server responds, so it can't count players.check_players_online.shnow records why the count is unavailable (gamedig is not installed,jq is not installed,querymode N cannot count players, orquery failed):Warning players: unable to check for players (gamedig is not installed): warning anyway.stoponlyifnoplayers: the stop goes ahead as before, but now always says why:Unable to determine player count (querymode 4 cannot count players): stoponlyifnoplayers check skipped. Previouslyquerymode1, 4 and 5 skipped the check silently.Postponed updates
With
stoponlyifnoplayers="on", anupdatethat finds an update while players are online is now postponed: it writes<selfname>-update-request.lock, andmonitorruns the update once the server is empty (like the existing restart request). If players are still online, monitor logsupdate postponedand carries on monitoring.setsid) and returns straight away. In the Docker imagesmonitoris the healthcheck (every 60s, 60s timeout), so running the update inside monitor would have been killed part way through. The background update shows asupdatein the process list, so other monitor runs see it in progress.force-updateis remembered (forcein the request) and retried withforceupdate=1, so it isn't turned into a plain update that finds nothing to do.Bugs fixed along the way
stoponlyifnoplayersdid not work forupdate,backuporworkshop-update, and left the server down. These commands callcommand_stop.shwithexitbypass=1, so thecore_exit.shinfn_stop_players_onlinereturned instead of exiting. The stop carried on, thencommand_stop.sh's owncore_exit.shended the whole command: the server was stopped and not updated until monitor restarted it. Now a prevented stop exits the whole command (server keeps running). Note this changesbackupwithstoponbackup="on": while players are online it is now skipped instead of stopping the server.<selfname>-stopping.lockbehind, because the player check ran after the lock was created. The check now runs before it.last-updated.locksaying "updated but not restarted", so the retried update restarted the server instead of updating. It is now removed when the update is postponed.restartrunningstop,updaterunningstop):core_trap.shcalledcore_exit.shwithexitbypassstill set, so it returned and the command carried on. During a restart countdown this told players "cancelled" and then restarted anyway. The trap now clearsexitbypass.backup.lockmakes the nextbackupwithin 60 minutes refuse to run ("Backup is currently running"), andlast-updated.lockmakes the next command restart the server. When a stop is prevented by players, or a countdown is cancelled, the calling command'sbackup.lock,update.lockandlast-updated.lockare now removed (fn_stop_cancel_locks).command_backup.sh's own CTRL+c trap also tells players the countdown was cancelled.update.lockolder than 15 minutes without checking whether the update is still running. The non-SteamCMD updaters (Minecraft, Factorio, MTA and others) writeupdate.lockbefore stopping the server, so a warning countdown plus download could pass 15 minutes, after which monitor removed the lock, found the server stopped and started it mid-update. A staleupdate.lockis now only removed when noupdate,force-update,validateorworkshop-updateis running.validatestopped by players leftupdate.lockbehind; it is now removed with the other locks._default.cfgfiles had no## Stopblock (stoponlyifnoplayers): ac hyt jbep3 mcv pvr rsdw rwr sm tf2c xnt. Added.Testing
Scenarios
Tested on a Minecraft server built from this branch. A gamedig stub controlled the player count (a number, or a failed query), and the chat lines were checked in Minecraft's own log (
[Server] Server restarting in 3 minutes).warnplayerstimer="0"warnplayerstimer="abc"(also-5,1.5," 5"in the step test)must be a number of minutes: skipped, immediate stopconsoleinteract="no"not supported by Minecraft: skippedno players on the server, immediate stopServer stopping in 1 minute, stopped after 64srestarting in 3 minutes,1 minute, restarted after 188squerymode="1"stoponlyifnoplayers="on", playersstop prevented, no warnings, no leftover stopping lockstoponlyifnoplayers="on"Update postponed until the server is empty, server keeps running, not updated, request lock written,last-updated.lockremovedupdate postponed, request kept, monitoring continuesstoponlyifnoplayers="off", timer 1Server updating in 1 minute, then updatedNo update available, request removedstoponlyifnoplayersallcommands="off"forceupdate=1(as set byforce-update)stoponbackup="on", playersServer restarting in 1 minute, then backupstoponlyifnoplayers="on"stop prevented, backup skipped, server keeps running,backup.lockremovedstoponlyifnoplayers="on"Server stopping cancelledsent, locks removed, server keeps runningServer restarting cancelled, the restart is really cancelled (before the trap fix it restarted anyway), server keeps runningServer updating cancelled, not updated,update.lockandlast-updated.lockremovedServer restarting cancelled, backup cancelled,backup.lockremoved, server keeps runningstopalready stoppedFinal regression
After the last fixes, the main scenarios above were run again in one pass (55 in total, all passing), plus:
monitorkilled after 15s (as a Docker healthcheck timeout would)force-updatepostponed by players, then monitor with the server emptyforce; the background update ran forced (26.3 > 26.3, re-downloaded), server restartedupdate.lockaged to 20 minutes, monitorLinuxGSM is updating the game server, lock kept, update completedvalidateprevented by playersupdate.lockremoved,last-updated.lockkeptWithout a player count
warnplayerstimer="1", server emptyunable to check for players (gamedig is not installed): warning anyway, full countdownstoponlyifnoplayers="on"Unable to determine player count (gamedig is not installed): stoponlyifnoplayers check skipped, server stoppedquerymode="4",warnplayerstimer="1"unable to check for players (querymode 4 cannot count players): warning anywayquerymode4 and 1,stoponlyifnoplayers="on"(query failed)shown, players prevent the stopChat command delivery
Each chat command was sent to running test servers, exactly as the code sends it (
tmux send-keys -lthen ENTER):say), qw wf xnt, fctr ([CHAT] <server>:), bt (HOST:), wmc ([Alert]), scpsl (BC#Global broadcast sent.), mc (test container)sayonly reaches connected clients), mcb, unt, dstechomarker testTwo things found and fixed during delivery testing:
C-ubroke the]-prompt consoles (cod cod4 rtcw etl jk2 silently dropped the command), so nothing is sent before the message./bc, notbc(Command bc does not exist!).Known limitations
last-updated.lockis shared by instances in the same directory, so removing it on a postponed update could also clear another instance's pending "restart after update" (rare).workshop-update(same code path asupdate), and real gamedig player counts (the existingquery_gamedig.shparsing is unchanged).Type of change
Checklist
developbranch as its base.Documentation