Weeks [15thMEU(SOC)]

Restart Script

28 posts in this topic

It's come up a lot as I've discussed my server with others. I'm using MarkMods.com as my host, and they have a server control panel that is pretty nice, but it didn't have any way for me to automate restarting the server without using battleye, which I detest. So, I wrote a simple little script. One quirk here is that I use Defent's Mission System on my server, so I'm co-opting his mission announcement function to pop up warnings about the server restart.

/*=================================================================================================================
  Timed Restart Script
  
  by Weeks
 [15thMEU(SOC)]
=================================================================================================================*/

ServerDuration = (3 * 60 * 60);
DebugServerDuration = (20 * 60);



private ["_timeStart","_timeSinceStart","_shutdownSuccess","_isDebug","_msg30mins","_msg15mins","_msg5mins","_timeUntilRestart","_30minspassed","_15minspassed","_5minspassed","_60secondspassed"];

_isDebug = false;

if(_isDebug) then
{
	ServerDuration = DebugServerDuration;
};

_msg30mins = "<t color='#FFFF00' size='1.25'>Server Restart</t><br/> The server will shut down in less than 30 minutes.";
_msg15mins = "<t color='#FF9D47' size='1.25'>Server Restart</t><br/> The server will shut down in less than 15 minutes.";
_msg5mins = "<t color='#FF5500' size='1.25'>Server Restart</t><br/> The server will shut down in less than 5 minutes.";
_msg1mins = "<t color='#FF0000' size='1.25'>Server Restart</t><br/> The server will shut down in less than 60 seconds! LOG OUT NOW!";

_30minspassed = false;
_15minspassed = false;
_5minspassed = false;
_60secondspassed = false;

_timeStart = diag_tickTime;

while{true} do
{
	_timeSinceStart = diag_tickTime - _timeStart;
	_timeUntilRestart = ServerDuration - _timeSinceStart;
	
	if(_isDebug) then
	{
		diag_log format ["Time Since Start: %1, Time Until Restart: %2", _timeSinceStart, _timeUntilRestart];
	};
	
	switch true do
	{
		case ((_timeUntilRestart < (1 * 60)) && !_60secondspassed) : 
		{
			_msg1mins call DMS_fnc_BroadcastMissionStatus; // using Defent's mission broadcast format for our messages
			diag_log "60 seconds until server restart.";
			_60secondspassed = true;
			_5minspassed = true;
			_15minspassed = true;
			_30minspassed = true;
		};
		case ((_timeUntilRestart < (5 * 60)) && !_5minspassed) : 
		{
			_msg5mins call DMS_fnc_BroadcastMissionStatus;
			diag_log "5 minutes until server restart.";
			_5minspassed = true;
			_15minspassed = true;
			_30minspassed = true;
		};
		case ((_timeUntilRestart < (15 * 60)) && !_15minspassed) : 
		{
			_msg15mins call DMS_fnc_BroadcastMissionStatus;
			diag_log "15 minutes until server restart.";
			_15minspassed = true;
			_30minspassed = true;
		};
		case ((_timeUntilRestart < (30 * 60)) && !_30minspassed) : 
		{
			_msg30mins call DMS_fnc_BroadcastMissionStatus;
			diag_log "30 minutes until server restart.";
			_30minspassed = true;
		};
	};
	
	if(_timeSinceStart > ServerDuration) then
	{
		diag_log "Restart timeout elapsed, attempting server shutdown.";
		_shutdownSuccess = "[server rcon password]" serverCommand "#shutdown";
		if(_shutdownSuccess) then
		{
			diag_log "Shutting down server!";
		}
		else
		{
			diag_log "Shutdown failed!";
		};
		
	};
	
	sleep 15;
};

Now, MarkMods' control panel monitors the server executable, and if it crashes or shuts down without the shutdown having been initiated by the control panel, it will restart the server automatically. If your host doesn't have that functionality, or you're self-hosting, feel free to co-opt this batch file I use for my local dev machine:

@echo off
cls
echo Starting Exile Auto-Restart Scripts
title Exile Auto-Restarter
:arma
echo (%time%) Exile Started
start /wait arma3server.exe -server "-config=S:\Steam\steamapps\common\Arma 3\MarkMods.cfg" "-cfg=S:\Steam\steamapps\common\Arma 3\MarkMods_basic.cfg" -nosound -nosplash -ip=127.0.0.1 -port=8302 "-profiles=S:\Steam\steamapps\common\Arma 3\Profiles" "-BEpath=S:\Steam\steamapps\common\Arma 3\BattlEye" -name=default -servermod=@ExileServer -mod=@Exile; -autoinit
echo (%time%) Exile crashed or closed, restarting.
goto arma

Obviously substituting your server start parameters in there for mine.

 

Share this post


Link to post
Share on other sites

This is real good. Been waiting for this as i can not for the life of god figure BEC. Thank you very much i will try this out.

Share this post


Link to post
Share on other sites
Advertisement

Has anyone successfully implemented this script?  If so could you please walk me through the steps to implement as BEC is not working with my hosting company and the exile_server_config/config.cpp handles the announcements but not the restart :(

Is it possible to have the exile_server_config/config.cpp to call an RCon #shutdown? that would be very convenient. Lastly, is there a way to alter the exile_server_config/config.cpp announcment message?

 

Thank you

Share this post


Link to post
Share on other sites

Put the first script in its own .sqf file in the base directory of the mission. "timed_restart.sqf" works.

In init.sqf add or merge in the following lines:

if (isServer) then {
    ExecVM "timed_restart.sqf";
};

The second bit above is a batch file for monitoring and restarting the server executable should it shut down. If your hosting company allows you to use custom batch files, great. If not, work something else out with them.

Share this post


Link to post
Share on other sites

Ok stupid question since I'm 100 new to this. I don't have a custom init.sqf file so how would i get it to read the file once i add it to my root mission folder.

its not a stupid question if your totally new to this.
 

you just have to make a NEW file called init.sqf and place the content in there. 
PS: Make sure the file changes from txt file to sqf file.

 

have fun..

Share this post


Link to post
Share on other sites

i having a problem with DMS_Fn_ broadcastmissionStatus.

the new DMS files are released but now i have this Arror in my rpt files "params" <> #3: Input value is 'nil' or undefined. Default value false is used instead.

and the Timed Restart.sqf is not working. if i download the old version of DMS then  its working again...

how do i fix it ?

 

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.