Donation Goal
Donate Now Goal amount for this year: 799 USD, Received: 100 USD (13%)
Please donate to help support this website. The funds will be used to purchase owned license of LiteSpeed Web Server Enterprise (2-CPU). It provides superior performance in terms of raw speed, scalability and anti-DDoS capabilities.

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

Posted By Raymond In Category: Computer

Oct
23
2009

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 the 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, restarting.
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.
Restart on Crash

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.
run program when crash
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 ]


Related posts:
  • Disable Program Has Stopped Working Error Dialog in Windows Server 2008
  • Keep Application Running by Automatically ReRun When Closed
  • Stop Virus from Running Automatically When you Execute Files
  • Prevent, Cancel and Abort a Windows System Shutdown or Restart when Application is Running
  • Minimize Running Application to Desktop as Thumbnail
    • Shail Shah

      Very Useful!

    • nerd

      I have a problem using this tool.

      I choose an application on “MONITOR THIS APPLICATION”..for example opera.exe

      after i wish if Opera isn’t running to run Firefox by a run.bat

      the problem is that when i choose the run.bat the same run.bat appears in the box MONITOR THIS APPLICATION

      i don’t understand

    • nerd

      I find the solution

      I have to modify manually the box in witch I run run.bat

      ALL is ok now

      It’s great

    • webcadre

      it will be usefull for when i set up a counter strike in my home :D do you think its possible fro me to set up at home via wireless connection?

    • Evan

      Raymond, I really like the use of CleanMem that you’ve implemented. I’m going to give Shane a call and tell him about it.

      Just out of curiousity are you running CleanMem with the “Clear File Cache” option enabled or disabled? If you’ve tried it both ways for this server have you noticed any positive or negative impact either way?

      Oh yeah, welcome back from the honeymoon and congrats!

      -Evan
      http://www.PcWinTech.com – Home of CleanMem

    • http://www.kalvster.com Kalvster

      I’ll keep this in mind. Hopefully I can use it when I host a CS Server. :)

    • ayham

      mon application RYNGA écrasé
      je dois faire quoi?

    Copyright © 2005-2012 - Raymond.CC Blog