I'm new to the SRCDS scene, and I have just set up my first dedicated TF2 server on linux. This website has been a great source of information for me setting everything up, so I wanted to give a little back.
I found just a few init scripts around the internet, though nothing really did what I wanted it to do, so I made my own. I like my init scripts to tell me more information that a simple "Service started" message. I also wanted the ability to stop and even restart a service without much effort in case the server failed.
This script is rather simple to configure and should only take you 10 minutes to set up. Configure the script's variables at the beginning to match your server's settings. It's well commented to help you understand what everything does.
Code:
#!/bin/sh
# Source Dedicated Server Init Script
# Server options
TITLE='Source Dedicated Server' # Script initialization title
LONGNAME='Team Fortress 2' # Full title of game type
NAME='tf2' # Server handle for the screen session
DAEMON='srcds_run' # The server daemon
STEAM='/home/tf2/orangebox' # STEAM to Steam installation
USER='tf2'
# Game options
IP='72.52.248.250' # IP of the server
PORT='27015' # Port number to
MAP='ctf_2fort' # Initial map to start
GAME='tf' # Game type (tf|cstrike|valve|hl2mp)
SIZE='24' # Maximum number of players
# Screen command
INTERFACE="/usr/bin/screen -A -m -d -S $NAME"
service_start() {
# Check if the pid files currently exist
if [ ! -f $STEAM/$GAME/$NAME.pid ] && [ ! -f $STEAM/$GAME/$NAME-screen.pid ]; then
if [ -x $STEAM/$DAEMON ]; then
echo "Starting $TITLE - $LONGNAME"
echo "Server IP: $IP"
echo "Server port: $PORT"
echo "Server size: $SIZE players"
cd $STEAM
$INTERFACE $STEAM/$DAEMON $OPTS
# Prevent race condition on SMP kernels
sleep 1
# Find and write current process id of the screen process
ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > $STEAM/$GAME/$NAME-screen.pid
echo "$TITLE screen process ID written to $STEAM/$GAME/$NAME-screen.pid"
echo "$TITLE server process ID written to $STEAM/$GAME/$NAME.pid"
echo "$TITLE started."
fi
else
echo -e "Cannot start $TITLE. Server is already running."
#exit 1
fi
}
service_stop() {
if [ -f $STEAM/$GAME/$NAME.pid ] && [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
echo "Stopping $TITLE - $LONGNAME."
# Get the process ID from the pid file we created earlier
for id in `cat $STEAM/$GAME/$NAME-screen.pid`
do kill -9 $id
echo "Killing process ID $id"
echo "Removing $TITLE screen pid file"
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
done
# Remove server pid file
echo "Removing $TITLE pid file"
rm -rf $STEAM/$GAME/$NAME.pid
# Wipe all old screen sessions
screen -wipe 1> /dev/null 2> /dev/null
echo "$TITLE stopped."
else
echo -e "Cannot stop $TITLE. Server is not running."
#exit 1
fi
}
Good point I'll add some more instructions, format it a little more nicely, and add it to the tutorials section. My second edition of the script will take a second command-line parameter to start, stop and restart multiple game servers on the same physical server.
I like scripting (as my name implies), so if anyone has requests for a script, please post here or PM me. I'd prefer a post so others can benefit.
It's always a good idea to run any service as a user instead of root, so I'll be modifying this script to run as a user. Would it be beneficial to anyone if I wrote a tutorial on setting up a chrooted SRCDS environment? I have seen many tutorials on setting up SRCDS, but none yet on setting up SRCDS in a secure manner.
It's always a good idea to run any service as a user instead of root, so I'll be modifying this script to run as a user. Would it be beneficial to anyone if I wrote a tutorial on setting up a chrooted SRCDS environment? I have seen many tutorials on setting up SRCDS, but none yet on setting up SRCDS in a secure manner.
I'll be putting CentOS 5.1 on my latest server. I'm a Debian fan personally, but CentOS/RedHat are both more popular. Once I get everything up and running, I'd be happy to write a tutorial for both Debian and Red Hat-based distributions. I will gladly accept requests if anyone uses something different (unless it's Gentoo, because you should be able to do it yourself ).
The CentOS tutorial should work for versions 4 and up; there is little difference with configuring chkconfig, et alia.
On another note, I have been looking for a web-based SRCDS administration toolkit, and haven't found one yet. Is there such a thing? I would like to be able to edit various files, like my server.cfg, maplist, mapcycle, etc.
I'll be putting CentOS 5.1 on my latest server. I'm a Debian fan personally, but CentOS/RedHat are both more popular. Once I get everything up and running, I'd be happy to write a tutorial for both Debian and Red Hat-based distributions. I will gladly accept requests if anyone uses something different (unless it's Gentoo, because you should be able to do it yourself ).
The CentOS tutorial should work for versions 4 and up; there is little difference with configuring chkconfig, et alia.
On another note, I have been looking for a web-based SRCDS administration toolkit, and haven't found one yet. Is there such a thing? I would like to be able to edit various files, like my server.cfg, maplist, mapcycle, etc.
Cheers!
I use IGC game panel on my clan box and it does the job. 5 bucks a month and does everything you need to be done through a web based control. Good luck. http://www.innovativegamingconcepts.com/
I'll be putting CentOS 5.1 on my latest server. I'm a Debian fan personally, but CentOS/RedHat are both more popular. Once I get everything up and running, I'd be happy to write a tutorial for both Debian and Red Hat-based distributions. I will gladly accept requests if anyone uses something different (unless it's Gentoo, because you should be able to do it yourself ).
The CentOS tutorial should work for versions 4 and up; there is little difference with configuring chkconfig, et alia.
On another note, I have been looking for a web-based SRCDS administration toolkit, and haven't found one yet. Is there such a thing? I would like to be able to edit various files, like my server.cfg, maplist, mapcycle, etc.
Cheers!
I use IGC game panel on my clan box and it does the job. 5 bucks a month and does everything you need to be done through a web based control. Good luck. http://www.innovativegamingconcepts.com/
Same panel I also use. Can be a bitch to setup on debian-based linux distros, but it runs well once you get the hang of it .
Hmm, I only host one server for now, and it's not even populated 90% of the time I'm surprised there's no open source one out there. Heck, I think I just found my next project
Spartanfrog Wrote:tcadmin.com More proffesional but its good
Doubt he uses windows since he is coding a linux script
The only that I know is close to free (not necassarily opensource) is the cpanel one, but that's only if you already have cpanel installed on your box. http://cpgs.cpanel.net/