Try New Technology

Linux Service scripts for TF2 and L4D

by on Jun.06, 2009, under Techie

While I was working on the Unreal Tournament 3 (UT3) server I found a great post on the Epic Games Forum by Kzoink that had a Liunux Service script for UT3. I have adjusted it to correctly terminate both the srcds_run an srcds_i486. Below are copies of the them I am now using on my TF2 and L4D servers. I am using his original script for my upcoming UT3 server.

NOTE: For these scripts to work correctly you’ll need to ensure you have a file called startserver.sh in the tf2/l4d_home path that has “chmod +x” permissions. The startserver.sh file will contain your startup command line for the game. Please see one of the game server configs or Linux Service scripts at my Articles section for examples of the startserver.sh files you can use.

Team Fortress 2 (TF2) Linux Service script (please change tf2_home & tf2_ownr accordingly):

#!/bin/bash
#
# Run-level Startup script for srcds_run
#
# chkconfig: 345 91 19
# description: Starts and stops hlds dedicated server binary

tf2_home=”/home/teamfortress2/hlds/orangebox/”
tf2_ownr=”teamfortress2″

# if the executables do not exist — display error

if [ ! -f $tf2_home/startserver.sh -o ! -d $tf2_home ]
then
echo “HLDS TF2 Server: cannot start”
exit 1
fi

# depending on parameter — startup, shutdown, restart
# of the instance and listener or usage display

case “$1” in
start)
# HLDS TF2 basic start script or command can be called here. For my purposes I placed the entire command line a shell script called startserver.sh
echo -n “Starting HLDS TF2 Server: ”
su – $tf2_ownr -c “cd $tf2_home && ./startserver.sh &”
touch /var/lock/subsys/teamfortress
echo “OK”
;;
stop)
# TF2 kill-shutdown
echo -n “Shutdown HLDS TF2 Server: ”
su – $tf2_ownr -c “killall srcds_run”
su – $tf2_ownr -c “killall srcds_i486”
rm -f /var/lock/subsys/teamfortress
echo “OK”
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo “Usage: $0 start|stop|restart|reload”
exit 1
esac
exit 0

Left 4 Dead (L4D) Linux Service script (please change l4d_home & l4d_ownr accordingly):

#!/bin/bash
#
# Run-level Startup script for srcds_run
#
# chkconfig: 345 91 19
# description: Starts and stops hlds dedicated server binary

l4d_home=”/home/left4dead/hlds/l4d/”
l4d_ownr=”left4dead”

# if the executables do not exist — display error

if [ ! -f $l4d_home/startserver.sh -o ! -d $l4d_home ]
then
echo “HLDS L4D Server: cannot start”
exit 1
fi

# depending on parameter — startup, shutdown, restart
# of the instance and listener or usage display

case “$1” in
start)
# HLDS L4D basic start script or command can be called here. For my purposes I placed the entire command line a shell script called startserver.sh
echo -n “Starting HLDS L4D Server: ”
su – $l4d_ownr -c “cd $l4d_home && ./startserver.sh &”
touch /var/lock/subsys/left4dead
echo “OK”
;;
stop)
# L4D kill-shutdown
echo -n “Shutdown HLDS L4D Server: ”
su – $l4d_ownr -c “killall srcds_run”
su – $l4d_ownr -c “killall srcds_i486”
rm -f /var/lock/subsys/left4dead
echo “OK”
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo “Usage: $0 start|stop|restart|reload”
exit 1
esac
exit 0


Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...