#!/bin/sh

# start SIP Trunk communication agent 

. /etc/sysconfig/rc.conf
. /bin/network-functions


PIDFILE=/var/run/siptrunk-agent.pid
LOGGER="/bin/logger -t $0"

SERVICE=siptrunk-agent
PROCESS_NAME=siptrunk-agent
SETSID=/usr/bin/setsid

do_start ()
{
	/etc/init.d/softdogd wait
	
	if ! ServiceCheckRunning1 ; then
		return $?
	fi

	cd /telephony > /dev/null 2>&1
	$SETSID ./siptrunk-agent > /dev/null 2>&1 &
	echo $! > $PIDFILE

	ServiceCheckRunning2
	return $?
}

do_stop ()
{
	/etc/init.d/softdogd wait
	ServiceStop

	return $?
}

do_status ()
{
	ServiceStatus

	return $?
}

case "$1" in
	start)
		do_start
		;;
	stop)
		do_stop
		;;
	status) 
		do_status
		;;
	restart)
		do_stop
		/bin/usleep 500
		do_start
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
esac

exit $?

