| 1 | #!/bin/sh |
|---|
| 2 | # |
|---|
| 3 | # chkconfig: 2345 26 74 |
|---|
| 4 | # description: sensors is used for monitoring motherboard sensor values. |
|---|
| 5 | # config: /etc/sysconfig/lm_sensors |
|---|
| 6 | # |
|---|
| 7 | # This program is free software; you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program; if not, write to the Free Software |
|---|
| 19 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 20 | |
|---|
| 21 | # See also the lm_sensors homepage at: |
|---|
| 22 | # http://www.lm-sensors.org |
|---|
| 23 | |
|---|
| 24 | # It uses a config file /etc/sysconfig/lm_sensors that contains the modules |
|---|
| 25 | # to be loaded/unloaded. That file is sourced into this one. |
|---|
| 26 | |
|---|
| 27 | # The format of that file a shell script that simply defines the modules |
|---|
| 28 | # in order as normal shell variables with the special names: |
|---|
| 29 | # MODULE_1, MODULE_2, MODULE_3, etc. |
|---|
| 30 | |
|---|
| 31 | if grep -q sysfs /proc/mounts; then |
|---|
| 32 | WITHSYS=1 |
|---|
| 33 | else |
|---|
| 34 | WITHSYS=0 |
|---|
| 35 | fi |
|---|
| 36 | |
|---|
| 37 | if [ $WITHSYS == "0" ]; then |
|---|
| 38 | # If sensors isn't supported by the kernel, try loading the module... |
|---|
| 39 | [ -e /proc/sys/dev/sensors ] || /sbin/modprobe i2c-proc >/dev/null 2>&1 |
|---|
| 40 | |
|---|
| 41 | # Don't bother if /proc/sensors still doesn't exist, kernel doesn't have |
|---|
| 42 | # support for sensors. |
|---|
| 43 | [ -e /proc/sys/dev/sensors ] || exit 0 |
|---|
| 44 | |
|---|
| 45 | # If sensors was not already running, unload the module... |
|---|
| 46 | [ -e /var/lock/subsys/lm_sensors ] || /sbin/modprobe -r i2c-proc >/dev/null 2>&1 |
|---|
| 47 | fi |
|---|
| 48 | |
|---|
| 49 | CONFIG=/etc/sysconfig/lm_sensors |
|---|
| 50 | [ -r "$CONFIG" ] || exit 0 |
|---|
| 51 | grep '^MODULE_' $CONFIG >/dev/null 2>&1 || exit 0 |
|---|
| 52 | |
|---|
| 53 | # Load config file |
|---|
| 54 | . "$CONFIG" |
|---|
| 55 | |
|---|
| 56 | PSENSORS=/usr/local/bin/sensors |
|---|
| 57 | |
|---|
| 58 | if [ ! -x $PSENSORS ]; then |
|---|
| 59 | PSENSORS=/usr/bin/sensors |
|---|
| 60 | fi |
|---|
| 61 | |
|---|
| 62 | # Source function library. |
|---|
| 63 | . /etc/init.d/functions |
|---|
| 64 | |
|---|
| 65 | RETVAL=0 |
|---|
| 66 | prog="lm_sensors" |
|---|
| 67 | |
|---|
| 68 | start() { |
|---|
| 69 | echo -n "Starting $prog: loading module " |
|---|
| 70 | |
|---|
| 71 | modules=`grep \^MODULE_ $CONFIG | wc -l | tr -d ' '` |
|---|
| 72 | i=0 |
|---|
| 73 | while [ $i -lt $modules ] ; do |
|---|
| 74 | module=`eval echo '$'MODULE_$i` |
|---|
| 75 | echo -n "${module} " |
|---|
| 76 | /sbin/modprobe $module >/dev/null 2>&1 |
|---|
| 77 | i=`expr $i + 1` |
|---|
| 78 | done |
|---|
| 79 | $PSENSORS -s |
|---|
| 80 | |
|---|
| 81 | RETVAL=$? |
|---|
| 82 | if [ $RETVAL -eq 0 ] && touch /var/lock/subsys/lm_sensors ; then |
|---|
| 83 | echo_success |
|---|
| 84 | echo |
|---|
| 85 | else |
|---|
| 86 | echo_failure |
|---|
| 87 | echo |
|---|
| 88 | fi |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | stop() { |
|---|
| 92 | echo -n "Stopping $prog: " |
|---|
| 93 | |
|---|
| 94 | modules=`grep \^MODULE_ $CONFIG | wc -l | tr -d ' '` |
|---|
| 95 | i=`expr $modules` |
|---|
| 96 | while [ $i -ge 0 ] ; do |
|---|
| 97 | module=`eval echo '$'MODULE_$i` |
|---|
| 98 | /sbin/modprobe -r $module >/dev/null 2>&1 |
|---|
| 99 | i=`expr $i - 1` |
|---|
| 100 | done |
|---|
| 101 | |
|---|
| 102 | if [ $WITHSYS == "0" ]; then |
|---|
| 103 | /sbin/modprobe -r i2c-proc >/dev/null 2>&1 |
|---|
| 104 | fi |
|---|
| 105 | |
|---|
| 106 | RETVAL=$? |
|---|
| 107 | if [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/lm_sensors ; then |
|---|
| 108 | echo_success |
|---|
| 109 | echo |
|---|
| 110 | else |
|---|
| 111 | echo_failure |
|---|
| 112 | echo |
|---|
| 113 | fi |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | dostatus() { |
|---|
| 117 | $PSENSORS |
|---|
| 118 | RETVAL=$? |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | restart() { |
|---|
| 122 | stop |
|---|
| 123 | start |
|---|
| 124 | RETVAL=$? |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | condrestart() { |
|---|
| 128 | [ -e /var/lock/subsys/lm_sensors ] && restart || : |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | # See how we were called. |
|---|
| 132 | case "$1" in |
|---|
| 133 | start) |
|---|
| 134 | start |
|---|
| 135 | ;; |
|---|
| 136 | stop) |
|---|
| 137 | stop |
|---|
| 138 | ;; |
|---|
| 139 | status) |
|---|
| 140 | dostatus |
|---|
| 141 | ;; |
|---|
| 142 | restart|reload) |
|---|
| 143 | restart |
|---|
| 144 | ;; |
|---|
| 145 | condrestart) |
|---|
| 146 | condrestart |
|---|
| 147 | ;; |
|---|
| 148 | *) |
|---|
| 149 | echo "Usage: $0 {start|stop|status|restart|reload|condrestart}" |
|---|
| 150 | exit 1 |
|---|
| 151 | esac |
|---|
| 152 | |
|---|
| 153 | exit $RETVAL |
|---|