#!/bin/sh

# PROVIDE: freeswitch
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable freeswitch:
#
# freeswitch_enable="YES"
#
#
#  freeswitch_user="freeswitch"
#  freeswitch_group="freeswitch"

. /etc/rc.subr

name=freeswitch
rcvar=`set_rcvar`

load_rc_config $name

: ${freeswitch_enable="NO"}
: ${freeswitch_user="freeswitch"}
: ${freeswitch_group="freeswitch"}
: ${freeswitch_flags="-nc -waste"}

command=/usr/local/bin/freeswitch
command_args="-u ${freeswitch_user} -g ${freeswitch_group}"

pidfile=${freeswitch_pidfile:-"/var/run/freeswitch/freeswitch.pid"}

start_precmd="${name}_prestart"
stop_cmd="${name}_stop"

freeswitch_stop () {
        echo "Stopping FreeSWITCH."
        /usr/local/bin/freeswitch -stop
	wait_for_pids `cat $pidfile`
}

freeswitch_prestart () {
	install -d -o ${freeswitch_user} -m755 /var/run/${name}
}

run_rc_command "$1"
