Here's a script I hacked together back in 2013 but it should still work.
Install steps:
1. Save the script as mon.sh
2. Adjust the serverport to reflect your own config (28960 = default)
3. Make the file executable and adjust the paths (file locations). Note: If you do not have a start.sh script to start your server, see below, I included one.
4. Schedule it as a crontab every minute, like so:
* * * * * /path/to/watchdog/script/mon.sh >/dev/null 2>&1
This script works with multiple COD servers on the same physical server. Just save multiple copies of the script and adjust the server port.Code:#!/bin/bash # COD2 Process Monitor - Server 1 # Restart COD2 Server When It Goes Down #Restart Command RESTART="/path/to/start/script/start.sh" #path to pgrep command PGREP="/usr/bin/pgrep" # find httpd pid $PGREP -f '.*28960' if [ $? -ne 0 ] # if server not running then # restart server $RESTART fi
In case you are not using a bash script to start your server, here's an example that uses screen to run the server in the background. Save it as start.sh, adjust paths and make it executable (no need to schedule in crontab).
Code:#!/bin/bash cd /home/cod2/cod2/ # Start server now! screen -A -m -d -S cod2pub /home/cod2/cod2/cod2_lnxded +set net_port 28960 +exec server.cfg +fs_homepath /home/cod2/cod2/



Reply With Quote