0

I'm looking over a script that would actually be restarting game-servers in case they crash. The game-servers are actually started in a screen session through a control panel. They have to be restarted by killing their respective screen session and starting them again in a new screen session with the same name. I've done this script by my self but it doesn't really work and runs into errors.

#!/bin/bash

START='cd /home/test; ./GameServer +set parameters'
SCREEN_NAME="test"


while /bin/true; do


sleep 5
SERVER=`ps --User test | grep GameServer | grep -v grep | wc -l`

 if [[ $SERVER -eq "0" ]]; then
    screen -S $SCREEN_NAME-X quit ; screen -S $SCREEN_NAME -md $START
    sleep 10
 fi
done

The process name is "gameserver" and an issue is with killing the screen session because it won't quit and if I kill all screen sessions, the screen running the script also quits.

test@de:~$ screen -list
There is a screen on:
        31861.2-test    (08/11/13 12:51:06)     (Detached)
1 Socket in /var/run/screen/S-test.

test@de:~$ screen -r 2-test -X quit
No screen session found.
test@de:~$ screen -x 2-test -X quit
No screen session found.
test@de:~$ screen -S 2-test -X quit
No screen session found.

I can although attach to the above screen by "screen -x" and I can also kill a screen with the same name using the above commands if I start it as: "screen -S test". I believe there's something in the Control panel that starts it in a different way such that it fails to attach using the name.

Asad Moeen
  • 437
  • 3
  • 11
  • 22

1 Answers1

4

Aw come on, don't use screen for this.

Use something that's actually designed to look after processes, and restart/respawn them when they die.

Anything else is just wheel-reinvention, and will never be as good or as tested.

Tom O'Connor
  • 27,480
  • 10
  • 73
  • 148
  • Well my control panel does the managing of services and processes but the only thing it doesn't do is the restarting of that service when it crashes. I have to manually restart it using the same control panel. And I guess these programs would only manage services that already exist in /etc/init.d ? – Asad Moeen Aug 13 '13 at 15:57