| 1 | #!/bin/sh |
|---|
| 2 | # |
|---|
| 3 | # chkconfig: - 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., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 20 | # MA 02110-1301 USA. |
|---|
| 21 | |
|---|
| 22 | # See also the lm_sensors homepage at: |
|---|
| 23 | # http://www.lm-sensors.org |
|---|
| 24 | |
|---|
| 25 | # It uses a config file /etc/sysconfig/lm_sensors that contains the modules |
|---|
| 26 | # to be loaded/unloaded. That file is sourced into this one. |
|---|
| 27 | |
|---|
| 28 | # The format of this file is a shell script that simply defines variables: |
|---|
| 29 | # HWMON_MODULES for hardware monitoring driver modules, and optionally |
|---|
| 30 | # BUS_MODULES for any required bus driver module (for example for I2C or SPI). |
|---|
| 31 | |
|---|
| 32 | PSENSORS=/usr/local/bin/sensors |
|---|
| 33 | |
|---|
| 34 | if [ ! -x $PSENSORS ]; then |
|---|
| 35 | PSENSORS=/usr/bin/sensors |
|---|
| 36 | fi |
|---|
| 37 | |
|---|
| 38 | # Source function library. |
|---|
| 39 | . /etc/init.d/functions |
|---|
| 40 | |
|---|
| 41 | RETVAL=0 |
|---|
| 42 | prog="lm_sensors" |
|---|
| 43 | |
|---|
| 44 | # This functions checks if sensor support is compiled into the kernel, if |
|---|
| 45 | # sensors are configured, and loads the config file |
|---|
| 46 | check_sensors() { |
|---|
| 47 | CONFIG=/etc/sysconfig/lm_sensors |
|---|
| 48 | if ! [ -r "$CONFIG" ] || ! grep '^HWMON_MODULES' $CONFIG >/dev/null 2>&1; then |
|---|
| 49 | echo -n "$1 $prog: not configured, run sensors-detect" |
|---|
| 50 | echo_warning |
|---|
| 51 | echo |
|---|
| 52 | exit 6 |
|---|
| 53 | fi |
|---|
| 54 | |
|---|
| 55 | # Load config file |
|---|
| 56 | . "$CONFIG" |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | start() { |
|---|
| 60 | check_sensors "Starting" |
|---|
| 61 | |
|---|
| 62 | echo -n "Starting $prog: loading module " |
|---|
| 63 | |
|---|
| 64 | for module in $BUS_MODULES $HWMON_MODULES ; do |
|---|
| 65 | echo -n "${module} " |
|---|
| 66 | /sbin/modprobe $module >/dev/null 2>&1 |
|---|
| 67 | done |
|---|
| 68 | $PSENSORS -s |
|---|
| 69 | |
|---|
| 70 | RETVAL=$? |
|---|
| 71 | if [ $RETVAL -eq 0 ] && touch /var/lock/subsys/lm_sensors ; then |
|---|
| 72 | echo_success |
|---|
| 73 | echo |
|---|
| 74 | else |
|---|
| 75 | echo_failure |
|---|
| 76 | echo |
|---|
| 77 | fi |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | stop() { |
|---|
| 81 | check_sensors "Stopping" |
|---|
| 82 | |
|---|
| 83 | echo -n "Stopping $prog: " |
|---|
| 84 | |
|---|
| 85 | for module in $HWMON_MODULES $BUS_MODULES ; do |
|---|
| 86 | /sbin/modprobe -r $module >/dev/null 2>&1 |
|---|
| 87 | done |
|---|
| 88 | |
|---|
| 89 | RETVAL=$? |
|---|
| 90 | if [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/lm_sensors ; then |
|---|
| 91 | echo_success |
|---|
| 92 | echo |
|---|
| 93 | else |
|---|
| 94 | echo_failure |
|---|
| 95 | echo |
|---|
| 96 | fi |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | dostatus() { |
|---|
| 100 | $PSENSORS |
|---|
| 101 | RETVAL=$? |
|---|
| 102 | if [ $RETVAL -ne 0 ]; then |
|---|
| 103 | RETVAL=3 |
|---|
| 104 | fi |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | restart() { |
|---|
| 108 | stop |
|---|
| 109 | start |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | condrestart() { |
|---|
| 113 | [ -e /var/lock/subsys/lm_sensors ] && restart || : |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | # See how we were called. |
|---|
| 117 | case "$1" in |
|---|
| 118 | start) |
|---|
| 119 | start |
|---|
| 120 | ;; |
|---|
| 121 | stop) |
|---|
| 122 | stop |
|---|
| 123 | ;; |
|---|
| 124 | status) |
|---|
| 125 | dostatus |
|---|
| 126 | ;; |
|---|
| 127 | restart|reload) |
|---|
| 128 | restart |
|---|
| 129 | ;; |
|---|
| 130 | condrestart) |
|---|
| 131 | condrestart |
|---|
| 132 | ;; |
|---|
| 133 | *) |
|---|
| 134 | echo "Usage: $0 {start|stop|status|restart|reload|condrestart}" |
|---|
| 135 | exit 3 |
|---|
| 136 | esac |
|---|
| 137 | |
|---|
| 138 | exit $RETVAL |
|---|