#! /bin/bash # Copyright (c) 2008 Unstable All rights reserved. # # Author: admin@unstable.co.uk 2008 # # Description: Runs and kills Call of Duty 4 server at boot time and shutdown. # Source function library. # Create a symlink to this script in /etc/rc3.d/S99cod4server or equivalent. # Tested on Fedora Core 6. # Released under the GPL License. # http://www.gnu.org/licenses/gpl.txt # START OF CONFIG SECTION # WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT USER=cod4 DIR=/var/games/cod4/cod4server CONFIG_FILE=server.cfg PID_FILE=cod4.pid BINARY=cod4_lnxded SERVER_ARGS="+map_rotate 1" # END OF CONFIG SECTION # See how we were called. case "$1" in start) if [ -e $DIR/$PID_FILE ]; then echo "$PID_FILE already exists...server already started ?"; echo "If you are sure the server is not running, delete $PID_FILE" exit 1 else echo "Starting the Call of Duty 4 Game server..." if [ -e $DIR/$BINARY ]; then if [ ! -x $DIR/$BINARY ]; then echo "$BINARY is not executable; trying to set it." chmod u+x $DIR/$BINARY fi if [ -x $DIR/$BINARY ]; then WD=`pwd` cd $DIR su $USER -c "$DIR/$BINARY +exec $CONFIG_FILE $SERVER_ARGS" > /dev/null 2>$1 & sleep 1 ps -fu cod4 | grep "$BINARY-bin" | awk '{print $2}' > $PID_FILE cd $WD else echo "$BINARY is not executable; fix this." exit 4 fi else echo "Couldnt find $BINARY." exit 5 fi fi ;; stop) if [ -e $DIR/$PID_FILE ]; then echo -n "Stopping the Call of Duty 4 Game server..." if ( kill -TERM `cat $DIR/$PID_FILE && rm $DIR/$PID_FILE` ); then for c in $(seq 1 300); do if [ -e $DIR/$PID_FILE ]; then echo -n "." sleep 1 fi done fi if [ -e $DIR/$PID_FILE ]; then echo "server does not shutdown cleanly - killing" kill -KILL `cat $DIR/$PID_FILE` rm $DIR/$PID_FILE sleep 5 else echo "done" fi else echo "$PID_FILE is missing; is the server stopped already?" fi ;; restart) $0 stop && $0 start || exit 1 ;; status) if [ -e $DIR/$PID_FILE ]; then echo "The Call of Duty 4 Game server is running." exit 0 else echo "The Call of Duty 4 Game server is stopped." exit 3 fi ;; *) echo "Usage: $0 {start|stop|restart|status|}" exit 2 esac exit 0