#!/bin/bash
#
#	/etc/rc.d/init.d/nanny
#
# Starts the nanny daemon
#
# chkconfig: 3457 99 50
# description:  Nanny daemon is an easy way to control what your kids \
#               are doing in the computer. \
#               See http://projects.gnome.org/nanny
# processname: nanny
#
# pidfile: /var/run/nanny.pid
### BEGIN INIT INFO
# Provides: nanny nannydeamon
# Required-Start: messagebus
# Required-Stop: messagebus
# Default-Start: 3 4 5 7
# Short-Description: Nanny daemon
# Description: This is a daemon for maintaining information
#              about parental control.
#              See http://projects.gnome.org/nanny/
### END INIT INFO

# Source function library.
. /etc/init.d/functions

test -x /usr/bin/twistd || exit 0

RETVAL=0

#
#	See how we were called.
#

prog="nanny"
USER=`id -u root`
GROUP=`id -g root`
TWISTED_FILE='/usr/share/nanny/daemon/nanny.tap'
TWISTED_PID='/var/run/nanny.pid'
TWISTED_LOG='/var/log/nanny.log'
servicename=NannyDaemon

start() {
	# Check if nanny is already running
 if [ ! -f /var/lock/subsys/nanny ]; then
 gprintf "Starting %s: " "$prog"
 daemon /usr/bin/twistd -r glib2 -y $TWISTED_FILE --pidfile=$TWISTED_PID --logfile=$TWISTED_LOG -u $USER -g $GROUP
 RETVAL=$?
 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/nanny
 echo
 fi
return $RETVAL
}

stop() {
	gprintf "Stopping %s: " "$prog"
	killproc twistd -TERM
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/nanny
	echo
        return $RETVAL
}


restart() {
	stop
	start
}	

reload() {
	restart
}	

status_at() {
 	status /usr/bin/twistd
}

case "$1" in
start)
	start
	;;
stop)
	stop
	;;
reload|restart)
	restart
	;;
condrestart)
	if [ -f /var/lock/subsys/nanny ]; then
	    restart
	fi
	;;
status)
	status_at
	;;
*)
	gprintf "Usage: %s {start|stop|restart|condrestart|status}\n" "$0"
	exit 1
esac

exit $?
exit $RETVAL
