"Fossies" - the Fresh Open Source Software Archive

Member "lm-sensors-3-6-0/prog/init/sensord.init" (17 Oct 2019, 4318 Bytes) of package /linux/misc/lm-sensors-3-6-0.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!@BASH@
    2 #
    3 # @INITRDDIR@/sensord
    4 #
    5 # sensord       This shell script takes care of starting and stopping
    6 #               sensord, the lm_sensors hardware health monitoring daemon.
    7 #
    8 # Here is the sensors service for SysV init, based on lm_sensors-2.5.5-sensors
    9 # from Mandrake lm_sensors source RPM. It is modified according to recommendations
   10 # for RedHat initscripts. The drivers starting part is taken from alsasound
   11 # service. To configure this service one should put appropriate "alias i2c-bus-0
   12 # xxx" and "alias i2c-sensors-chip-0 xxx" in /etc/modules.conf. The rest should be
   13 # self explaining.
   14 #
   15 # You put it into /etc/rc.d/init.d/, you make a symlink (probably using
   16 # chkconfig, ntsysv, tksysv or serviceconf program) named S95xxx and K05xxx
   17 # into /etc/rc#.d (where # is the number of runlevel), and sensors service
   18 # (which starts lm_sensors modules, runs sensors -s and starts sensord)
   19 # will be started automatically at startup/reboot and stopped at shutdown.
   20 # One could also start/stop service manually.
   21 #
   22 # This service was tested for RedHat 7.2 only.
   23 # Jakub Narębski, Poland
   24 #
   25 
   26 # chkconfig: 2345 05 95
   27 # processname: sensord
   28 # config: @SYSCONFDIR@/sensors.conf
   29 # pidfile: /var/run/sensord.pid
   30 # description: Sensors is a sensors daemon which can be used to alert you \
   31 #              in the event of a hardware health monitoring alarm.
   32 
   33 # Source function library.
   34 . @INITRDDIR@/functions
   35 
   36 # Set default return value to 0 (success)
   37 RETVAL=0
   38 # Add @SBINDIR@ (sensord) and @BINDIR@ (sensors) to PATH if necessary
   39 echo "$PATH" | grep -q @SBINDIR@ || PATH=$PATH:@SBINDIR@
   40 echo "$PATH" | grep -q  @BINDIR@ || PATH=$PATH:@BINDIR@
   41 export PATH
   42 
   43 # Modules to load from modules.conf (modules configuration)
   44 i2c_bus_drivers=´modprobe -c | \
   45   awk ´/^[[:space:]]*alias[[:space:]]+i2c-bus-[[:digit:]]/ { print $3 }´´
   46 i2c_chip_drivers=´modprobe -c | \
   47   awk ´/^[[:space:]]*alias[[:space:]]+i2c-sensors-chip-[[:digit:]]/ { print $3
   48 }´´
   49 
   50 # Configuration of sensord
   51 interval=1m      # interval between scanning for sensor alarms
   52 log_interval=30m # interval between logging all sensor readings
   53 
   54 # Check that we use kernel for which lm_sensors-drivers was installed
   55 [ ´uname -r´ = @MVERSION@ ] || exit 0
   56 
   57 # Check that lm_sensors is installed.
   58 [ -x @SBINDIR@/sensord ] || exit 0
   59 [ -x  @BINDIR@/sensors ] || exit 0
   60 
   61 echo_status()
   62 {
   63         if [ $1 -eq 0 ]; then
   64                 echo_success
   65         else
   66                 echo_failure
   67         fi
   68         echo
   69 }
   70 
   71 start()
   72 {
   73         # Start modules
   74         echo "Starting I2C bus (adapter) drivers: "
   75         for driver in $i2c_bus_drivers; do
   76                 echo -n "Starting I2C driver: $driver "
   77                 /sbin/modprobe ´echo $driver´
   78                 echo_status $?
   79         done
   80         echo "Starting I2C chip (sensors) drivers: "
   81         for driver in $i2c_chip_drivers; do
   82                 echo -n "Starting I2C driver: $driver "
   83                 /sbin/modprobe $(echo $driver)
   84                 echo_status $?
   85         done
   86         # Set Alarm
   87         echo -n "Configuring sensors: "
   88         sensors -s && sleep 2
   89         echo_status $?
   90         # Start daemons.
   91         echo -n $"Starting sensord: "
   92         daemon sensord -i $interval -l $log_interval
   93         RETVAL=$?
   94 
   95         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sensord
   96 
   97         echo
   98         return $RETVAL
   99 }
  100 
  101 stop()
  102 {
  103         # Stop daemons.
  104         echo -n $"Shutting down sensord: "
  105         killproc sensord
  106         RETVAL=$?
  107 
  108         echo
  109         # Remove modules
  110         drivers=´echo "$i2c_chip_drivers $i2c_bus_drivers" | \
  111           tr -s "[:space:]\n" " "´
  112         echo -n "Removing I2C drivers: $drivers"
  113         /sbin/modprobe -r -q $drivers
  114         echo_status $?
  115 
  116         echo
  117         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sensord
  118 
  119         return $RETVAL
  120 }
  121 
  122 reload()
  123 {
  124         # Reread configuration file
  125         sensors -s
  126 
  127         return $?
  128 }
  129 
  130 # See how we were called.
  131 case "$1" in
  132   start)
  133         start
  134         ;;
  135   stop)
  136         stop
  137         ;;
  138   status)
  139         status sensord
  140         ;;
  141   restart)
  142         stop
  143         start
  144         ;;
  145   reload)
  146         reload
  147         ;;
  148   condrestart)
  149         [ -e /var/lock/subsys/sensord ] && restart || :
  150         ;;
  151   *)
  152         echo "Usage: sensord {start|stop|restart|reload|condrestart|status}"
  153         exit 1
  154         ;;
  155 esac
  156 
  157 exit $?