Home ~  CG /  Choppergirl ~  Dorothy ~  Alice ~  Poor Girl ~  14 Mile ~  Build Plan

Youtube ~  Cheapskate Flyer ~  Music to Fly to ~  Musicbox ~  Banner Graphix

FPV ~  Flags ~  Tshirts ~  Greg ~  Donate ~  Archive ~  Volmer Jensen




Game servers are notoriously unreliable; they die all the time. At least every couple of hours.

When they die, your game server is offline, at least until you realize this, and then you have to manual restart it.

This can happen many times a day, day in and day out every day of every year. You don't have time to monitor your server and restart it all the time.

There are products such as TCadmin, gamecp, SwiftPanel, god, Procautostart, ps-watcher, monit, and so on that purport to watch a (game server) process and start/stop/ restart it if it has crashed. Some have some other options to ftp up files with a web interface and edit some default files, and are all very complex pieces of software and cost money and add a lot of junk which you don't need. I got so fed up with trying to get any one of them to work that I finally wrote my own.

You don't need all that other crap. All you need to do all the work for you is a script which does one thing: watches a process and restarts it if it has died.

That Linux does not have a command built in to do this, is totally appalling to me.

To run a game server under Linux and mod it, all you need is the very basics:

  • a basic knowledge of working on a linux command line shell
  • an account on a linux box with bandwidth
  • httpd, ftpd, and telnetd server running on the linux box
  • an ftp client program to upload your game server directory to the linux box
  • your game server directory for the game you want to play
  • a text editor to edit text files
  • a way to unzip files
  • my script below
Once you have your game up and running under Linux, use my very simple code below that will watch your linux game server and restart it if it has died.

# Monitor Linux Game Server Process with Cron Job and Restart Process If Not Present

# this is a (very simple) bash script, to do one thing, watch a process and restart it if it has died


# STEP 1
# you may have to install bash as root with yum install bash
# but most systems have bash pre installed (do ls /bin/bash ) to check if unsure
# most likely it is, so proceed...

# In my examples, username where my server is installed is "airwar", replace with your own account

# Save this file in your home dir, in my case /home/airwar/
# make it executable with the command
# chmod a+x /home/airwar/

# STEP 2
# next, edit all the variables for your server below under 'config variables below'

# if you need to monitor more than one serer, copy the code under "FIRST SERVER"
# and paste it as many times for a SECOND SERVER, THIRD SERVER, etc.
# edit the variables to be correct for each one

# STEP 3
# to test if script works, run it as many times as you want from command line with
# ./
# if your server is not running, it will/should start it
# if its already running, it won't do anything but exit with a number (its own pid saying its finished)
# if the script dies on the first line, you probably added some garbage line breaks
# into the file with your text editor; if so, recreate the file using midnight commander editor
# $ yum install mc and recreate with "mcedit"

# STEP 4
# Once you know that it works, su root, and then edit /etc/rc.local and add these two lines
# so the script will be restarted with every reboot, in case entire system crashes... and it
# will bring your server right back up
# su airwar
# home/airwar/

# STEP 5
# if you ever need to bring down your server, first kill the
# proces in the process list (do ps -ax, look for its pid, then kill pidnumber
# then look for your game server pid the same way, and kill it as well.
# later I'll write a script to do this.

# STEP 6
# to make it survive reboots, edit /etc/rc.local and add this line,
# substituting username airwar and home directory to point to your script:
# sudo -u airwar nice /home/airwar/ &

# --------------------------------------------------------------------
while true

# --------------------------------------------------------------------


# config variables below
# path to pgrep command, mostly this is correct and you don't need to change it
# string of name of process you want to look for in process table
# directory of where game dir process is to be restarted
# command to execute to restart process (add amperstand to background it and continue script)
RESTART="./ &"

# here's the actual tiny program - now do actual check if server is listed in process list and if not, start it
# find APPNAMEs pid
if [ $? -ne 0 ] # if APPNAME not running
# restart APPNAME
echo Restarting Server

# --------------------------------------------------------------------

# SECOND SERVER, etc - copy all code above for first server, paste here, and edit to suit for each server

# --------------------------------------------------------------------

# wait/sleep for x seconds, and then repeat whole loop
sleep 15

# --------------------------------------------------------------------


Home ~  CG /  Choppergirl ~  Dorothy ~  Alice ~  Poor Girl ~  14 Mile ~  Build Plan

Youtube ~  Cheapskate Flyer ~  Music to Fly to ~  Musicbox ~  Banner Graphix

FPV ~  Flags ~  Tshirts ~  Greg ~  Donate ~  Archive ~  Volmer Jensen

Contact & Website Administrator: