Technology Information: Execute any File When Application Crashed or Stopped Running (Useful for SRCDS)

Execute any File When Application Crashed or Stopped Running (Useful for SRCDS)

I have been managing a Counter-Strike: Source server for nearly a year and believe me, it is a very sensitive and buggy server to maintain. Buggy in the sense that it crashes nearly everyday especially when you are running intensive mods such as ZombieMod or Garry’s Mod. Moreover there are hundreds of third party plugins for SourceMod and EventScripts which makes it even more unstable because of incompatibility problems. It is not easy and time consuming to debug and find out what is causing the crash. So it is important to be able to auto restart the server when the srcds crashes.

If you are running a CSS server on linux, the server itself already supports auto restarting srcds when crash. However on Windows, you can do it via a batch file. It works but it has its problems in doing that which I’ll explain further.

This is the batch file that you need to run to keep srcds.exe open by automatically running when crashed or closed.

@echo off
cls
echo Protecting srcds from crashes...
echo If you want to close srcds and this script, close t
he srcds window and type Y depending on your language followed by Enter.
title srcds.com Watchdog
:srcds

echo (%time%) srcds started.
start /wait srcds.exe -console -game cstrike +map de_dust +
maxplayers 16
echo (%time%) WARNING: srcds closed or crashed, res
tarting.
goto srcds


The command above will monitor for srcds.exe and immediately auto runs the command line if it’s not running. Well Valve recommends that we should wait for at least 10 seconds before restarting so that there is enough time for the memory to clear up. I’ve used this batch and noticed that there were a few times the server crashes, restart, crashes again and restart. Previously I’ve written an article that contains a couple of free tools that can auto rerun program when closed but this time I needed something different.

I was looking for a free, small, simple and portable tool that can monitor for a specific process and then run a “different” file when it detects a crash. I found Restart on Crash which has been working perfectly ever since I started using it. Restart on Crash is an monitoring tool that will watch the applications that you specify and automatically relaunch any program that hangs or crashes. You can add any number of applications to monitor, enable/disable them individually and edit the command line that will be used to restart an application. Restart on Crash doesn’t require installation and stores all it’s configuration data in a “settings.ini” file in the program’s folder, so it’s portable. It should be compatible with most NT-based Windows versions.

Basically the below image is the settings for the srcds server. It monitors srcds.exe and when it isn’t running, a run.bat file will be executed.

The more interesting part is the run.bat which is executed when the program detected that srcds.exe is not running. Since it is a batch file, I can program it to run multiple commands.

The first command shows that I ping localhost 3 times. This command is being used as a feature to wait for 3 seconds before going to the second command. The second command from the batch file is to execute CleanMem which is a tool to clean process and file cache to recover even more memory and performance. Then again pause for 10 seconds before running srcds.exe with the full command line. This method has been working perfectly for weeks already and I didn’t need any other more advanced crash recovery software such as Firedaemon that cost money.

[ Download Restart on Crash ]

0 comments:

Enter your mail address:
Template by - ADMIN | HiTechvnn Template