#!/bin/sh

# PROVIDE: teamspeak
# REQUIRE: LOGIN 
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# teamspeak_enable (bool):   Set to NO by default.
#               Set it to YES to enable teamspeak server.
#

. /etc/rc.subr

name="teamspeak"
rcvar=teamspeak_enable

load_rc_config $name

: ${teamspeak_enable:="NO"}
: ${teamspeak_pidfile:="/var/db/teamspeak/teamspeak_server.pid"}
: ${teamspeak_db_dir:="/var/db/teamspeak"}
: ${teamspeak_log_dir:="/var/log/teamspeak"}

# Add flags var so it isn't called in daemon
flags=" "
procname=/usr/local/libexec/ts3server
command=/usr/sbin/daemon
command_args="-fp "$teamspeak_pidfile" -u teamspeak /usr/local/libexec/ts3server dbsqlpath=/usr/local/share/teamspeak/server/sql/ inifile=/usr/local/etc/teamspeak/ts3server.ini licensepath=/usr/local/etc/teamspeak/ logpath="$teamspeak_log_dir" license_accepted=1 $teamspeak_flags"
teamspeak_chdir="$teamspeak_db_dir"
required_dirs="$teamspeak_db_dir $teamspeak_log_dir"

LD_LIBRARY_PATH=/usr/local/lib/teamspeak/server:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

run_rc_command "$1"
