#! /bin/sh

DAEMON=onvif_srvd_debug
DAEMON_PATH=.
PID_FILE=$DAEMON.pid

DAEMON_ARGS="--pid_file $PID_FILE"


# ONVIF Device Service param (more details see help)
DAEMON_ARGS="$DAEMON_ARGS --ifs eth0"
DAEMON_ARGS="$DAEMON_ARGS --scope onvif://www.onvif.org/name/TestDev"
DAEMON_ARGS="$DAEMON_ARGS --scope onvif://www.onvif.org/location/Unknow"
DAEMON_ARGS="$DAEMON_ARGS --scope onvif://www.onvif.org/Profile/Streaming"
DAEMON_ARGS="$DAEMON_ARGS --scope onvif://www.onvif.org/Profile/S"
DAEMON_ARGS="$DAEMON_ARGS --name RTSP --width 800 --height 600 --url rtsp://%s:554/unicast --type JPEG"



d_start()
{
    if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE); then
        echo "$DAEMON already running"
        return 1
    fi

    echo "Starting $DAEMON..."
    $DAEMON_PATH/$DAEMON $DAEMON_ARGS && echo "$DAEMON started"
}



d_stop()
{
    if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE"); then
        echo "$DAEMON not running"
        return 1
    fi

    echo "Stopping $DAEMON..."
    kill -15 $(cat $PID_FILE) && rm -f $PID_FILE
    echo "$DAEMON stopped"
}



case "$1" in
      start)
          d_start
          ;;
      stop)
          d_stop
          ;;
      restart)
          echo "Restarting $DAEMON"
          d_stop
          d_start
          ;;
      *)
          echo "Usage: $0 {start|stop|restart}"
          exit 1
          ;;
esac
