#!/bin/sh
#
# fancontrol initscript 
# 
# 08-Dec-2004  aewyn@cloneshit.hu
#
# original version  
# http://www2.lm-sensors.nu/~lm78/cvs/browse.cgi/lm_sensors2/prog/init/fancontrol.init
# Jean Delvare (http://khali.linux-fr.org)
# Dean Takemori

FANCONTROL="/usr/sbin/fancontrol"
PIDFILE="/var/run/fancontrol.pid"

RETVAL=0
	
start()
{
   echo -n "Starting fancontrol daemon"
   daemon $FANCONTROL -n fancontrol
   RETVAL=$?
   [ $RETVAL -eq 0 ] && touch /var/lock/fancontrol
   echo
}
	
stop()
{
   echo -n "Stopping fancontrol daemon"
   daemon $FANCONTROL --stop -n fancontrol
   RETVAL=$?
   rm -f $PIDFILE
   rm -f /var/lock/fancontrol
   echo
}
	
status()
{
   if [ -f $PIDFILE ] ; then
     pid=`cat $PIDFILE`
   else
     echo -n "$FANCONTROL does not appear to be running"
     echo
     exit
   fi

   if [ -n "$pid" ] ; then
     ps -p $pid > /dev/null
     if [ $? ] ; then
       echo -n "$FANCONTROL appears to be running"
     else
       echo -n "$FANCONTROL does not appear to be running"
     fi
     echo
   fi
}
	
condrestart()
{
   [ -e /var/lock/subsys/fancontrol ] && restart || :
}

if [ ! -x $FANCONTROL ] ; then
   echo "Cannot run $FANCONTROL"
   exit 0
fi

case "$1" in
   start)
     start
     ;;

   stop)
     stop
     ;;

   status)
     status
     ;;
	
   restart)
     stop
     start
     ;;
	
   condrestart)
     condrestart
     ;;

   *)
echo "Usage: /etc/init.d/fancontrol {start|stop|status|restart|condrestart}"
     RETVAL=1
esac
	
exit $RETVAL

