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.

#  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
	# number of virtual servers
	# additional options go here...
## TS3 Config END
# path to ts3 root directory
# full path to ts3 server binary
# user running ts3 server
# group running ts3 server
# server .ini config file
# full path to pid file for start-stop-daemon
	DAEMON_COMMAND_PARAMS="default_voice_port=$UDP_PORT \
				create_default_virtualserver=$NUMBER_OF_SERVERS \
				createinifile=1 \
case "$1" in
	echo "Starting TS3 server..."
	start-stop-daemon --start --quiet --exec "$SERVER_BINARY" --chdir "$SERVER_PATH" \
			  --background --make-pidfile --pidfile "$PID_FILE" \
	if [ $? != 0 ]; then
		echo "! Failed. (Server already running?)"
		exit 1
		echo "done."
 	echo "Stopping TS3 server..."
	start-stop-daemon --stop --quiet --pidfile "$PID_FILE"
	if [ $? != 0 ]; then
		echo "! Failed."
		exit 1
		echo "done."
	if [ -e $PID_FILE ]; then
		if ( kill -0 $(cat $PID_FILE) 2&gt; /dev/null ); then
			echo "Server is running"
			echo "Server not running"
		echo "Server PID file not found"
 	echo "Deleting $SERVER_CONFIG_FILE..."
	$0 restart
	$0 stop && $0 start || exit 1
	echo "Usage: $0 {start|stop|restart}"
    exit 1
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

    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!


  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.