]>
Commit | Line | Data |
---|---|---|
832b75ed GG |
1 | #! /bin/sh |
2 | ||
3 | # smartmontools init file for smartd | |
4 | # Copyright (C) 2002-6 Bruce Allen <smartmontools-support@lists.sourceforge.net> | |
5 | # $Id: smartd.initd.in,v 1.33 2006/04/12 14:54:28 ballen4705 Exp $ | |
6 | ||
7 | # For RedHat and cousins: | |
8 | # chkconfig: 2345 40 40 | |
9 | # description: Self Monitoring and Reporting Technology (SMART) Daemon | |
10 | # processname: smartd | |
11 | ||
12 | # For SuSE and cousins | |
13 | ### BEGIN INIT INFO | |
14 | # Provides: smartd | |
15 | # Required-Start: $syslog | |
16 | # X-UnitedLinux-Should-Start: $sendmail | |
17 | # Required-Stop: $syslog | |
18 | # X-UnitedLinux-Should-Stop: | |
19 | # Default-Start: 2 3 5 | |
20 | # Default-Stop: | |
21 | # Short-Description: Monitors disk and tape health via S.M.A.R.T. | |
22 | # Description: Start S.M.A.R.T. disk and tape monitor. | |
23 | ### END INIT INFO | |
24 | ||
25 | # This program is free software; you can redistribute it and/or modify it | |
26 | # under the terms of the GNU General Public License as published by the Free | |
27 | # Software Foundation; either version 2, or (at your option) any later | |
28 | # version. | |
29 | # You should have received a copy of the GNU General Public License (for | |
30 | # example COPYING); if not, write to the Free Software Foundation, Inc., 675 | |
31 | # Mass Ave, Cambridge, MA 02139, USA. | |
32 | # This code was originally developed as a Senior Thesis by Michael Cornwell | |
33 | # at the Concurrent Systems Laboratory (now part of the Storage Systems | |
34 | # Research Center), Jack Baskin School of Engineering, University of | |
35 | # California, Santa Cruz. http://ssrc.soe.ucsc.edu/. | |
36 | ||
37 | # Uncomment the line below to pass options to smartd on startup. | |
38 | # Note that distribution specific configuration files like | |
39 | # /etc/{default,sysconfig}/smartmontools might override these | |
40 | #smartd_opts="--interval=1800" | |
41 | ||
42 | SMARTD_BIN=/usr/local/sbin/smartd | |
43 | ||
44 | report_unsupported () { | |
45 | echo "Currently the smartmontools package has no init script for" | |
46 | echo "the $1 OS/distribution. If you can provide one or this" | |
47 | echo "one works after removing some ifdefs, please contact" | |
48 | echo "smartmontools-support@lists.sourceforge.net." | |
49 | exit 1 | |
50 | } | |
51 | ||
52 | # Red Hat or Yellow Dog or Mandrake | |
53 | if [ -f /etc/redhat-release -o -f /etc/yellowdog-release -o -f /etc/mandrake-release -o -f /etc/whitebox-release -o -f /etc/trustix-release -o -f /etc/tinysofa-release ] ; then | |
54 | ||
55 | # Source function library | |
56 | . /etc/rc.d/init.d/functions | |
57 | ||
58 | # Source configuration file. This should define the shell variable smartd_opts | |
59 | [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools | |
60 | ||
61 | RETVAL=0 | |
62 | ||
63 | prog=smartd | |
64 | ||
65 | case "$1" in | |
66 | start) | |
67 | echo -n $"Starting $prog: " | |
68 | daemon $SMARTD_BIN $smartd_opts | |
69 | touch /var/lock/subsys/smartd | |
70 | echo | |
71 | ;; | |
72 | stop) | |
73 | echo -n $"Shutting down $prog: " | |
74 | killproc $SMARTD_BIN | |
75 | rm -f /var/lock/subsys/smartd | |
76 | echo | |
77 | ;; | |
78 | reload) | |
79 | echo -n $"Reloading $prog daemon configuration: " | |
80 | killproc $SMARTD_BIN -HUP | |
81 | RETVAL=$? | |
82 | echo | |
83 | ;; | |
84 | report) | |
85 | echo -n $"Checking SMART devices now: " | |
86 | killproc $SMARTD_BIN -USR1 | |
87 | RETVAL=$? | |
88 | echo | |
89 | ;; | |
90 | restart) | |
91 | $0 stop | |
92 | $0 start | |
93 | ;; | |
94 | status) | |
95 | status $prog | |
96 | ;; | |
97 | *) | |
98 | echo $"Usage: $0 {start|stop|reload|report|restart|status}" | |
99 | RETVAL=1 | |
100 | esac | |
101 | ||
102 | exit $RETVAL | |
103 | ||
104 | # Slackware | |
105 | elif [ -f /etc/slackware-version ] ; then | |
106 | ||
107 | # Source configuration file. This should define the shell variable smartd_opts. | |
108 | # Email smartmontools-support@lists.sourceforge.net if there is a better choice | |
109 | # of path for Slackware. | |
110 | ||
111 | [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools | |
112 | ||
113 | case "$1" in | |
114 | start) | |
115 | echo -n "Starting smartd: " | |
116 | $SMARTD_BIN $smartd_opts | |
117 | echo | |
118 | ;; | |
119 | stop) | |
120 | echo -n "Shutting down smartd: " | |
121 | killall $SMARTD_BIN | |
122 | echo | |
123 | ;; | |
124 | restart) | |
125 | $0 stop | |
126 | sleep 1 | |
127 | $0 start | |
128 | ;; | |
129 | *) | |
130 | echo "Usage: smartd {start|stop|restart}" | |
131 | exit 1 | |
132 | esac | |
133 | ||
134 | exit 0 | |
135 | ||
136 | # SuSE | |
137 | elif [ -f /etc/SuSE-release ] ; then | |
138 | test -x $SMARTD_BIN || exit 5 | |
139 | ||
140 | # Existence of config file is optional | |
141 | SMARTD_CONFIG=/etc/smartd.conf | |
142 | ||
143 | # source configuration file. This should set the shell variable smartd_opts | |
144 | [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools | |
145 | ||
146 | # Shell functions sourced from /etc/rc.status: | |
147 | # rc_check check and set local and overall rc status | |
148 | # rc_status check and set local and overall rc status | |
149 | # rc_status -v ditto but be verbose in local rc status | |
150 | # rc_status -v -r ditto and clear the local rc status | |
151 | # rc_failed set local and overall rc status to failed | |
152 | # rc_reset clear local rc status (overall remains) | |
153 | # rc_exit exit appropriate to overall rc status | |
154 | . /etc/rc.status | |
155 | ||
156 | # First reset status of this service | |
157 | rc_reset | |
158 | ||
159 | # Return values acc. to LSB for all commands but status: | |
160 | # 0 - success | |
161 | # 1 - misc error | |
162 | # 2 - invalid or excess args | |
163 | # 3 - unimplemented feature (e.g. reload) | |
164 | # 4 - insufficient privilege | |
165 | # 5 - program not installed | |
166 | # 6 - program not configured | |
167 | # | |
168 | # Note that starting an already running service, stopping | |
169 | # or restarting a not-running service as well as the restart | |
170 | # with force-reload (in case signalling is not supported) are | |
171 | # considered a success. | |
172 | case "$1" in | |
173 | start) | |
174 | echo -n "Starting smartd" | |
175 | ## Start daemon with startproc(8). If this fails | |
176 | ## the echo return value is set appropriate. | |
177 | ||
178 | # startproc should return 0, even if service is | |
179 | # already running to match LSB spec. | |
180 | startproc $SMARTD_BIN $smartd_opts | |
181 | ||
182 | # Remember status and be verbose | |
183 | rc_status -v | |
184 | ;; | |
185 | stop) | |
186 | echo -n "Shutting down smartd" | |
187 | killproc -TERM $SMARTD_BIN | |
188 | ||
189 | # Remember status and be verbose | |
190 | rc_status -v | |
191 | ;; | |
192 | restart | force-reload) | |
193 | $0 stop | |
194 | $0 start | |
195 | ;; | |
196 | reload) | |
197 | ## Like force-reload, but if daemon does not support | |
198 | ## signaling, do nothing (!) | |
199 | rc_failed 3 | |
200 | rc_status -v | |
201 | ;; | |
202 | status) | |
203 | echo -n "Checking for service smartd: " | |
204 | ## Check status with checkproc(8), if process is running | |
205 | ## checkproc will return with exit status 0. | |
206 | ||
207 | # Status has a slightly different for the status command: | |
208 | # 0 - service running | |
209 | # 1 - service dead, but /var/run/ pid file exists | |
210 | # 2 - service dead, but /var/lock/ lock file exists | |
211 | # 3 - service not running | |
212 | ||
213 | # NOTE: checkproc returns LSB compliant status values. | |
214 | checkproc $SMARTD_BIN | |
215 | rc_status -v | |
216 | ;; | |
217 | probe) | |
218 | ## Optional: Probe for the necessity of a reload, print out the | |
219 | ## argument to this init script which is required for a reload. | |
220 | ## Note: probe is not (yet) part of LSB (as of 1.2) | |
221 | ||
222 | test $SMARTD_CONFIG -nt /var/run/smartd.pid && echo reload | |
223 | ;; | |
224 | *) | |
225 | echo "Usage: $0 {start|stop|status|restart|force-reload|reload|probe}" | |
226 | exit 1 | |
227 | ;; | |
228 | esac | |
229 | ||
230 | rc_exit | |
231 | ||
232 | # Debian case | |
233 | elif [ -f /etc/debian_version ] ; then | |
234 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
235 | SMARTDPID=/var/run/smartd.pid | |
236 | [ -x $SMARTD_BIN ] || exit 0 | |
237 | RET=0 | |
238 | ||
239 | # source configuration file | |
240 | [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools | |
241 | ||
242 | smartd_opts="--pidfile $SMARTDPID $smartd_opts" | |
243 | ||
244 | case "$1" in | |
245 | start) | |
246 | echo -n "Starting S.M.A.R.T. daemon: smartd" | |
247 | if start-stop-daemon --start --quiet --pidfile $SMARTDPID \ | |
248 | --exec $SMARTD_BIN -- $smartd_opts; then | |
249 | echo "." | |
250 | else | |
251 | echo " (failed)" | |
252 | RET=1 | |
253 | fi | |
254 | ;; | |
255 | stop) | |
256 | echo -n "Stopping S.M.A.R.T. daemon: smartd" | |
257 | start-stop-daemon --stop --quiet --oknodo --pidfile $SMARTDPID | |
258 | echo "." | |
259 | ;; | |
260 | restart|force-reload) | |
261 | $0 stop | |
262 | $0 start | |
263 | ;; | |
264 | *) | |
265 | echo "Usage: /etc/init.d/smartmontools {start|stop|restart|force-reload}" | |
266 | exit 1 | |
267 | esac | |
268 | exit $RET | |
269 | ||
270 | elif [ -f /etc/gentoo-release ] ; then | |
271 | report_unsupported "Gentoo" | |
272 | ||
273 | elif [ -f /etc/turbolinux-release ] ; then | |
274 | report_unsupported "Turbolinux" | |
275 | ||
276 | elif [ -f /etc/environment.corel ] ; then | |
277 | report_unsupported "Corel" | |
278 | ||
279 | # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif | |
280 | ||
281 | elif uname -a | grep FreeBSD > /dev/null 2>&1 ; then | |
282 | # following is replaced by port install | |
283 | PREFIX=@@PREFIX@@ | |
284 | ||
285 | # Updated to try both the RCNG version of things from 5.x, or fallback to | |
286 | # oldfashioned rc.conf | |
287 | ||
288 | if [ -r /etc/rc.subr ]; then | |
289 | # This is RC-NG, pick up our values | |
290 | . /etc/rc.subr | |
291 | name="smartd" | |
292 | rcvar="smartd_enable" | |
293 | command="$SMARTD_BIN" | |
294 | load_rc_config $name | |
295 | elif [ -r /etc/defaults/rc.conf ]; then | |
296 | # Not a 5.x system, try the default location for variables | |
297 | . /etc/defaults/rc.conf | |
298 | source_rc_confs | |
299 | elif [ -r /etc/rc.conf ]; then | |
300 | # Worst case, fallback to system config file | |
301 | . /etc/rc.conf | |
302 | fi | |
303 | ||
304 | if [ -r /etc/rc.subr ]; then | |
305 | # Use new functionality from RC-NG | |
306 | run_rc_command "$1" | |
307 | else | |
308 | PID_FILE=/var/run/smartd.pid | |
309 | case "$1" in | |
310 | start) | |
311 | $SMARTD_BIN -p $PID_FILE $smartd_flags | |
312 | echo -n " smartd" | |
313 | ;; | |
314 | stop) | |
315 | kill `cat $PID_FILE` | |
316 | echo -n " smartd" | |
317 | ;; | |
318 | restart) | |
319 | $0 stop | |
320 | sleep 1 | |
321 | $0 start | |
322 | ;; | |
323 | *) | |
324 | echo "Usage: smartd {start|stop|restart}" | |
325 | exit 1 | |
326 | esac | |
327 | ||
328 | exit 0 | |
329 | fi | |
330 | elif uname -a | grep SunOS > /dev/null 2>&1 ; then | |
331 | ||
332 | # Source configuration file. This should define the shell variable smartd_opts. | |
333 | # Email smartmontools-support@lists.sourceforge.net if there is a better choice | |
334 | # of path for Solaris | |
335 | ||
336 | [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools | |
337 | ||
338 | PID_FILE=/var/run/smartd.pid | |
339 | ||
340 | case "$1" in | |
341 | start) | |
342 | $SMARTD_BIN -p $PID_FILE $smartd_opts | |
343 | echo -n "smartd " | |
344 | ;; | |
345 | stop) | |
346 | [ -f $PID_FILE ] && kill `cat $PID_FILE` | |
347 | echo -n "smartd " | |
348 | ;; | |
349 | restart) | |
350 | $0 stop | |
351 | sleep 1 | |
352 | $0 start | |
353 | ;; | |
354 | *) | |
355 | echo "Usage: smartd {start|stop|restart}" | |
356 | exit 1 | |
357 | esac | |
358 | ||
359 | exit 0 | |
360 | ||
361 | # Cygwin | |
362 | elif uname | grep -i CYGWIN > /dev/null 2>&1 ; then | |
363 | ||
364 | # The following settings may be changed by the configuration file below | |
365 | # Service Name (must be unique) | |
366 | smartd_svcname=smartd | |
367 | # Service display name | |
368 | smartd_svcdisp="CYGWIN smartd" | |
369 | # Service description | |
370 | smartd_svcdesc="\ | |
371 | Controls and monitors storage devices using the Self-Monitoring \ | |
372 | Analysis and Reporting Technology System (S.M.A.R.T.) \ | |
373 | built into ATA and SCSI Hard Drives. \ | |
374 | http://smartmontools.sourceforge.net/" | |
375 | ||
376 | # Source configuration file. This should define the shell variable smartd_opts. | |
377 | # Email smartmontools-support@lists.sourceforge.net if there is a better choice | |
378 | # of path for Cygwin | |
379 | ||
380 | [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools | |
381 | ||
382 | PID_FILE=/var/run/smartd.pid | |
383 | RETVAL=0 | |
384 | ||
385 | # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may | |
386 | # return success even if the file is present but cannot be read by current user. | |
387 | # If smartd is running as service, smartd.pid is owned by local system account | |
388 | # which is different from any user ever executing this script. | |
389 | ||
390 | case "$1" in | |
391 | start) | |
392 | if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then | |
393 | echo -n "Starting service $smartd_svcname: " | |
394 | cygrunsrv -S "$smartd_svcname" | |
395 | else | |
396 | echo -n "Starting smartd as daemon: " | |
397 | $SMARTD_BIN -p $PID_FILE $smartd_opts | |
398 | fi | |
399 | RETVAL=$? | |
400 | ;; | |
401 | stop) | |
402 | echo -n "Shutting down smartd: " | |
403 | pid="`cat $PID_FILE 2>/dev/null`" && kill "$pid" | |
404 | RETVAL=$? | |
405 | ;; | |
406 | reload) | |
407 | echo -n "Reloading smartd configuration: " | |
408 | pid="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid" | |
409 | RETVAL=$? | |
410 | ;; | |
411 | report) | |
412 | echo -n "Checking SMART devices now: " | |
413 | pid="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid" | |
414 | RETVAL=$? | |
415 | ;; | |
416 | restart) | |
417 | $0 stop | |
418 | sleep 1 | |
419 | $0 start | |
420 | exit $? | |
421 | ;; | |
422 | install) | |
423 | shift | |
424 | [ $# -eq 0 ] || smartd_opts="$*" | |
425 | dep= | |
426 | if cygrunsrv -L 2>/dev/null | grep "^syslogd$" >/dev/null 2>&1; then | |
427 | dep="-y syslogd" | |
428 | else | |
429 | echo "Warning: syslogd service not installed, smartd will write to windows event log."; | |
430 | fi | |
431 | echo "Installing service ${smartd_svcname}${smartd_opts+ with options '$smartd_opts'}:" | |
432 | cygrunsrv -I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" $dep \ | |
433 | -e CYGWIN="$CYGWIN" -p $SMARTD_BIN -a "--service -p ${PID_FILE}${smartd_opts+ }$smartd_opts" | |
434 | RETVAL=$? | |
435 | ;; | |
436 | remove) | |
437 | echo "Removing service $smartd_svcname:" | |
438 | cygrunsrv -R "$smartd_svcname" | |
439 | RETVAL=$? | |
440 | ;; | |
441 | status) | |
442 | echo -n "Checking smartd status: " | |
443 | if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then | |
444 | if cygrunsrv -Q "$smartd_svcname" 2>/dev/null | grep "State *: Running" >/dev/null 2>&1; then | |
445 | echo "running as service '$smartd_svcname'." | |
446 | elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then | |
447 | echo "installed as service '$smartd_svcname' but running as daemon." | |
448 | else | |
449 | echo "installed as service '$smartd_svcname' but not running." | |
450 | RETVAL=1 | |
451 | fi | |
452 | elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then | |
453 | echo "running as daemon." | |
454 | else | |
455 | echo "not running." | |
456 | RETVAL=1 | |
457 | fi | |
458 | exit $RETVAL | |
459 | ;; | |
460 | *) | |
461 | echo "Usage: $0 {start|stop|restart|reload|report|status}" | |
462 | echo " $0 {install [options]|remove}" | |
463 | exit 1 | |
464 | esac | |
465 | ||
466 | if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi | |
467 | exit $RETVAL | |
468 | ||
469 | # Add other OSes HERE, using elif... | |
470 | else | |
471 | report_unsupported "Unknown" | |
472 | fi | |
473 | ||
474 | # One should NEVER arrive here, except for a badly written case above, | |
475 | # that fails to exit. | |
476 | echo "SOMETHING IS WRONG WITH THE SMARTD STARTUP SCRIPT" | |
477 | echo "PLEASE CONTACT smartmontools-support@lists.sourceforge.net" | |
478 | exit 1 |