#! /bin/sh
#
# Start the Counter-Strike dedicated server.
#
# AUTHORS :
#
# Julien Escario ( pandemik@azilog.net )
# &
# Cedric Rochat ( crochat@younics.org )
#
# ===========================================
#
# What you need:
#
# Linux :)
# awk
# screen
# the hlds_l & cstrike-files
#
# How to use:
#
# Edit the DIR-Var to fit your system (just contains the path to the dir that contains hlds_run)
# Edit the PARAMS-Var to fit your needs
# - standard is startup as LAN-server
#
# When this is done, copy the file to /etc/rc.d/init.d (or whereever your system stores the
# scripts for starting the services
# Now you can link the script to your runlevel-dir, here's an example for runlevel 3:
# ln -s /etc/rc.d/init.d/hlds /etc/rc.d/rc3.d/S90hlds
# ln -s /etc/rc.d/init.d/hlds /etc/rc.d/rc3.d/K50hlds
#
# Or use it manualy like:
# /etc/rc.d/init.d/hlds start
# /etc/rc.d/init.d/hlds stop
#
# How to see the server-console:
#
# Just type in: screen -r cstrike
# More info about screen can be found by typing "man screen" or using this nice link
# http://server.counter-strike.net/help/linuxscreen.html
#
# If you don't want to start the server as root you have to change this:
# add the var CS_USER and uncomment it
# change the lines at the "start-block"
#
# You must be logged in as this user to re-attach the screen!
#
# DOC by jwm (jwm@counter-strike.de)
clear
# Edit and uncomment it to run the server as non-root
# CS_USER="gamesrv"
PATH=/bin:/usr/bin:/sbin:/usr/sbin
# DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS!
DIR=/home/hlds/css/public
DAEMON=$DIR/srcds_run
# Internet-server:
PARAMS="-console -tickrate 100 -secure -game cstrike -port 27015 +ip 217.172.44.116 +map de_dust2 +maxplayers 26 -autoupdate -debug -verify_all"
NAME=css1
DESC="=|PWF|= Server"
case "$1" in
start)
echo "Starting $DESC: $NAME"
if [ -e $DIR ];
then
cd $DIR
# Change the lines for running as non-root!
# su $CS_USER -l -c "screen -d -m -S $NAME $DAEMON $PARAMS"
screen -d -m -S $NAME $DAEMON $PARAMS
else echo "No such directory: $DIR!"
fi
;;
stop)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
;;
restart)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
echo -n "Starting $DESC: $NAME"
cd $DIR
screen -d -m -S $NAME $DAEMON $PARAMS
echo " ... done."
;;
status)
# Check whether there's a "hlds" process
# if "checkproc" is installed, you can use this:
# checkproc $DIR/hlds_run && echo "CS-Server RUNNING" || echo "CS-Server NOT RUNNING"
# (thx to commander)
ps aux | grep -v grep | grep hlds_r > /dev/null
CHECK=$?
[ $CHECK -eq 0 ] && echo "HLDS is UP" || echo "HLDS is DOWN"
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0