File: lm_sensors.init

package info (click to toggle)
lm-sensors 1%3A2.10.7-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,324 kB
  • ctags: 10,814
  • sloc: ansic: 63,969; perl: 8,111; sh: 1,823; makefile: 399; lex: 371; yacc: 312; python: 11
file content (172 lines) | stat: -rwxr-xr-x 3,805 bytes parent folder | download | duplicates (2)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/sh
#
# chkconfig: - 26 74
# description: sensors is used for monitoring motherboard sensor values.
# config: /etc/sysconfig/lm_sensors
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# See also the lm_sensors homepage at:
#     http://www.lm-sensors.org

# It uses a config file /etc/sysconfig/lm_sensors that contains the modules
# to be loaded/unloaded. That file is sourced into this one.

# The format of that file a shell script that simply defines the modules 
# in order as normal shell variables with the special names:
#    MODULE_1, MODULE_2, MODULE_3, etc.

PSENSORS=/usr/local/bin/sensors

if [ ! -x $PSENSORS ]; then
	PSENSORS=/usr/bin/sensors
fi

# Source function library.
. /etc/init.d/functions

RETVAL=0
prog="lm_sensors"

# This functions checks if sensor support is compiled into the kernel, if
# sensors are configured, and loads the config file
check_sensors() {
	if grep -q sysfs /proc/mounts; then
		WITHSYS=1
	else
		WITHSYS=0
	fi

	if [ $WITHSYS == "0" ]; then
		# If sensors isn't supported by the kernel, try loading the module...
		[ -e /proc/sys/dev/sensors ] || /sbin/modprobe i2c-proc >/dev/null 2>&1

		# Don't bother if /proc/sensors still doesn't exist, kernel doesn't have
		# support for sensors.
		if ! [ -e /proc/sys/dev/sensors ]; then
			echo -n "$1 $prog: kernel does not have sensors support"
			echo_failure
			echo
			exit 5
		fi

		# If sensors was not already running, unload the module...
		[ -e /var/lock/subsys/lm_sensors ] || /sbin/modprobe -r i2c-proc >/dev/null 2>&1
	fi

	CONFIG=/etc/sysconfig/lm_sensors
	if ! [ -r "$CONFIG" ] || ! grep '^MODULE_' $CONFIG >/dev/null 2>&1; then
		echo -n "$1 $prog: not configured, run sensors-detect"
		echo_warning
		echo
		exit 6
	fi

	# Load config file
	. "$CONFIG"
}

start() {
	check_sensors "Starting"

	echo -n "Starting $prog: loading module "

	modules=`grep \^MODULE_ $CONFIG | wc -l | tr -d ' '`
	i=0
	while [ $i -lt $modules ] ; do
		module=`eval echo '$'MODULE_$i`
		echo -n "${module} "
		/sbin/modprobe $module >/dev/null 2>&1
		i=`expr $i + 1`
	done
	$PSENSORS -s

	RETVAL=$?
	if [ $RETVAL -eq 0 ] && touch /var/lock/subsys/lm_sensors ; then
		echo_success
		echo
	else
		echo_failure
		echo
	fi
}

stop() {
	check_sensors "Stopping"

	echo -n "Stopping $prog: "

	modules=`grep \^MODULE_ $CONFIG | wc -l | tr -d ' '`
	i=`expr $modules`
	while [ $i -ge 0 ] ; do
		module=`eval echo '$'MODULE_$i`
		/sbin/modprobe -r $module >/dev/null 2>&1
		i=`expr $i - 1`
	done

	if [ $WITHSYS == "0" ]; then
		/sbin/modprobe -r i2c-proc >/dev/null 2>&1
	fi

	RETVAL=$?
	if [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/lm_sensors ; then
		echo_success
		echo
	else
		echo_failure
		echo
	fi
}

dostatus() {
	$PSENSORS
	RETVAL=$?
	if [ $RETVAL -ne 0 ]; then
		RETVAL=3
	fi
}

restart() {
	stop
	start
}

condrestart() {
	[ -e /var/lock/subsys/lm_sensors ] && restart || :
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	dostatus
	;;
  restart|reload)
	restart
	;;
  condrestart)
	condrestart
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
	exit 3
esac

exit $RETVAL