Restarts the server (or changes the map) when all players leave the game / or optionally, by the scheduled hours.
Features:
- 3 methods of server restart: using "crash", using "_restart", or just change the map.
- Grace period - plugin waits some time for a new player to connect before actually decide to restart.
- unloads the "Accelerator" extension to prevent false crash reports.
- correctly free resources by unloading all plugins before actual restarting
- Able to remove the false crash log in the "CRASH" folder - some servers create it
- Control sv_hibernate_when_empty ConVar. Some admins (hosters) setup it, so many similar plugins cannot perform a restart due to plugin freeze.
- (optionally) start-end hours where restart allowed
- (optionally) start-end hours to force restart (with kicking the players)
- (optionally) restrict the frequency of restarting
- the restart time is logged to file: addons/sourcemod/logs/restart.log
Recommended for:
- prophylaxis
- fixing the bug related to resetting all ConVars to defaults (seen on some servers). The source of the problem is unknown.
Requirements:
- Regexp extension (included in SourceMod).
Settings (ConVars):
see: cfg/sourcemod/sm_restart_empty.cfg:
- sm_restart_empty_enable - def.: 1 - Enable plugin (1 - On / 0 - Off)
- sm_restart_empty_method - def.: 2 - When server is empty, what to do? 1 - _restart, 2 - crash (use if method # 1 is not work), 3 - just change map
- sm_restart_empty_delay - def.: 1.0 - Grace period (in sec.) waiting for new player to join until actually decide to restart the server
- sm_restart_empty_unload_ext_num - def.: 0 - If you have Accelerator extension, you need specify here order number of this extension in the list: sm exts list
- sm_restart_empty_min_period - def.: 0 - Minimum period (in hours) this plugin should wait before the next restarting is allowed (0 - disable, 24 - allow once per day)
- sm_restart_empty_limit_hour_start - def.: 0 - Allow rebooting to be started from this hour only (paired with "*_end" ConVar)
- sm_restart_empty_limit_hour_end - def.: 24 - Allow rebooting until this hour only (paired with "*_start" ConVar)
- sm_restart_empty_force_hour_start - def.: -1 - Start hour for force rebooting (if last reboot happened > 24 hours ago) and somebody leaves during this hour (paired with "*_end" ConVar) (-1 to disable)
- sm_restart_empty_force_hour_end - def.: -1 - End hour for force rebooting (if last reboot happened > 24 hours ago) and somebody leaves during this hour (paired with "*_start" ConVar) (-1 to disable)
- sm_restart_empty_utc_delta - def.: 0.0 - If your server has incorrect time, you can set UTC correction hours here (they will be appended to a server time)
- sm_restart_empty_server_start_changemap - def.: 0 - When server restarted, change map to the random one from the file: data/restart_empty_maps.txt (1 - Yes / 0 - No)
Commands: (both intended for plugin setup stage)
sm_restarter_ctime - Check the server time taking into account UTC delta ConVar
sm_restarter_accelerator - Show auto-detected order number of Accelerator extension
Installation
1. Unpack the archive and place its contents to addons/sourcemod
2. If you plan to use map change features, edit file "addons/sourcemod/data/restart_empty_maps.txt" inserting your own map list (one per line) you want to randomly change map to.
3. Change the map.
4. See Suggestions on Setup section
5.
If you have "Accelerator" extension, do this:
Execute command:
Code:
sm_restarter_accelerator
It must show extension number (or not).
Compare this number with the number from the next step.
Run in server console such command:
Code:
sm exts list
You'll see something like this:
Code:
sm exts list
[SM] Displaying 14 extensions:
[01] [L4D2] 8+ Players BugFixes (1.0.6): This extension try fix some bugs on server have more than 8 players
[02] Accelerator (2.5.0): SRCDS Crash Handler
As you see, Accelerator is under number "02".
Compare this number with the one displayed when you entered command sm_restarter_accelerator.
- If it is match, you don't need to do anything. Stop here.
- If not match:
you need to set ConVar "sm_restart_empty_unload_ext_num" to "2" in cfg/sourcemod/sm_restart_empty.cfg file (replace "2" to your own order number).
Suggestions on Setup
Spoiler
- If you want your server will restart not often than 12 hours (when all players leave the game), set sm_restart_empty_min_period to "12"
- If you want to restrict the hours of the day where restart is allowed, set the pair of ConVars:
That is mean, if the last server restart has happened >= 24 hours ago,
and if the current server time is somewhere between 4-5 o'clock,
the server will restart even if there are still human players.
They will receive a kick with message "Server Restarts". Note: the restart is only happening if somebody will leave the game during these hours,
because the plugin catches exactly that event and doesn't use timers.
- Ensure: your server has a correct time by executing "sm_restarter_ctime" command.
If no, you have 2 options:
* fix the time in the server, e.g. for Linux, you can check timezone using command "timedatectl"
and change timezone using command "timedatectl set-timezone TIME-ZONE"
* use ConVar "sm_restart_empty_utc_delta" to append some hours to the actual server time,
then execute "sm_restarter_ctime" again to verify it.
Credits:
- @Luckylock - for alternative way of reboot, "crash" command.
- @Forgetest - for coding auto-detection of Accelerator extension order number.
2.9 (04-Feb-2025)
- Fixed the issue causing timer might incorrect counting grace time due to not resetting the old one.
- Fixed potential ability to restart server during map change.
2.7 (06-Jan-2025)
- Added debugging code, set #define DEBUG 1
2.6 (07-Jan-2023)
- Added auto-detection of Accelerator extension number (thanks to @Forgetest for coding).
- Command "sm_time renamed to" "sm_restarter_ctime" to prevent possible collisions.
- Added command "sm_restarter_accelerator" - Show auto-detected order number of Accelerator extension.
- Readme updated.
- Compatibilities with SM 1.13.
2.5 (14-Feb-2022)
- Fixed: non-functional version was uploaded last time.
2.4 (06-Feb-2022)
- Critical bug: fixed case, when under some circumstances* the plugin unloads himself causing server malfunction.
* Plugin iterator returned null handle for current plugin. The cause of behavior is unknown and under investigation still.
- Fixed compilation warnings on SM 1.11.
2.3 (23-Mar-2021)
- Attempt to fix hibernation ConVar for "No more room in hell".
2.2 (07-Dec-2020)
- Fix for sm_restart_empty_method "3" - all plugins are been unloaded even if method "3" is used (thanks to @zombieland0302 for reporting).
- IsMapValid() is replaced by FindMap() to prevent undefined behaviour.
2.1 (28-Nov-2020)
- Fixed mistake in a loop, causing server could restart when the last player had an index == 32.
Installation:
- ensure you have correct server timezone and synchronized time:
* e.g. for Linux, you can check timezone using command "timedatectl" and change timezone using command "timedatectl set-timezone TIME-ZONE"
* or you can set UTC delta correction using ConVar "sm_restart_empty_utc_delta".
2.0 (27-Nov-2020)
Included requests by @Ejziponken, @PeterPan and @penalte.
- Added "sm_restart_empty_min_period" ConVar - Minimum period (in hours) this plugin should wait before the next restarting is allowed (0 - disable, 24 - allow once per day)
- Added "sm_restart_empty_limit_hour_start" ConVar - Allow rebooting to be started from this hour only (paired with "*_end" ConVar)
- Added "sm_restart_empty_limit_hour_end" ConVar - Allow rebooting until this hour only (paired with "*_start" ConVar)
- Added "sm_restart_empty_force_hour_start" ConVar - Start hour for force rebooting (if last reboot happened > 24 hours ago) and somebody leaves during this hour (paired with "*_end" ConVar) (-1 to disable)
- Added "sm_restart_empty_force_hour_end" ConVar - End hour for force rebooting (if last reboot happened > 24 hours ago) and somebody leaves during this hour (paired with "*_start" ConVar) (-1 to disable)
- Added "sm_restart_empty_server_start_changemap" ConVar - When server restarted, change map to the random one from the file: data/restart_empty_maps.txt (1 - Yes / 0 - No)
- Prefer "sm_map" command to change the map (if available).
- Removed ConVar "sm_restart_empty_default_map"; use file: "data/restart_empty_maps.txt" instead.
- Added "sm_time" command to check server time (taking into account utc delta ConVar).
See updated 1st post and Suggestions on Setup Section.
1.9
- Fixed warnings
1.8
- Default grace time ConVar is decreased down to 1 sec. to prevent misunderstanding of this feature by server administrators.
- Corrected identification of crash log from MyArena.ru server to clear it after server restart.
1.7
- Added ConVar: "sm_restart_empty_unload_ext_num". If you have Accelerator extension,
you need specify here order number of this extension in the list by executing "sm exts list" command, to prevent creating false crash log.
Plugin will automatically unload this extension before restarting the server.
- Log path location is changed to logs/restart.log
- no more auto-create "CRASH" folder (since it was a speficic of myarena.ru hosting only)
- All ConVars are cached.
- Some simplifications.
1.6
- Added all plugins unload before restarting the server (for safe).
1.5
- Added change map method. New ConVar "sm_restart_empty_default_map" - Map name to change to when server become empty
1.4
- Fixed "Client index 0 is invalid" in IsFakeClient() check.
1.3
- Added sv_hibernate_when_empty to force server not hibernate allowing this plugin to make its work
- Added alternative method for restarting ("crash" command) (thanks to Luckylock)
- Added ConVars
- Crash logs remover: parser method is replaced by time based method.
- Create "CRASH" folder
1.2
- Removing crash logs caused by server restart for some reason
1.1
- Added log file
1.0
- Initial release
Donate
Donates are very appreciated and welcomed for further inspiration, make me happy, and make next updates came out more often:
- Patreon (Paypal)
- BitCoin
- Ю.Money
We are using a plugin to restart the server every night. Now this plugin wont just restart the server at set time, it will wait until the server is empty, like this plugin..
The problem is that sometimes a server never actually gets empty, and then the server wont restart and it will start to perform worse over time.
It would be nice if the plugin could keep track if it did restart after the set time, and if not, it could force an restart at a second specified time with some warning in the chat before it goes down. like when its 5 min left and when its 30 seconds left or something.
For example:
DM #3 is set to restart at 5am. But since its a popular server, the players stay on it all night and and it wont actually have a chance to restart again until 5am next morning. So with this new idea, the server would force a restart at maybe 2pm and then again at 5am if the server is empty. :p