#!/bin/sh
#
# fancontrol
#
# chkconfig: 2345 90 01
# description: start/stop fancontrol
# config: /etc/fancontrol
# pidfile: /var/run/fancontrol.pid
#
### BEGIN INIT INFO
# Provides:       fancontrol
# Required-Start: $local_fs
# Required-Stop:  $local_fs
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Description:    fancontrol Service
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

LOCKFILE=/var/lock/subsys/fancontrol
CONFIG=/etc/fancontrol
FANCONTROL=/usr/sbin/fancontrol
PIDFILE=/var/run/fancontrol.pid

# Get config.
if [ ! -s "$CONFIG" ]; then
   echo "$CONFIG is empty! Setup it first with pwmconfig(8)"
   exit 1
fi

RETVAL=0

start()
{
   start_daemon --lockfile "$LOCKFILE" --pidfile "$PIDFILE" --background -- $FANCONTROL
   RETVAL=$?
   return "$RETVAL"
}

stop()
{
   stop_daemon --lockfile "$LOCKFILE" --pidfile "$PIDFILE" --name fancontrol -- $FANCONTROL
   RETVAL=$?
   return "$RETVAL"
}

case "$1" in
   start)
     start
     ;;
   stop)
     stop
     ;;
   status)
     status --lockfile "$LOCKFILE" --pidfile "$PIDFILE" --name fancontrol -- "$FANCONTROL" 
     ;;
   restart)
     stop
     start
     ;;
   condstop)
     if [ -e "$LOCKFILE" ]; then
	stop
     fi
     ;;
   condrestart)
     if [ -e "$LOCKFILE" ]; then
        restart
     fi
     ;;
   *)
     echo "Usage: ${0##*/} {start|stop|restart|condstop|condrestart|status}"
     RETVAL=1
esac

exit $RETVAL
