root/lm-sensors/trunk/prog/init/sensord.init

Revision 2777, 4.2 KB (checked in by mds, 7 years ago)

rename lockfile to sensord to match filename. ticket 1806

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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)
37RETVAL=0
38# Add @SBINDIR@ (sensord) and @BINDIR@ (sensors) to PATH if necessary
39echo "$PATH" | grep -q @SBINDIR@ || PATH=$PATH:@SBINDIR@
40echo "$PATH" | grep -q  @BINDIR@ || PATH=$PATH:@BINDIR@
41export PATH
42
43# Modules to load from modules.conf (modules configuration)
44i2c_bus_drivers=Žmodprobe -c | \
45  awk Ž/^[[:space:]]*alias[[:space:]]+i2c-bus-[[:digit:]]/ { print $3 }ŽŽ
46i2c_chip_drivers=Žmodprobe -c | \
47  awk Ž/^[[:space:]]*alias[[:space:]]+i2c-sensors-chip-[[:digit:]]/ { print $3
48}ŽŽ
49
50# Configuration of sensord
51interval=1m      # interval between scanning for sensor alarms
52log_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
61echo_status()
62{
63        if [ $1 -eq 0 ]; then
64                echo_success
65        else
66                echo_failure
67        fi
68        echo
69}
70
71start()
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
101stop()
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
122reload()
123{
124        # Reread configuration file
125        sensors -s
126
127        return $?
128}
129
130# See how we were called.
131case "$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        ;;
155esac
156
157exit $?
Note: See TracBrowser for help on using the browser.