LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-11-2004, 12:43 PM   #1
rmount
LQ Newbie
 
Registered: Oct 2003
Distribution: CentOS
Posts: 22

Rep: Reputation: 15
Cron starting multiple copies of a server


I'm starting a game server with a Cron job:

*/1 * * * * /usr/control/cod start >/dev/null 2>&1

Basically, if the server dies (or someone kills it), it'll reload in 1 minute or less. I'm using this shell script to load the server:


#! /bin/sh
# Start CoD
# Last Change: 5.7.2004 (Creation)

CS_USER=mi-cod02
NAME=cod1
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DIR=/home/cod1/cod
DAEMON=cod_lnxded
PARAMS="+set dedicated 2 +exec config.cfg +map_rotate"
DESC="Call of Duty"

case "$1" in
start)
if [[ `screen -ls |grep $NAME` ]]
then
echo "Server is already running!"
else
echo "Starting $DESC: $NAME"
cd $DIR; screen -m -d -S $NAME ./$DAEMON $PARAMS
fi
;;

stop)
if [[ `screen -ls | grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `ps aux | grep -v grep | grep -i $CS_USER | grep -i screen | grep -i $NAME | awk '{print $2}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
;;

restart)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `ps aux | grep -v grep | grep -i $CS_USER | grep -i screen | grep -i $NAME | awk '{print $2}'`
echo " ... done.<br>"
else
echo "Coulnd't find a running $DESC<br>"
fi

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

status)
ps aux | grep -v grep | grep $NAME > /dev/null
CHECK=$?
[ $CHECK -eq 0 ] && echo "Server is UP" || echo "Server is DOWN"
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac

exit 0


The problem is the every so often, a new process get started. Sometimes i've got ten or more of them when i check. Is the ps & grep process too slow for Cron or something? Is my script messed up?

Thanks for any advice any can offer.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two Copies Of XFCE Starting? douceur Linux - Software 1 06-19-2005 01:05 PM
Mandrake 9.2 runs multiple copies of services. Help QtCoder Mandriva 0 03-10-2004 05:23 PM
Getting Multiple Copies of dhcpcd for Same Network Card MQMan Slackware 1 03-09-2004 11:41 AM
Printing multiple copies wjn Linux - Networking 4 12-16-2003 07:19 PM
network printing multiple copies drwolfson Linux - Hardware 0 12-11-2003 08:27 AM


All times are GMT -5. The time now is 09:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration