[cod] Start server using screen problem

BludGeonT[EUG] bludgeont at gmail.com
Fri Dec 10 12:44:12 EST 2004


If you wanted to use screen with these, you need to remember that if
you kill off a screen session with a game server in it, and you do a
screen -ls, you will see a screen entry saying its DEAD, in which case
you need to do a screen -wipe.

I'll give you a few ideas, you should be able to incorporate what
youre doing into this kind of setup.  Basically, under redhat linux,
first I check to see if the screen session is actually running, if it
is, it could be wedged, but if there is no screen session that shows
up in ps -ef, then its safe to assume that the server is not running,
so it starts it.

In the even that the screen session exists, then it goes and actually
checks the output from netstat based on the variables that are set up
in the top of the script, if the server is up and listening, netstat
will show it.  This works on a multihomed machine also.  If it detects
no UDP port listening that is specified, it restarts the server, or if
it detects it, it just bails out and says the server is running.

The screen -wipe command is used a couple of times in this script,
dont let the term get you confused.  When you run this, it will
basically clean off all stale and dead screen sessions.

Now, to list your servers running in  screens, do

screen -ls

and you'll see something like:

[eq at gamesrv01 ~]$ screen -ls
There are screens on:
        19609.eq_soldieroffortune2_pas_inf_1    (Multi, detached)
        12750.eq_callofduty_pas_sd_eug_1        (Multi, detached)
        5941.eq_callofduty_pas_uo_pub_1 (Multi, detached)
3 Sockets in /ms/svc/earthquake/.screen.


to attach to the screen, you then:

screen -r 12750

or

screen -r eq_callofduty_pas_sd_eug_1

The number in the front of the session listed above is the PID of the
screen session.

Then you are on the console of the server.  To properly detach from a
screen session, you need to do   CTRL A then D.  You will see a
detached message.  If you hit break or CTRL C, it will kill your game
server and the screen session off completely.

the $SERVERNAME variable is what will be used to label your screen
sessions, if you look at my example above, you will see that they each
have names to make it easy to decipher which server is which,
especially when you get lots of them running on a machine that can
handle it.

I didnt sanitize this script.  It should work out for you, or at least
give you an idea on how screen works and a couple of different options
on checking to make sure a server is up.

Hope this helps


:
# cron monitoring script
#
HOMEDIR="/home/games/cod"
SERVERNAME="DeathMatch_cod"
THISSERVER=192.168.1.1
THISPORT=28960

# Check if a screen session is running already for this server, if it is not, 
# then definately it needs to be started

ps -ef | grep -v grep | grep "SCREEN -S $SERVERNAME"
case $? in
    1)  echo "Instance not detected, restarting $SERVERNAME"
         screen -wipe           # to clear out any stale screens
         cd $HOMEDIR
         screen -S $SERVERNAME -dmS ./cod_lnxded +set net_ip ######
+set fs_homepath /home/games/logs/cod/ +exec cod1.cfg  +map_rotate
         case $? in
                 0) echo "$SERVERNAME started sucessfully!"
                     ;;
                 1) echo "There was a problem starting $SERVERNAME" ; exit 1
                     ;;
         esac
         ;;

     0) echo "Screen session already running, checking for IP and UDP listening"
         ;;
esac

# Now use netstat to check if they are listening - this wont detect
wedged servers
# buts its a sure fire way of detecting if the binaries are running.

netstat -an | grep $THISSERVER | grep $THISPORT

case $? in 

     0)  echo "$SERVERNAME appears to be listening in $THISSERVER :
$THISPORT" ; exit 0
          ;;

     *)  echo "$SERVERNAME doesn't appear to be up, restarting..."
         screen -wipe
         screen -S $SERVERNAME -dmS ./cod_lnxded +set net_ip ######
+set fs_homepath /home/games/logs/cod/ +exec cod1.cfg  +map_rotate
         ;;

esac







On Thu, 9 Dec 2004 15:01:10 -0000, Carlo Moretto
<Carlo at londonengland.co.uk> wrote:
> hi guys,
> 
> I have 2 scripts per server that check to see if the server is up and
> running and the main script is run via cron every 1 minute
> 
> here is the script that is run via cron:
> 
> #!/bin/bash
> #
> gamedir=/home/games/status/cod/
> pidfile=cod1.pid
> 
> cd $gamedir
> if [ -f $pidfile ]; then
>        kill -0 `cat $pidfile` >/dev/null 2>&1
>        if [ $? -ne 0 ]; then
>        ./start_cod1 >/dev/null 2>&1
>        fi
> else
>        ./start_cod1 >/dev/null 2>&1
> fi
> 
> here is the start_cod1 script:
> 
> #!/bin/bash
> cd /home/games/cod/
> 
> ./cod_lnxded +set net_ip ###### +set fs_homepath /home/games/logs/cod/ +exec
> cod1.cfg  +map_rotate  & echo $! >/home/games/status/cod/cod1.pid
> 
> Now, if I wanted to start this server via screen, where would I put the
> various screen commands (screen -dmS, screen -r etc etc)
> 
> Many thanks
> 
>



More information about the Cod mailing list