]> git.pld-linux.org Git - packages/lm_sensors.git/blobdiff - fancontrol.init
exec binary with full path, use redirfds
[packages/lm_sensors.git] / fancontrol.init
old mode 100644 (file)
new mode 100755 (executable)
index cfefcc5..e77b23e
@@ -1,93 +1,98 @@
 #!/bin/sh
 #
-# fancontrol   fancontrol short service description
+# fancontrol   Fans speed control according to temperature service
 #
-# chkconfig:   345 <start_level> <stop_level>
+# Starts after all hotplug-like things, which could load proper drivers
+# for fans and dies last possible
+# chkconfig:   345 09 99
 #
-# description: fancontrol long service description
-#
-# $Id$
+# description: It is crucial to proper configure this service, or severe
+#              damadge could occur. For this, be sure, to run init first
+#              and be sure the configuration is correct.
 #
 # TODO:
-# - find out, if it should be dependant of sensors deamon
 # - check this, case this is my first 'advanced' init script
-# - register proper start and stop levels
-# - describe that
+# - maybe add some more stop control, like re-running fancontrol and killing
+#   it once more, if killproc fails
 #
 
 # Source function library
 . /etc/rc.d/init.d/functions
 
-# Get service config - may override defaults
-# [ -f /etc/sysconfig/fancontrol ] && . /etc/sysconfig/fancontrol
+# Get service config
+ [ -f /etc/sysconfig/fancontrol ] && . /etc/sysconfig/fancontrol
 
-# See how we were called.
-case "$1" in
-  start)
-       # Fancontrol needs to check system for pwm control
+start() {
+       # sensors deamon needs to be started
+       # or at least proper modules loaded (provided by sensorsd deamon)
+       if [ ! -f /var/lock/subsys/sensord ]; then
+               echo "Start sensors daemon first"
+               RETVAL=1
+               return
+       fi
+
+       # Check if the service is already running?
+       if [ -f /var/lock/subsys/fancontrol ]; then
+               msg_already_running fancontrol
+               return
+       fi
+
+       # Fancontrol needs to check system for pwm control
        if [ ! -f /etc/sysconfig/fancontrol ]; then
                nls "Fancontrol not initialized."
                nls "Try \`%s init' before start." "$0"
                exit 6
        fi
-       # Check if the service is already running?
+
+       msg_starting fancontrol
+       # won't start without an output
+       daemon --fork --redirfds /usr/sbin/fancontrol
+       RETVAL=$?
+       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/fancontrol
+}
+
+stop() {
        if [ ! -f /var/lock/subsys/fancontrol ]; then
-               msg_starting fancontrol
-               daemon fancontrol
-               RETVAL=$?
-               [ $RETVAL -eq 0 ] && touch /var/lock/subsys/fancontrol
-       else
-               msg_already_running fancontrol
+               msg_not_running fancontrol
+               return
        fi
+
+       # Stop daemons.
+       msg_stopping fancontrol
+       # it's crucial to be sure it ended ok, otherwise we get
+       # the fans set and the computer working without any control
+       # and that could cause MASSIVE damage
+       killproc --waitforname fancontrol --waitfortime 30 fancontrol -TERM
+       rm -f /var/lock/subsys/fancontrol
+}
+
+restart() {
+       stop
+       start
+}
+
+# See how we were called.
+case "$1" in
+  start)
+       start
        ;;
   stop)
-       if [ -f /var/lock/subsys/fancontrol ]; then
-               # Stop daemons.
-               msg_stopping fancontrol
-               killproc fancontrol
-               rm -f /var/lock/subsys/fancontrol
-       else
-               msg_not_running fancontrol
-       fi
+       stop
        ;;
   restart)
-       $0 stop
-       $0 start
-       exit $?
+       restart
        ;;
-  reload)
-       if [ -f /var/lock/subsys/fancontrol ]; then
-               msg_reloading fancontrol
-               killproc fancontrol -HUP
-               RETVAL=$?
-       else
-               msg_not_running fancontrol >&2
-               RETVAL=7
-       fi
-       ;;
-  force-reload)
-       # if program allows reloading without stopping
-       $0 reload
-
-       # or if it doesn't
-       $0 restart
-
+  init)
+       pwmconfig
        exit $?
        ;;
-  init)
-       pwmconfig
-       exit $?
-       ;;
   status)
        status fancontrol
        RETVAL=$?
        ;;
   *)
-       msg_usage "$0 {start|stop|restart|reload|force-reload|status|init}"
+       msg_usage "$0 {start|stop|restart|init|status}"
        exit 3
 esac
 
 exit $RETVAL
-
-# This must be last line !
-# vi:syntax=sh
This page took 0.071949 seconds and 4 git commands to generate.