SRCDS Steam group


[Linux/Unix]: Init.d Script for SRCDS
#1
Just polished up the script I am using for SRCDS, which has been built on top of some of the ones I found on the net.

I use /etc/init.d/SRCDS but you can call it whatever you please.

Using screen to keep the process output detached in the background and using your "newuser" to avoid using root.

Code:
# replace <newuser> with the user you want to run the server as (NOT ROOT)
SRCDS_USER="<newuser>"
# Do not change this path
PATH=/bin:/usr/bin:/sbin:/usr/sbin
# The path to the game you want to host. Replace <filepath> with your path, example = /home/newuser/tf2/orangebox
DIR=<filepath>
DAEMON=$DIR/srcds_run
# Change all PARAMS to your needs.
PARAMS="-console -game tf +map ctf_2fort -maxplayers 30 -autoupdate"
# Change <name> to what you want the detached screen to be called. e.g. SRCDS-TF2
NAME=<name>
DESC="Source Dedicated Server"
case "$1" in
start)
echo "Starting $DESC: $NAME"
if [ -e $DIR ];
then
  cd $DIR
su $SRCDS_USER -l -c "screen -d -m -S $NAME $DAEMON $PARAMS"
else echo "No such directory: $DIR!"
fi
;;
stop)
if su $SRCDS_USER -l -c "screen -ls |grep $NAME"
then
     echo -n "Stopping $DESC: $NAME"
     su $SRCDS_USER -l -c "screen -S $NAME  -X quit "
    echo " ... done."
else
    echo "Couldn't find a running $DESC"
fi
;;
restart)
if su $SRCDS_USER -l -c "screen -ls |grep $NAME"
then
     echo -n "Stopping $DESC: $NAME"
     su $SRCDS_USER -l -c "screen -S $NAME  -X quit "
     echo " ... done."
else
     echo "Couldn't find a running $DESC"
fi
echo -n "Starting $DESC: $NAME"
cd $DIR
su $SRCDS_USER -l -c "screen -d -m -S $NAME $DAEMON $PARAMS"
echo " ... done."
;;
status)
# Check whether there's a "srcds" process
ps aux | grep -v grep | grep srcds_r > /dev/null
CHECK=$?
[ $CHECK -eq 0 ] && echo "SRCDS is UP" || echo "SRCDS is DOWN"
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0


On Ubuntu, add this script to your /etc/init.d directory. <script> = Scriptname e.g. SRCDS-TF2

Code:
sudo update-rc.d <script> defaults

To start the server:
Code:
/etc/init.d/<script> start

To stop the server:
Code:
/etc/init.d/<script> stop

To restart:
Code:
/etc/init.d/<script> restart

To check status:
Code:
/etc/init.d/<script> status
Which will reply either UP (online) or DOWN (offline.)


In Ubuntu you can also use:
Code:
service <script> restart

and the other start stop status commands.






I do however take no responsibility for any screw ups/ complaints about the hacky nature of the closing of the server.

Built upon the work here:
http://www.freenerd.net/index.php?title=Linux_SRCDS_server
and
http://stevenbenner.com/2010/11/how-to-set-up-a-team-fortress-2-dedicated-server-on-ubuntu/
Check out http://resshef.co.cc for more stuff.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)