#!/bin/sh
#----------------------------------------------------------------------------------
# rtspmg -- Start/stop RTSPD Management Daemon(FW) services.
#----------------------------------------------------------------------------------

BIN_PATH="/opt/nss/bin/rtspmg"

[ -f $BIN_PATH ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
  start)
	echo -n "Starting RTSPMG Service Daemon: "
	$BIN_PATH
	RETVAL=$?

	if [ $RETVAL -eq 0 ]; then
		echo "[  OK  ]"
	else
		echo "[FAILED]"
	fi

	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/rtspmg
	;;
  stop)
	echo -n "Stopping RTSPMG Service Daemon: "

	RTSPMG_PROC=`/sbin/pidof rtspmg`
	while [ -n "$RTSPMG_PROC" ]
	do
		[ -f /var/run/rtspmg.pid ] && kill `cat /var/run/rtspmg.pid`
		/bin/sleep 1
		RTSPMG_PROC=`/sbin/pidof rtspmg`
	done

	if [ ! -e /tmp/rtspmgstart ]; then
		RETVAL=0
		echo "[  OK  ]"
	else
		RETVAL=-1
		echo "[FAILED]"
	fi

	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/rtspmg
	;;
  restart)
  	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
	echo "Usage: rtspmg {start|stop|restart}"
	exit 1
esac

exit $RETVAL
