#!/bin/sh

# TODO :  Add rc.status


UNIX_C="/usr/local/bin/unixclient"
BARK_BIN="/usr/local/bin/bark"
BARK_ARGS="-d"   # use "-z -d" for debug messages
SOCKET=/tmp/socket
#SSD_BIN="/sbin/start-stop-daemon"
#USER="adtec"


#. /etc/profile


case "$1" in
    start)
        # check if running
        if [ -z $(pgrep -f $BARK_BIN) ]; then
           echo -n "Starting bark daemon..."
           $UNIX_C $SOCKET $BARK_BIN $BARK_ARGS &
           #echo $$ > $BARK_PID
           # some reason, ssd is not working with this.
           #$SSD_BIN --start --background --exec $UNIX_C --pidfile $BARK_PID --make-pidfile --chuid $USER -- "$SOCKET $BARK_BIN $BARK_BIN"
           echo "Done."
        else
           echo "Bark daemon running.  Not starting."
        fi            
        ;;
    stop)
        echo "Shutting down bark daemon"
	pkill -f $BARK_BIN
#        $SSD_BIN -K -p $BARK_PID  > /dev/null 2>&1

        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac
