08-04-2011, 06:04 AM
Here is my sturtup script. It is more simple and without using pid files.
Writen for use with OpenSuSE 11.4 x32_64, but will work with any other GNU/Linux system
Dependencies for clean minimal server (package names from OpenSuSe repos):
glibc-32bit
libstdc++45-32bit
gdb
screen
gzip2
Writen for use with OpenSuSE 11.4 x32_64, but will work with any other GNU/Linux system
Dependencies for clean minimal server (package names from OpenSuSe repos):
glibc-32bit
libstdc++45-32bit
gdb
screen
gzip2
Code:
#!/bin/bash
### BEGIN INIT INFO
# Provides: css1
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Valve dedicated server
# Description: Counter-Strike Source Server
### END INIT INFO
SERVERNAME="VIPGAMES CS:S Server #1"
USERNAME="css"
SERVICE="css1"
BINDIR="/home/css/css1/orangebox"
BIN="srcds_run"
IP="10.0.12.7"
PORT="27015"
MAP="de_dust2"
GAME="cstrike"
MAXPLAYERS="22"
OPTS="./$BIN -game $GAME -ip $IP -port $PORT -insecure +sv_lan 0 +maxplayers $MAXPLAYERS +map $MAP"
CURRENT_USER=`/usr/bin/whoami`
as_user() {
if [ $CURRENT_USER == $USERNAME ] ; then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}
case "$1" in
start)
if ps axw | grep -v grep | grep -v -i SCREEN | grep $BIN | grep $IP | grep $PORT > /dev/null
then
echo "$SERVERNAME is already running!"
else
echo "STARTING $SERVERNAME at $IP:$PORT ... "
as_user "cd $BINDIR && screen -dmS $SERVICE $OPTS"
sleep 1
if ps axw | grep -v grep | grep -v -i SCREEN | grep $BIN | grep $IP | grep $PORT > /dev/null
then
echo "OK"
else
echo "ERROR"
fi
fi
;;
stop)
if ps axw | grep -v grep | grep -v -i SCREEN | grep $BIN | grep $IP | grep $PORT > /dev/null
then
echo "SHUTING DOWN $SERVERNAME at $IP:$PORT ... "
kill -9 `ps axw | grep -v grep | grep -v -i SCREEN | grep ${BIN} | grep ${IP} | grep $PORT | awk '{print $1}'`
sleep 1
if ps axw | grep -v grep | grep -v -i SCREEN | grep $BIN | grep $IP | grep $PORT > /dev/null
then
echo "ERROR - $SERVERNAME is still runing at $IP:$PORT"
else
echo "OK"
fi
else
echo "$SERVERNAME is not runing"
fi
;;
restart)
if ps axw | grep -v grep | grep -v -i SCREEN | grep $BIN | grep $IP | grep $PORT > /dev/null
then
echo "RESTARTING $SERVERNAME at $IP:$PORT ... "
kill -9 `ps axw | grep -v grep | grep -v -i SCREEN | grep ${BIN} | grep ${IP} | grep $PORT | awk '{print $1}'`
sleep 1
if ps axw | grep -v grep | grep -v -i SCREEN | grep $BIN | grep $IP | grep $PORT > /dev/null
then
echo "ERROR - $SERVERNAME is still runing at $IP:$PORT, couldn't restart it"
else
as_user "cd $BINDIR && screen -dmS $SERVICE $OPTS"
echo "OK"
fi
else
echo "$SERVERNAME is not runing"
fi
;;
status)
if ps axw | grep -v grep | grep -v -i SCREEN | grep $BIN | grep $IP | grep $PORT > /dev/null
then
echo "$SERVERNAME is running."
else
echo "$SERVERNAME is not running."
fi
;;
*)
echo "Usage: /etc/init.d/$SERVICE {start|stop|restart|status}"
exit 1
;;
esac