Quote Originally Posted by CaptainSlow View Post
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

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
This script works with multiple COD servers on the same physical server. Just save multiple copies of the script and adjust the server port.

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/
So I want to use this script. I just the exact same script, but with other startup, port and screenname.
I start it with
Code:
bash ./autoboot.sh
The screen is created, but the server is not started inside the screen, but in the "main" Putty window.
How to fix this?