Annotation of embedaddon/smartmontools/smartd.initd.in, revision 1.1.1.1
1.1 misho 1: #! /bin/sh
2:
3: # smartmontools init file for smartd
4: # Copyright (C) 2002-8 Bruce Allen <smartmontools-support@lists.sourceforge.net>
5: # $Id: smartd.initd.in 3360 2011-06-06 19:25:36Z chrfranke $
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 $remote_fs
16: # Should-Start: sendmail
17: # Required-Stop: $syslog $remote_fs
18: # Should-Stop: sendmail
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: pidfile=/var/lock/subsys/smartd
65: config=/etc/smartd.conf
66:
67: start()
68: {
69: [ $UID -eq 0 ] || exit 4
70: [ -x $SMARTD_BIN ] || exit 5
71: [ -f $config ] || exit 6
72: echo -n $"Starting $prog: "
73: daemon $SMARTD_BIN $smartd_opts
74: RETVAL=$?
75: echo
76: [ $RETVAL = 0 ] && touch $pidfile
77: return $RETVAL
78: }
79:
80: stop()
81: {
82: [ $UID -eq 0 ] || exit 4
83: echo -n $"Shutting down $prog: "
84: killproc $SMARTD_BIN
85: RETVAL=$?
86: echo
87: rm -f $pidfile
88: return $RETVAL
89: }
90:
91: reload()
92: {
93: echo -n $"Reloading $prog daemon configuration: "
94: killproc $SMARTD_BIN -HUP
95: RETVAL=$?
96: echo
97: return $RETVAL
98: }
99:
100: report()
101: {
102: echo -n $"Checking SMART devices now: "
103: killproc $SMARTD_BIN -USR1
104: RETVAL=$?
105: echo
106: return $RETVAL
107: }
108:
109: case "$1" in
110: start)
111: start
112: ;;
113: stop)
114: stop
115: ;;
116: reload)
117: reload
118: ;;
119: report)
120: report
121: ;;
122: restart)
123: stop
124: start
125: ;;
126: condrestart|try-restart)
127: if [ -f $pidfile ]; then
128: stop
129: start
130: fi
131: ;;
132: force-reload)
133: reload || (stop; start)
134: ;;
135: status)
136: status $prog
137: RETVAL=$?
138: ;;
139: *)
140: echo $"Usage: $0 {start|stop|restart|status|condrestart|try-restart|reload|force-reload|report}"
141: RETVAL=2
142: [ "$1" = 'usage' ] && RETVAL=0
143: esac
144: exit $RETVAL
145:
146: # Slackware
147: elif [ -f /etc/slackware-version ] ; then
148:
149: # Source configuration file. This should define the shell variable smartd_opts.
150: # Email smartmontools-support@lists.sourceforge.net if there is a better choice
151: # of path for Slackware.
152:
153: [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
154:
155: RETVAL=0
156: case "$1" in
157: start)
158: echo -n "Starting smartd: "
159: $SMARTD_BIN $smartd_opts
160: RETVAL=$?
161: echo
162: ;;
163: stop)
164: echo -n "Shutting down smartd: "
165: killall $SMARTD_BIN
166: RETVAL=$?
167: echo
168: ;;
169: restart)
170: $0 stop
171: sleep 1
172: $0 start
173: RETVAL=$?
174: ;;
175: try-restart)
176: if pidof $SMARTD_BIN >/dev/null; then
177: $0 restart
178: RETVAL=$?
179: fi
180: ;;
181: force-reload)
182: $0 reload || $0 restart
183: RETVAL=$?
184: ;;
185: reload)
186: echo -n "Reloading smartd configuration: "
187: killall -s HUP $SMARTD_BIN
188: RETVAL=$?
189: echo
190: ;;
191: report)
192: echo -n "Checking SMART devices now: "
193: killall -s USR1 $SMARTD_BIN
194: RETVAL=$?
195: echo
196: ;;
197: status)
198: if pidof $SMARTD_BIN >/dev/null; then
199: echo "$SMARTD_BIN is running."
200: else
201: echo "$SMARTD_BIN is not running."
202: RETVAL=1
203: fi
204: ;;
205: *)
206: echo "Usage: $0 {start|stop|restart|try-restart|force-reload|reload|report|status}"
207: RETVAL=1
208: esac
209: exit $RETVAL
210:
211: # SuSE
212: elif [ -f /etc/SuSE-release ] ; then
213: test -x $SMARTD_BIN || exit 5
214:
215: # Existence of config file is optional
216: SMARTD_CONFIG=/etc/smartd.conf
217:
218: # source configuration file.
219: [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
220: smartd_opts=
221: if test -n "$SMARTD_CHECK_INTERVAL" -a "$SMARTD_CHECK_INTERVAL" != 1800 ; then
222: smartd_opts=" -i $SMARTD_CHECK_INTERVAL"
223: fi
224: if test -n "$SMARTD_LOG_FACILITY" -a "$SMARTD_LOG_FACILITY" != "daemon" ; then
225: smartd_opts="$smartd_opts -l $SMARTD_LOG_FACILITY"
226: fi
227: if test -n "$SMARTD_DRIVEDB" ; then
228: smartd_opts="$smartd_opts -B $SMARTD_DRIVEDB"
229: fi
230:
231: # Shell functions sourced from /etc/rc.status:
232: # rc_check check and set local and overall rc status
233: # rc_status check and set local and overall rc status
234: # rc_status -v be verbose in local rc status and clear it afterwards
235: # rc_status -v -r ditto and clear both the local and overall rc status
236: # rc_status -s display "skipped" and exit with status 3
237: # rc_status -u display "unused" and exit with status 3
238: # rc_failed set local and overall rc status to failed
239: # rc_failed <num> set local and overall rc status to <num>
240: # rc_reset clear both the local and overall rc status
241: # rc_exit exit appropriate to overall rc status
242: # rc_active checks whether a service is activated by symlinks
243: . /etc/rc.status
244:
245: # Reset status of this service
246: rc_reset
247:
248: # Return values acc. to LSB for all commands but status:
249: # 0 - success
250: # 1 - generic or unspecified error
251: # 2 - invalid or excess argument(s)
252: # 3 - unimplemented feature (e.g. "reload")
253: # 4 - user had insufficient privileges
254: # 5 - program is not installed
255: # 6 - program is not configured
256: # 7 - program is not running
257: # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
258: #
259: # Note that starting an already running service, stopping
260: # or restarting a not-running service as well as the restart
261: # with force-reload (in case signaling is not supported) are
262: # considered a success.
263:
264: case "$1" in
265: start)
266: echo -n "Starting smartd "
267: ## Start daemon with startproc(8). If this fails
268: ## the return value is set appropriately by startproc.
269:
270: # We don't use startproc - we need to check for return code 17.
271: if ! /sbin/checkproc $SMARTD_BIN ; then
272: $SMARTD_BIN $smartd_opts
273: # Remember status and be verbose
274: if test $? -ne 17 ; then
275: rc_status -v
276: else
277: rc_status -u
278: fi
279: else
280: rc_reset
281: rc_status -v
282: fi
283: ;;
284: stop)
285: echo -n "Shutting down smartd "
286: /sbin/killproc -TERM $SMARTD_BIN
287: # Remember status and be verbose
288: rc_status -v
289: ;;
290: try-restart)
291: ## Do a restart only if the service was active before.
292: ## Note: try-restart is now part of LSB (as of 1.9).
293: $0 status
294: if test $? = 0; then
295: $0 restart
296: else
297: rc_reset # Not running is not a failure.
298: fi
299: # Remember status and be quiet
300: rc_status
301: ;;
302: restart)
303: $0 stop
304: $0 start
305: # Remember status and be quiet
306: rc_status
307: ;;
308: force-reload|reload)
309: echo -n "Reload service smartd "
310: /sbin/killproc -HUP $SMARTD_BIN
311: rc_status -v
312: ;;
313: report)
314: ## Checking SMART devices now (smartd specific function)
315: echo -n "Checking SMART devices now "
316: /sbin/killproc -USR1 $SMARTD_BIN
317: rc_status -v
318: ;;
319: status)
320: echo -n "Checking for service smartd "
321: ## Check status with checkproc(8), if process is running
322: ## checkproc will return with exit status 0.
323:
324: # Return value is slightly different for the status command:
325: # 0 - service up and running
326: # 1 - service dead, but /var/run/ pid file exists
327: # 2 - service dead, but /var/lock/ lock file exists
328: # 3 - service not running (unused)
329: # 4 - service status unknown :-(
330: # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
331:
332: # NOTE: checkproc returns LSB compliant status values.
333: /sbin/checkproc $SMARTD_BIN
334: rc_status -v
335: ;;
336: probe)
337: ## Optional: Probe for the necessity of a reload, print out the
338: ## argument to this init script which is required for a reload.
339: ## Note: probe is not (yet) part of LSB (as of 1.9)
340:
341: test $SMARTD_CONFIG -nt /var/run/smartd.pid && echo reload
342: ;;
343: *)
344: echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|report|probe}"
345: exit 1
346: esac
347: rc_exit
348:
349: # Debian case
350: elif [ -f /etc/debian_version ] ; then
351: PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
352: SMARTDPID=/var/run/smartd.pid
353: [ -x $SMARTD_BIN ] || exit 0
354: RET=0
355:
356: # source configuration file
357: [ -r /etc/default/rcS ] && . /etc/default/rcS
358: [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
359:
360: smartd_opts="--pidfile $SMARTDPID $smartd_opts"
361:
362: case "$1" in
363: start)
364: echo -n "Starting S.M.A.R.T. daemon: smartd"
365: if start-stop-daemon --start --quiet --pidfile $SMARTDPID \
366: --exec $SMARTD_BIN -- $smartd_opts; then
367: echo "."
368: else
369: echo " (failed)"
370: RET=1
371: fi
372: ;;
373: stop)
374: echo -n "Stopping S.M.A.R.T. daemon: smartd"
375: start-stop-daemon --stop --quiet --oknodo --pidfile $SMARTDPID
376: echo "."
377: ;;
378: restart)
379: $0 stop
380: $0 start
381: ;;
382: force-reload)
383: $0 reload || $0 restart
384: ;;
385: reload)
386: echo -n "Reload S.M.A.R.T. daemon: smartd"
387: if start-stop-daemon --stop --quiet --signal 1 \
388: --pidfile $SMARTDPID; then
389: echo "."
390: else
391: echo " (failed)"
392: RET=1
393: fi
394: ;;
395: report)
396: echo -n "Checking SMART devices now"
397: if start-stop-daemon --stop --quiet --signal 10 \
398: --pidfile $SMARTDPID; then
399: echo "."
400: else
401: echo " (failed)"
402: RET=1
403: fi
404: ;;
405: status)
406: if pidof $SMARTD_BIN >/dev/null; then
407: echo "$SMARTD_BIN is running."
408: else
409: echo "$SMARTD_BIN is not running."
410: RET=1
411: fi
412: ;;
413: *)
414: echo "Usage: $0 {start|stop|restart|force-reload|reload|report|status}"
415: exit 1
416: esac
417: exit $RET
418:
419: elif [ -f /etc/gentoo-release ] ; then
420: report_unsupported "Gentoo"
421:
422: elif [ -f /etc/turbolinux-release ] ; then
423: report_unsupported "Turbolinux"
424:
425: elif [ -f /etc/environment.corel ] ; then
426: report_unsupported "Corel"
427:
428: # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif
429:
430: elif uname -a | grep FreeBSD > /dev/null 2>&1 ; then
431: # following is replaced by port install
432: PREFIX=@@PREFIX@@
433:
434: # Updated to try both the RCNG version of things from 5.x, or fallback to
435: # oldfashioned rc.conf
436:
437: if [ -r /etc/rc.subr ]; then
438: # This is RC-NG, pick up our values
439: . /etc/rc.subr
440: name="smartd"
441: rcvar="smartd_enable"
442: command="$SMARTD_BIN"
443: load_rc_config $name
444: elif [ -r /etc/defaults/rc.conf ]; then
445: # Not a 5.x system, try the default location for variables
446: . /etc/defaults/rc.conf
447: source_rc_confs
448: elif [ -r /etc/rc.conf ]; then
449: # Worst case, fallback to system config file
450: . /etc/rc.conf
451: fi
452:
453: if [ -r /etc/rc.subr ]; then
454: # Use new functionality from RC-NG
455: run_rc_command "$1"
456: else
457: PID_FILE=/var/run/smartd.pid
458: case "$1" in
459: start)
460: $SMARTD_BIN -p $PID_FILE $smartd_flags
461: echo -n " smartd"
462: ;;
463: stop)
464: kill `cat $PID_FILE`
465: echo -n " smartd"
466: ;;
467: restart)
468: $0 stop
469: sleep 1
470: $0 start
471: ;;
472: reload)
473: kill -s HUP `cat $PID_FILE`
474: ;;
475: report)
476: kill -s USR1 `cat $PID_FILE`
477: ;;
478: *)
479: echo "Usage: $0 {start|stop|restart|reload|report}"
480: exit 1
481: esac
482: exit 0
483: fi
484:
485: elif uname -a | grep SunOS > /dev/null 2>&1 ; then
486:
487: # Source configuration file. This should define the shell variable smartd_opts.
488: # Email smartmontools-support@lists.sourceforge.net if there is a better choice
489: # of path for Solaris
490:
491: [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
492:
493: PID_FILE=/var/run/smartd.pid
494:
495: case "$1" in
496: start)
497: $SMARTD_BIN -p $PID_FILE $smartd_opts
498: echo -n "smartd "
499: ;;
500: stop)
501: [ -f $PID_FILE ] && kill `cat $PID_FILE`
502: echo -n "smartd "
503: ;;
504: restart)
505: $0 stop
506: sleep 1
507: $0 start
508: ;;
509: reload)
510: kill -s HUP `cat $PID_FILE`
511: ;;
512: report)
513: kill -s USR1 `cat $PID_FILE`
514: ;;
515: *)
516: echo "Usage: $0 {start|stop|restart|reload|report}"
517: exit 1
518: esac
519: exit 0
520:
521: # Cygwin
522: elif uname | grep -i CYGWIN > /dev/null 2>&1 ; then
523:
524: # The following settings may be changed by the configuration file below
525: # Service Name (must be unique)
526: smartd_svcname=smartd
527: # Service display name
528: smartd_svcdisp="CYGWIN smartd"
529: # Service description
530: smartd_svcdesc="\
531: Controls and monitors storage devices using the Self-Monitoring \
532: Analysis and Reporting Technology System (S.M.A.R.T.) \
533: built into ATA and SCSI Hard Drives. \
534: http://smartmontools.sourceforge.net/"
535:
536: # Source configuration file. This should define the shell variable smartd_opts.
537: # Email smartmontools-support@lists.sourceforge.net if there is a better choice
538: # of path for Cygwin
539:
540: [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
541:
542: PID_FILE=/var/run/smartd.pid
543: RETVAL=0
544:
545: # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may
546: # return success even if the file is present but cannot be read by current user.
547: # If smartd is running as service, smartd.pid is owned by local system account
548: # which is different from any user ever executing this script.
549:
550: case "$1" in
551: start)
552: if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then
553: echo -n "Starting service $smartd_svcname: "
554: cygrunsrv -S "$smartd_svcname"
555: else
556: echo -n "Starting smartd as daemon: "
557: $SMARTD_BIN -p $PID_FILE $smartd_opts
558: fi
559: RETVAL=$?
560: ;;
561: stop)
562: echo -n "Shutting down smartd: "
563: pid="`cat $PID_FILE 2>/dev/null`" && kill "$pid"
564: RETVAL=$?
565: ;;
566: reload)
567: echo -n "Reloading smartd configuration: "
568: pid="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid"
569: RETVAL=$?
570: ;;
571: report)
572: echo -n "Checking SMART devices now: "
573: pid="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid"
574: RETVAL=$?
575: ;;
576: restart)
577: $0 stop
578: sleep 1
579: $0 start
580: exit $?
581: ;;
582: install)
583: shift
584: [ $# -eq 0 ] || smartd_opts="$*"
585: dep=; dep2=
586: if cygrunsrv -L 2>/dev/null | grep "^syslogd$" >/dev/null 2>&1; then
587: dep="syslogd"
588: fi
589: if cygrunsrv -L 2>/dev/null | grep "^syslog-ng" >/dev/null 2>&1; then
590: dep2="syslog-ng"
591: fi
592: if [ -z "$dep" ]; then
593: if [ -z "$dep2" ]; then
594: echo "Warning: no syslog service installed, smartd will write to windows event log.";
595: else
596: dep="$dep2"
597: fi
598: else
599: if [ -z "$dep2" ]; then
600: :
601: else
602: dep=
603: echo "Warning: both syslogd and syslog-ng installed, dependency not set."
604: fi
605: fi
606: echo "Installing service ${smartd_svcname}${dep:+ (depending on '$dep')}${smartd_opts:+ with options '$smartd_opts'}:"
607: cygrunsrv -I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" ${dep:+-y} $dep \
608: -e CYGWIN="$CYGWIN" -p $SMARTD_BIN -a "-n -p ${PID_FILE}${smartd_opts:+ }$smartd_opts"
609: RETVAL=$?
610: ;;
611: remove)
612: echo "Removing service $smartd_svcname:"
613: cygrunsrv -R "$smartd_svcname"
614: RETVAL=$?
615: ;;
616: status)
617: echo -n "Checking smartd status: "
618: if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then
619: if cygrunsrv -Q "$smartd_svcname" 2>/dev/null | grep "State *: Running" >/dev/null 2>&1; then
620: echo "running as service '$smartd_svcname'."
621: elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then
622: echo "installed as service '$smartd_svcname' but running as daemon."
623: else
624: echo "installed as service '$smartd_svcname' but not running."
625: RETVAL=1
626: fi
627: elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then
628: echo "running as daemon."
629: else
630: echo "not running."
631: RETVAL=1
632: fi
633: exit $RETVAL
634: ;;
635: *)
636: echo "Usage: $0 {start|stop|restart|reload|report|status}"
637: echo " $0 {install [options]|remove}"
638: exit 1
639: esac
640:
641: if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi
642: exit $RETVAL
643:
644: # Add other OSes HERE, using elif...
645: else
646: report_unsupported "Unknown"
647: fi
648:
649: # One should NEVER arrive here, except for a badly written case above,
650: # that fails to exit.
651: echo "SOMETHING IS WRONG WITH THE SMARTD STARTUP SCRIPT"
652: echo "PLEASE CONTACT smartmontools-support@lists.sourceforge.net"
653: exit 1
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>