If you own a game server running on a linux box and you are in need of a auto restart function for your game server these scripts may be of use for you:

create the files "gsload.sh" and "gs.sh" with any editor (notepad or vi) and copy paste the following code:

gsload.sh
Code:
 
#!/bin/bash
NAME=gs1_port12205
DESC="Medal of Honor v1.12"
DIR=/home/gs1
SCRIPT=gs.sh
DAEMON=$DIR/$SCRIPT

case "$1" in
start)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME "
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... Server stopped ... Start will be executed"
else
echo ""
fi
echo "Starting $DESC: $NAME"
cd $DIR
screen -d -m -S $NAME $DAEMON
;;

stop)

if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... Server stopped."
else
echo "Found no server with PID -- $DESC --  "
fi
;;

restart)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME "
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... Server stopped ... Start will be executed"
else
echo "Found no server with PID -- $DESC -- ... Start couldn't executed"
fi

echo -n "Starting $DESC: $NAME"
cd $DIR
screen -d -m -S $NAME $DAEMON
;;

*)
echo "Usage: $0 Parameter {start|stop|restart}"
exit 1
;;
esac

exit 0
gs.sh
Code:
#! /bin/bash

echo "Launching Mohaa Server Port 12205"

cd server

while true
do

   ./mohaa_lnxded "+set dedicated 1 +set net_port 12205 +exec server.cfg"

   sleep 2

done
Now you need to edit some values so that it match your server layout:

in "gsload.sh" edit these values:

NAME=gs1_port12205 <==== change the port here to the port your server listens to, if you are running multiple servers with these scripts its important that the name is unique
DIR=/home/gs1 <==== change to the root directory

In this example "gs1" is the root directory where the files "gsload.sh" and "gs.sh" are located. The server itself is located in a subdirectory of the root directory called "server"

change accordingly in "gs.sh" these values:

echo "Launching Mohaa Server Port 12205" <==== change the port here to the port your server listens to
cd server <==== change to the subdirectory your server is located in
./mohaa_lnxded "+set dedicated 1 +set net_port 12205 +exec server.cfg" <====== change the port here and the arguments to your needs here


To initially start the server type:

Code:
./gsload.sh start
for stopping the server type:

Code:
./gsload.sh stop
for restarting the server type:

Code:
./gsload.sh restart