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