#!/bin/sh

# PROVIDE: teamspeak
# REQUIRE: LOGIN %%MYSQL%%
# 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:="%%DBDIR%%/teamspeak_server.pid"}
: ${teamspeak_db_dir:="%%DBDIR%%"}
: ${teamspeak_log_dir:="%%LOGDIR%%"}

# Add flags var so it isn't called in daemon
flags=" "
procname=%%PREFIX%%/libexec/ts3server
command=/usr/sbin/daemon
command_args="-fp "$teamspeak_pidfile" -u teamspeak %%PREFIX%%/libexec/ts3server dbsqlpath=%%PREFIX%%/share/teamspeak/server/sql/ inifile=%%PREFIX%%/etc/teamspeak/ts3server.ini licensepath=%%PREFIX%%/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=%%PREFIX%%/lib/teamspeak/server:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

run_rc_command "$1"
