SmartlyDressedGames / Unturned-Docs

Documentation for Unturned's modding features.
135 stars 49 forks source link

Server Auto Restart features #307

Closed MoltonMontro closed 1 month ago

MoltonMontro commented 5 months ago

Making a note that the "Server Auto Restart" features added in the 3.22.12.0 Update should eventually be added to the documentation site. (Currently just available in the patchnotes.) I don't believe there's been any changes to these features, so the docs may just be verbatim.

Server Auto Restart:

Two features have been added to the server Config.json file in this update to make server maintenance without plugins easier:

Scheduled Maintenance:

Restarting approximately once per 24 hours is recommended for the meantime because most of the older code still uses 32-bit floating point time. While this is gradually being improved an option to schedule shutdown has been added.

Enable_Scheduled_Shutdown: if true the server will shutdown at the specified time.

Scheduled_Shutdown_Time: local time the server will shutdown.

Scheduled_Shutdown_Warnings: list of times before the shutdown to notify players. For example 30:00 will broadcast in chat 30 minutes before the shutdown.

Checking for Updates:

Finally! The server can monitor for updates and restart when one is detected.

Enable_Update_Shutdown: if true the server will monitor for updates.

Update_Steam_Beta_Name: defaults to "public", but can be set to "preview" for servers running on the preview branch.

Update_Shutdown_Warnings: after an update is detected the server will wait for the longest of these durations to notify players before shutdown. For example if the longest time is 2:30 the server will broadcast in chat 2 minutes and 30 seconds before the shutdown.

Practical Application:

These options are most useful in conjunction with a script that updates and restarts the server in a loop. For example this Windows .bat script can be placed in the steamcmd folder to infinitely update and restart the server:

@echo off
rem @ suppresses echo command from being echoed, and then disables echoing in this script.

rem This is a label for use with "goto". The script will return to this label to update and restart the server.
:loop

rem %~dp0 expands to the path to this script's directory, allowing it to be called from a different working directory.
rem The "/wait" option pauses our script until steamcmd is finished.
rem Start steamcmd, download latest version of Unturned Dedicated Server, then close cleanly.
echo Updating...
start "" /wait "%~dp0steamcmd.exe" +login anonymous +app_update 1110390 +quit

echo Finished update! Launching server...
start "" /wait "%~dp0steamapps\common\U3DS\Unturned.exe" -batchmode -nographics +InternetServer/MyServer

echo Server has exited. Restarting after timeout...
echo:
echo Press CTRL+C and then Y during this timeout to cancel restart.
timeout 10

rem Return to the "loop" label to update and restart the server.
goto loop