]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - smartd.initd.in
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 $
7 # For RedHat and cousins:
8 # chkconfig: 2345 40 40
9 # description: Self Monitoring and Reporting Technology (SMART) Daemon
12 # For SuSE and cousins
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
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.
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
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/.
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"
42 SMARTD_BIN
=/usr
/local
/sbin
/smartd
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."
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
55 # Source function library
56 .
/etc
/rc.d
/init.d
/functions
58 # Source configuration file. This should define the shell variable smartd_opts
59 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
64 pidfile
=/var
/lock
/subsys
/smartd
65 config
=/etc
/smartd.conf
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
76 [ $RETVAL = 0 ] && touch $pidfile
82 [ $UID -eq 0 ] ||
exit 4
83 echo -n $
"Shutting down $prog: "
93 echo -n $
"Reloading $prog daemon configuration: "
94 killproc
$SMARTD_BIN -HUP
102 echo -n $
"Checking SMART devices now: "
103 killproc
$SMARTD_BIN -USR1
126 condrestart|try-restart
)
127 if [ -f $pidfile ]; then
133 reload ||
(stop
; start
)
140 echo $
"Usage: $0 {start|stop|restart|status|condrestart|try-restart|reload|force-reload|report}"
142 [ "$1" = 'usage' ] && RETVAL
=0
147 elif [ -f /etc
/slackware-version
] ; then
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.
153 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
158 echo -n "Starting smartd: "
159 $SMARTD_BIN $smartd_opts
164 echo -n "Shutting down smartd: "
176 if pidof
$SMARTD_BIN >/dev
/null
; then
182 $0 reload ||
$0 restart
186 echo -n "Reloading smartd configuration: "
187 killall
-s HUP
$SMARTD_BIN
192 echo -n "Checking SMART devices now: "
193 killall
-s USR1
$SMARTD_BIN
198 if pidof
$SMARTD_BIN >/dev
/null
; then
199 echo "$SMARTD_BIN is running."
201 echo "$SMARTD_BIN is not running."
206 echo "Usage: $0 {start|stop|restart|try-restart|force-reload|reload|report|status}"
212 elif [ -f /etc
/SuSE-release
] ; then
213 test -x $SMARTD_BIN ||
exit 5
215 # Existence of config file is optional
216 SMARTD_CONFIG
=/etc
/smartd.conf
218 # source configuration file.
219 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
221 if test -n "$SMARTD_CHECK_INTERVAL" -a "$SMARTD_CHECK_INTERVAL" != 1800 ; then
222 smartd_opts
=" -i $SMARTD_CHECK_INTERVAL"
224 if test -n "$SMARTD_LOG_FACILITY" -a "$SMARTD_LOG_FACILITY" != "daemon" ; then
225 smartd_opts
="$smartd_opts -l $SMARTD_LOG_FACILITY"
227 if test -n "$SMARTD_DRIVEDB" ; then
228 smartd_opts
="$smartd_opts -B $SMARTD_DRIVEDB"
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
245 # Reset status of this service
248 # Return values acc. to LSB for all commands but status:
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)
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.
266 echo -n "Starting smartd "
267 ## Start daemon with startproc(8). If this fails
268 ## the return value is set appropriately by startproc.
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
285 echo -n "Shutting down smartd "
286 /sbin
/killproc
-TERM $SMARTD_BIN
287 # Remember status and be verbose
291 ## Do a restart only if the service was active before.
292 ## Note: try-restart is now part of LSB (as of 1.9).
297 rc_reset
# Not running is not a failure.
299 # Remember status and be quiet
305 # Remember status and be quiet
309 echo -n "Reload service smartd "
310 /sbin
/killproc
-HUP $SMARTD_BIN
314 ## Checking SMART devices now (smartd specific function)
315 echo -n "Checking SMART devices now "
316 /sbin
/killproc
-USR1 $SMARTD_BIN
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.
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.)
332 # NOTE: checkproc returns LSB compliant status values.
333 /sbin
/checkproc
$SMARTD_BIN
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)
341 test $SMARTD_CONFIG -nt /var
/run
/smartd.pid
&& echo reload
344 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|report|probe}"
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
356 # source configuration file
357 [ -r /etc
/default
/rcS
] && .
/etc
/default
/rcS
358 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
360 smartd_opts
="--pidfile $SMARTDPID $smartd_opts"
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
374 echo -n "Stopping S.M.A.R.T. daemon: smartd"
375 start-stop-daemon
--stop --quiet --oknodo --pidfile $SMARTDPID
383 $0 reload ||
$0 restart
386 echo -n "Reload S.M.A.R.T. daemon: smartd"
387 if start-stop-daemon
--stop --quiet --signal 1 \
388 --pidfile $SMARTDPID; then
396 echo -n "Checking SMART devices now"
397 if start-stop-daemon
--stop --quiet --signal 10 \
398 --pidfile $SMARTDPID; then
406 if pidof
$SMARTD_BIN >/dev
/null
; then
407 echo "$SMARTD_BIN is running."
409 echo "$SMARTD_BIN is not running."
414 echo "Usage: $0 {start|stop|restart|force-reload|reload|report|status}"
419 elif [ -f /etc
/gentoo-release
] ; then
420 report_unsupported
"Gentoo"
422 elif [ -f /etc
/turbolinux-release
] ; then
423 report_unsupported
"Turbolinux"
425 elif [ -f /etc
/environment.corel
] ; then
426 report_unsupported
"Corel"
428 # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif
430 elif uname
-a |
grep FreeBSD
> /dev
/null
2>&1 ; then
431 # following is replaced by port install
434 # Updated to try both the RCNG version of things from 5.x, or fallback to
435 # oldfashioned rc.conf
437 if [ -r /etc
/rc.subr
]; then
438 # This is RC-NG, pick up our values
441 rcvar
="smartd_enable"
442 command="$SMARTD_BIN"
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
448 elif [ -r /etc
/rc.conf
]; then
449 # Worst case, fallback to system config file
453 if [ -r /etc
/rc.subr
]; then
454 # Use new functionality from RC-NG
457 PID_FILE
=/var
/run
/smartd.pid
460 $SMARTD_BIN -p $PID_FILE $smartd_flags
473 kill -s HUP
`cat $PID_FILE`
476 kill -s USR1
`cat $PID_FILE`
479 echo "Usage: $0 {start|stop|restart|reload|report}"
485 elif uname
-a |
grep SunOS
> /dev
/null
2>&1 ; then
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
491 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
493 PID_FILE
=/var
/run
/smartd.pid
497 $SMARTD_BIN -p $PID_FILE $smartd_opts
501 [ -f $PID_FILE ] && kill `cat $PID_FILE`
510 kill -s HUP
`cat $PID_FILE`
513 kill -s USR1
`cat $PID_FILE`
516 echo "Usage: $0 {start|stop|restart|reload|report}"
522 elif uname |
grep -i CYGWIN
> /dev
/null
2>&1 ; then
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
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/"
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
540 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
542 PID_FILE
=/var
/run
/smartd.pid
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.
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"
556 echo -n "Starting smartd as daemon: "
557 $SMARTD_BIN -p $PID_FILE $smartd_opts
562 echo -n "Shutting down smartd: "
563 pid
="`cat $PID_FILE 2>/dev/null`" && kill "$pid"
567 echo -n "Reloading smartd configuration: "
568 pid
="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid"
572 echo -n "Checking SMART devices now: "
573 pid
="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid"
584 [ $# -eq 0 ] || smartd_opts
="$*"
586 if cygrunsrv
-L 2>/dev
/null |
grep "^syslogd$" >/dev
/null
2>&1; then
589 if cygrunsrv
-L 2>/dev
/null |
grep "^syslog-ng" >/dev
/null
2>&1; then
592 if [ -z "$dep" ]; then
593 if [ -z "$dep2" ]; then
594 echo "Warning: no syslog service installed, smartd will write to windows event log.";
599 if [ -z "$dep2" ]; then
603 echo "Warning: both syslogd and syslog-ng installed, dependency not set."
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"
612 echo "Removing service $smartd_svcname:"
613 cygrunsrv
-R "$smartd_svcname"
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."
624 echo "installed as service '$smartd_svcname' but not running."
627 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
628 echo "running as daemon."
636 echo "Usage: $0 {start|stop|restart|reload|report|status}"
637 echo " $0 {install [options]|remove}"
641 if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi
644 # Add other OSes HERE, using elif...
646 report_unsupported
"Unknown"
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"