Archive

Archive for December, 2009

Teamspeak 3 Server – Debian Startup Script

December 23rd, 2009 7 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