Sunday, 11 August 2013

Auto-restart crashed service/script

Auto-restart crashed service/script

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 the control panel and they can crash due to a lot of
reasons. 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="Command-to-Start"
SCREEN_NAME="test"
SERVER=`ps ax | grep gameserver | grep -v grep | wc -l`
while /bin/true; do
sleep 5
if [ $SERVER -eq 1 ]
then
else
screen -x -X quit ; screen -S $SCREEN_NAME -md $START
sleep 10
fi
The process name is "gameserver" and an issue is that a couple of users on
the system have the same process name although each of their file is
located in and runs from a different directory. That's where the "ps" and
"grep" commands fail because username is not specified. How do we get to
use it if the process name is "gameserver" and we have to grep the one
running under "test" ?

No comments:

Post a Comment