Home > IT > Teamspeak 3 Server – Debian Startup Script

Teamspeak 3 Server – Debian Startup Script

December 23rd, 2009 Leave a comment Go to comments

In case you haven’t noticed: A few days ago the beta of TeamSpeak 3 was finally released.

At first glance, it seems to be a decent piece of software, which is more than you could say of its predecessor. The feature list is quite impressive and most of them seem to be well-thought-out.

One of the hurdles you’ll have to take when setting up a server yourself is the startup script. By now there are already countless user-made scripts flying around, but as you might’ve expected, that did not stop this author to write yet another one. This one avoids the grep/awk-voodoo of most scripts, instead using start-stop-daemon to get the job done.

As usual, this thing comes without any warranty whatsoever.

#!/bin/bash
#
#  Init script for TS3.
#  The server configuration will be written to the
#  SERVER_CONFIG_FILE .ini file on first start to avoid
#  display of server parameters in process listings; Thus
#  in order for changes to the config in this file to
#  be applied, stop the server, delete the .ini file
#  and run this script afterwards;
#  Do *not* apply config changes to the .ini directly!
#
 
## TS3 Config START
 
	# udp server port
	UDP_PORT=
 
	# number of virtual servers
	NUMBER_OF_SERVERS=1
 
	# additional options go here...
 
## TS3 Config END
 
# path to ts3 root directory
SERVER_PATH=<your_server_path_here>
# full path to ts3 server binary
SERVER_BINARY=$SERVER_PATH/<your_binary_name_here>
# user running ts3 server
TEAMSPEAK_SYSTEM_USER=<your_user_name_here>
# group running ts3 server
TEAMSPEAK_SYSTEM_GROUP=<your_group_name_here>
 
# server .ini config file
SERVER_CONFIG_FILE=ts3server.ini
 
# full path to pid file for start-stop-daemon
PID_FILE=$SERVER_PATH/server.pid
 
if [ -f $SERVER_CONFIG_FILE ]
then
	DAEMON_COMMAND_PARAMS="inifile=$SERVER_CONFIG_FILE"
else
	DAEMON_COMMAND_PARAMS="default_voice_port=$UDP_PORT \
				create_default_virtualserver=$NUMBER_OF_SERVERS \
				createinifile=1 \
				inifile=$SERVER_CONFIG_FILE"
fi						
 
case "$1" in
 start)
	echo "Starting TS3 server..."
	export LD_LIBRARY_PATH="${SERVER_PATH}:${LD_LIBRARY_PATH}"
	start-stop-daemon --start --quiet --exec "$SERVER_BINARY" --chdir "$SERVER_PATH" \
			  --chuid "$TEAMSPEAK_SYSTEM_USER" --group "$TEAMSPEAK_SYSTEM_GROUP" \
			  --background --make-pidfile --pidfile "$PID_FILE" \
			  $DAEMON_COMMAND_PARAMS
	if [ $? != 0 ]; then
		echo "! Failed. (Server already running?)"
		exit 1
	else
		echo "done."
	fi
 ;;
 stop)
 	echo "Stopping TS3 server..."
	start-stop-daemon --stop --quiet --pidfile "$PID_FILE"
	if [ $? != 0 ]; then
		echo "! Failed."
		exit 1
	else
		echo "done."
	fi
 ;;
 status)
	if [ -e $PID_FILE ]; then
		if ( kill -0 $(cat $PID_FILE) 2&gt; /dev/null ); then
			echo "Server is running"
		else
			echo "Server not running"
		fi
	else
		echo "Server PID file not found"
	fi
 ;;
 update-config)
 	echo "Deleting $SERVER_CONFIG_FILE..."
 	rm -f $SERVER_CONFIG_FILE
	$0 restart
 ;;
 restart)
	$0 stop && $0 start || exit 1
 ;;
 *)
	echo "Usage: $0 {start|stop|restart}"
    exit 1
 ;;
esac
 
exit 0

Update: Added export call for Beta17.

Categories: IT
  1. February 3rd, 2010 at 22:09 | #1

    I really liked this startup script and I used it with success.
    But now, beta 17 has been released and it already includes a start script.

    That start script is not as advanced as yours, but has a status-option, though.
    The real problem is that your script doesn’t work with the new binary anymore.

    Could you please update your script?
    (And perhaps add a status-option?)

    It will be appreciated greatly!

  2. February 4th, 2010 at 20:35 | #2

    @Erik van Paassen

    Thanks for pointing out, I adjusted the script. Turns out Beta17 needs an additional environment variable set before starting up.
    I also included the status command you requested as a bonus :)

    With the new version supplying the PID all by itself, the usage of start-stop-daemon has become obsolete. I will probably give the startup script a full rewrite to reflect the changes.
    Might take a couple of days though, I don’t feel much like bash-scripting atm 😉

  3. February 9th, 2010 at 19:09 | #3

    @Thaumiel
    Hi Thaumiel,

    It works fine now. Thanks for the update! There are just some little things you might want to correct.

    First of all, the restart-option says ‘….&&…’, but I think they shouldn’t have been entity-escaped, just &&. Otherwise, there’s a syntax error.

    Second, but not at all important, the usage-string could be updated with the status and update-config options.

    Although, it works now! Thanks again!

    Erik

  4. February 9th, 2010 at 19:12 | #4

    @Erik van Paassen
    In my previous comment, I meant the ‘…& amp’ & amp;…’ in the restart option, but WordPress was not escaping those.

  5. February 9th, 2010 at 19:17 | #5

    @Erik van Paassen

    Of course, my bad.

    Has been corrected.

  6. andy
    March 27th, 2010 at 17:06 | #6

    hey thanks, worked like a charm….just had to change the pid to ts3server.pid

  7. March 27th, 2010 at 17:27 | #7

    I just noticed another thing, on the line:
    if ( kill -0 $(cat $PID_FILE) 2> /dev/null ); then

    The > is entity escaped too, which it off course shouldn’t be.

    But besides that, I’m still using the script and I find it very useful. Thanks again!

  1. No trackbacks yet.