#!/bin/bash

# chkconfig: 35 90 12
# description: TeamSpeak Service
# processname: teamspeak

[ -f /etc/rc.d/init.d/functions ] || exit 0
. /etc/rc.d/init.d/functions

RETVAL=0
PROG="<%= teamspeak_bin %>"
ARGS="inifile=ts3server.ini"

start() {
	echo -n "Starting TeamSpeak server: "
	export LD_LIBRARY_PATH="/usr/local/teamspeak"
	daemon --user teamspeak "cd /srv/teamspeak ; $PROG $ARGS >/dev/null &"
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/teamspeak
	return $RETVAL
}

stop() {
	echo -n "Stopping TeamSpeak server: "
	killproc $PROG
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/teamspeak
	return $RETVAL
}

case "$1" in
	start)
	start
	;;

	stop)
	stop
	;;

	status)
	status $PROG
	;;

	restart|reload|condrestart)
	stop
	sleep 2
	start
	;;

	*)
	echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
	exit 1
esac

exit $RETVAL
