#!/bin/sh

CONF_PATH=/etc/telephony
APP_PATH=/bin
ENGINE=xmlengine
SETSID=/usr/bin/setsid
KILLALL=/usr/bin/killall

# start XML engine 
do_start ()
{
	#/etc/init.d/softdogd wait
	#sleep 2
	$SETSID $APP_PATH/$ENGINE $CONF_PATH > /dev/null 2>&1 &
	
	return 0
}

# stop XML engine  
do_stop ()
{
	#/etc/init.d/softdogd wait
	$KILLALL $ENGINE > /dev/null 2>&1
	
	return 0
}

# Check status
do_status ()
{
	$KILLALL -0 $ENGINE > /dev/null 2>&1
	if [ $? != 0 ] ; then
		echo "$ENGINE is in an undefined state or is not running."
		return 2
	fi

	echo "$ENGINE is up and running."
	return 0
}


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

exit $?
