#!/bin/sh /etc/rc.common
START=98

PROG=/usr/sbin/beardropper
SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1

getKids() { 
 egrep "^PPid:	*$1$" /proc/[0-9]*/s*s 2>/dev/null | cut -f3 -d/ | xargs echo
}

start() {
    service_start ${PROG} -m follow   
    echo "beardropper started!"
}

stop() {
    #PID=`cat /var/run/bearDropper.pid`
	#kill `getKids $PID`
	kill -9 `pgrep -f /usr/sbin/beardropper`
	sleep 1
        service_stop ${PROG}
	echo "beardropper exit...."
}

restart() {
	enabled=$(uci get beardropper.@beardropper[0].enabled)
	pgrep -f ${PROG} >/dev/null
	if [ $? -eq 0 ];then #running
		if [ $enabled -eq 1 ]; then
			stop 
			sleep 1
			echo "beardropper is restarting..."
			start
		else 
			stop
		fi
	else
		if [ $enabled -eq 1 ]; then
			start
		else
			exit 0
		fi
	fi

}
