Omen

My Arma Exile Auto Restart / Process Checker

21 posts in this topic

I couldn't get the built in auto restart to work nor any of the other user provided scripts so I pieced together one that works for me. It may or may not work for you but I figured I would share since this is a modding community.  You can probably clean up the code since I am far from a programmer.

With this batch file you can -

  • Set the restart time down to the second
  • It tells you when your server started and when it is going to restart automatically
  • It tells you if/when your server crashed and restarts it for you
  • Time stamps everything so you know when everything happened
  • No need for BEC or anything else third party, just PowerShell and my server came with it
  • Checks on your server every 3 seconds and restarts when needed
  • Timer restarts if your server crashes

This screenshot shows it running at 1 minute intervals to test and display the status messages. I killed the process manually to test the process checker and restart. Then I let it run for the 1 minute and you can see it notifies you that it is time for a restart and does so without user interaction.

 

yafOvGo.png

 

Usage -

Set your restart timer (below is for 4 hour restarts)

set hours="4"
set minutes="0"
set seconds="0"

 

 

Set your launch parameters and folder paths

REM // Launch parameters
start "Exile" /high "arma3server.exe" -port=2302 "-config=@ExileServer\config.cfg" "-cfg=@ExileServer\basic.cfg" "-profiles=config_exile" -name=Exile "-servermod=@ExileServer;" "-mod=@Exile;" -malloc=tbbmalloc -autoinit -enableHT

 

 

Run the batch file. Place the batch file in the same folder as arma3server.exe

 

The Batch File (save as auto_restart.bat or anothername.bat)

@echo off
cls

set gameserver=Arma Exile

title %gameserver% Auto Restart / Process Checker

:start


REM How long until auto restart?
set hours="4"
set minutes="0"
set seconds="0"

REM // Launch parameters
start "Exile" /high "arma3server.exe" -port=2302 "-config=@ExileServer\config.cfg" "-cfg=@ExileServer\basic.cfg" "-profiles=config_exile" -name=Exile "-servermod=@ExileServer;" "-mod=@Exile;" -malloc=tbbmalloc -autoinit -enableHT


REM //////// You do not need to update anything else below this line ////////


REM Pull, display and create some time functions
for /f "delims=" %%G IN ('powershell "(get-date %time%).AddHours(%hours%).AddMinutes(%minutes%).AddSeconds(%seconds%).ToString('yyyyMMddHHmmss')"') do set endtime=%%G
for /f "delims=" %%G IN ('powershell "(get-date %time%).ToString('HH:mm:ss')"') do set nowtimeclean=%%G
for /f "delims=" %%G IN ('powershell "(get-date %time%).AddHours(%hours%).AddMinutes(%minutes%).AddSeconds(%seconds%).ToString('HH:mm:ss')"') do set endtimeclean=%%G

echo %time% - %gameserver% Server started at %nowtimeclean% and will restart at %endtimeclean%

:checkarma

for /f "delims=" %%G IN ('powershell "(get-date %time%).ToString('yyyyMMddHHmmss')"') do set nowtime=%%G

REM ////////// TIMER CHECK ///////////
if "%nowtime%" gtr "%endtime%" (
echo %time% - It is time to restart %gameserver%!
echo.
echo.
goto restartarma
)
REM ////////// END TIMER CHECK ///////////

REM ////////// PROCESS CHECK ///////////
tasklist /FI "IMAGENAME eq arma3server.exe" 2>NUL | find /I /N "arma3server.exe">NUL
if "%ERRORLEVEL%"=="1" (
echo %time% - The process is not running, restart %gameserver%!
echo.
echo.
goto restartarma
)
REM ////////// END PROCESS CHECK ///////////


REM restart not needed. Check again in 3 seconds.
TIMEOUT /T 3 /NOBREAK >NUL
goto checkarma


:restartarma
REM Either the server crashed or it is time for a restart. Kill the process and go to start.
START taskkill /f /im arma3server.exe 2>nul
TIMEOUT /T 3 /NOBREAK >NUL
goto start

 

 

If you can improve on this then by all means please do and post your fixes / updates / optimizations.

Enjoy!

Edited by Omen
  • Like 2

Share this post


Link to post
Share on other sites

Your script is working well for me.

But it would be nice if you can set a specific time for the restart. Like 6am and then every 6h so it restarts at 0,6,12,18

Share this post


Link to post
Share on other sites
Advertisement

Nice work.

21 hours ago, Fendo said:

Your script is working well for me.

But it would be nice if you can set a specific time for the restart. Like 6am and then every 6h so it restarts at 0,6,12,18

You can do that through windows task scheduler :)

  • Like 1

Share this post


Link to post
Share on other sites
On ‎11‎/‎12‎/‎2015 at 1:25 PM, Omen said:

I couldn't get the built in auto restart to work nor any of the other user provided scripts so I pieced together one that works for me. It may or may not work for you but I figured I would share since this is a modding community.  You can probably clean up the code since I am far from a programmer.

With this batch file you can -

  • Set the restart time down to the second
  • It tells you when your server started and when it is going to restart automatically
  • It tells you if/when your server crashed and restarts it for you
  • Time stamps everything so you know when everything happened
  • No need for BEC or anything else third party, just PowerShell and my server came with it
  • Checks on your server every 3 seconds and restarts when needed
  • Timer restarts if your server crashes

This screenshot shows it running at 1 minute intervals to test and display the status messages. I killed the process manually to test the process checker and restart. Then I let it run for the 1 minute and you can see it notifies you that it is time for a restart and does so without user interaction.

 

yafOvGo.png

 

Installation -

Set your restart timer (below is for 4 hour restarts)

Hidden Content

 

Set your launch parameters and folder paths

Hidden Content

Run the batch file.

 

The Batch File (save as auto_restart.bat or anothername.bat)

Hidden Content

 

If you can improve on this then by all means please do and post your fixes / updates / optimizations.

Enjoy!

Finally people are using PowerShell for Windows tasks!

Good work man. Ill get-someCoffee | Add-ThisToServer | Set-Areply

Soon!

 

  • Like 1

Share this post


Link to post
Share on other sites

The main script has been updated. The date formatting was off and it didn't like it when the start time was 2015 and restart was 2016. It kept thinking it was time to restart the server.

 

I have fixed the date formatting so now you should be good to go.

Share this post


Link to post
Share on other sites

NICE BIG THX !!!!
 

BUT NO TIME IN MY CONSOLE FOR SERVER RESTART and and and ...... its a space in the line 

 

echo %time% - %gameserver% Server started at %nowtimeclean% and will restart at %endtimeclean%

 

:/

Edited by Hatler

Share this post


Link to post
Share on other sites

You might want to add a check for "Not responding" as well, I have that with mine, my server haven't been hanging ever since I made that check, it simply just kills the hanging process and restart the server B|

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.