]>
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 4120 2015-08-27 16:12:21Z samm2 $
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.,
31 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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"
230 if test "$SMARTD_SAVESTATES" = "no" ; then
231 smartd_opts
="$smartd_opts -s \"\""
233 if test "$SMARTD_ATTRLOG" = "no" ; then
234 smartd_opts
="$smartd_opts -A \"\""
236 if test -n "$SMARTD_EXTRA_OPTS" ; then
237 smartd_opts
="$smartd_opts $SMARTD_EXTRA_OPTS"
240 # Shell functions sourced from /etc/rc.status:
241 # rc_check check and set local and overall rc status
242 # rc_status check and set local and overall rc status
243 # rc_status -v be verbose in local rc status and clear it afterwards
244 # rc_status -v -r ditto and clear both the local and overall rc status
245 # rc_status -s display "skipped" and exit with status 3
246 # rc_status -u display "unused" and exit with status 3
247 # rc_failed set local and overall rc status to failed
248 # rc_failed <num> set local and overall rc status to <num>
249 # rc_reset clear both the local and overall rc status
250 # rc_exit exit appropriate to overall rc status
251 # rc_active checks whether a service is activated by symlinks
254 # Reset status of this service
257 # Return values acc. to LSB for all commands but status:
259 # 1 - generic or unspecified error
260 # 2 - invalid or excess argument(s)
261 # 3 - unimplemented feature (e.g. "reload")
262 # 4 - user had insufficient privileges
263 # 5 - program is not installed
264 # 6 - program is not configured
265 # 7 - program is not running
266 # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
268 # Note that starting an already running service, stopping
269 # or restarting a not-running service as well as the restart
270 # with force-reload (in case signaling is not supported) are
271 # considered a success.
275 echo -n "Starting smartd "
276 ## Start daemon with startproc(8). If this fails
277 ## the return value is set appropriately by startproc.
279 # We don't use startproc - we need to check for return code 17.
280 if ! /sbin
/checkproc
$SMARTD_BIN ; then
281 eval $SMARTD_BIN$smartd_opts
282 # Remember status and be verbose
283 if test $?
-ne 17 ; then
294 echo -n "Shutting down smartd "
295 /sbin
/killproc
-TERM $SMARTD_BIN
296 # Remember status and be verbose
300 ## Do a restart only if the service was active before.
301 ## Note: try-restart is now part of LSB (as of 1.9).
306 rc_reset
# Not running is not a failure.
308 # Remember status and be quiet
314 # Remember status and be quiet
318 echo -n "Reload service smartd "
319 /sbin
/killproc
-HUP $SMARTD_BIN
323 ## Checking SMART devices now (smartd specific function)
324 echo -n "Checking SMART devices now "
325 /sbin
/killproc
-USR1 $SMARTD_BIN
329 echo -n "Checking for service smartd "
330 ## Check status with checkproc(8), if process is running
331 ## checkproc will return with exit status 0.
333 # Return value is slightly different for the status command:
334 # 0 - service up and running
335 # 1 - service dead, but /var/run/ pid file exists
336 # 2 - service dead, but /var/lock/ lock file exists
337 # 3 - service not running (unused)
338 # 4 - service status unknown :-(
339 # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
341 # NOTE: checkproc returns LSB compliant status values.
342 /sbin
/checkproc
$SMARTD_BIN
346 ## Optional: Probe for the necessity of a reload, print out the
347 ## argument to this init script which is required for a reload.
348 ## Note: probe is not (yet) part of LSB (as of 1.9)
350 test $SMARTD_CONFIG -nt /var
/run
/smartd.pid
&& echo reload
353 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|report|probe}"
359 elif [ -f /etc
/debian_version
] ; then
360 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
361 SMARTDPID
=/var
/run
/smartd.pid
362 [ -x $SMARTD_BIN ] ||
exit 0
365 # source configuration file
366 [ -r /etc
/default
/rcS
] && .
/etc
/default
/rcS
367 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
369 smartd_opts
="--pidfile $SMARTDPID $smartd_opts"
373 echo -n "Starting S.M.A.R.T. daemon: smartd"
374 if start-stop-daemon
--start --quiet --pidfile $SMARTDPID \
375 --exec $SMARTD_BIN -- $smartd_opts; then
383 echo -n "Stopping S.M.A.R.T. daemon: smartd"
384 start-stop-daemon
--stop --quiet --oknodo --pidfile $SMARTDPID
392 $0 reload ||
$0 restart
395 echo -n "Reload S.M.A.R.T. daemon: smartd"
396 if start-stop-daemon
--stop --quiet --signal 1 \
397 --pidfile $SMARTDPID; then
405 echo -n "Checking SMART devices now"
406 if start-stop-daemon
--stop --quiet --signal 10 \
407 --pidfile $SMARTDPID; then
415 if pidof
$SMARTD_BIN >/dev
/null
; then
416 echo "$SMARTD_BIN is running."
418 echo "$SMARTD_BIN is not running."
423 echo "Usage: $0 {start|stop|restart|force-reload|reload|report|status}"
428 elif [ -f /etc
/gentoo-release
] ; then
429 report_unsupported
"Gentoo"
431 elif [ -f /etc
/turbolinux-release
] ; then
432 report_unsupported
"Turbolinux"
434 elif [ -f /etc
/environment.corel
] ; then
435 report_unsupported
"Corel"
437 # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif
439 elif uname
-a |
grep FreeBSD
> /dev
/null
2>&1 ; then
440 # following is replaced by port install
443 # Updated to try both the RCNG version of things from 5.x, or fallback to
444 # oldfashioned rc.conf
446 if [ -r /etc
/rc.subr
]; then
447 # This is RC-NG, pick up our values
450 rcvar
="smartd_enable"
451 command="$SMARTD_BIN"
453 elif [ -r /etc
/defaults
/rc.conf
]; then
454 # Not a 5.x system, try the default location for variables
455 .
/etc
/defaults
/rc.conf
457 elif [ -r /etc
/rc.conf
]; then
458 # Worst case, fallback to system config file
462 if [ -r /etc
/rc.subr
]; then
463 # Use new functionality from RC-NG
466 PID_FILE
=/var
/run
/smartd.pid
469 $SMARTD_BIN -p $PID_FILE $smartd_flags
482 kill -s HUP
`cat $PID_FILE`
485 kill -s USR1
`cat $PID_FILE`
488 echo "Usage: $0 {start|stop|restart|reload|report}"
494 elif uname
-a |
grep SunOS
> /dev
/null
2>&1 ; then
496 # Source configuration file. This should define the shell variable smartd_opts.
497 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
498 # of path for Solaris
500 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
502 PID_FILE
=/var
/run
/smartd.pid
506 $SMARTD_BIN -p $PID_FILE $smartd_opts
510 [ -f $PID_FILE ] && kill `cat $PID_FILE`
519 kill -s HUP
`cat $PID_FILE`
522 kill -s USR1
`cat $PID_FILE`
525 echo "Usage: $0 {start|stop|restart|reload|report}"
531 elif uname |
grep -i CYGWIN
> /dev
/null
2>&1 ; then
533 # The following settings may be changed by the configuration file below
534 # Service Name (must be unique)
535 smartd_svcname
=smartd
536 # Service display name
537 smartd_svcdisp
="CYGWIN smartd"
538 # Service description
540 Controls and monitors storage devices using the Self-Monitoring \
541 Analysis and Reporting Technology System (S.M.A.R.T.) \
542 built into ATA and SCSI Hard Drives. \
543 http://www.smartmontools.org/"
545 # Source configuration file. This should define the shell variable smartd_opts.
546 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
549 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
551 PID_FILE
=/var
/run
/smartd.pid
554 # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may
555 # return success even if the file is present but cannot be read by current user.
556 # If smartd is running as service, smartd.pid is owned by local system account
557 # which is different from any user ever executing this script.
561 if cygrunsrv
-L 2>/dev
/null |
grep "^${smartd_svcname}$" >/dev
/null
2>&1; then
562 echo -n "Starting service $smartd_svcname: "
563 cygrunsrv
-S "$smartd_svcname"
565 echo -n "Starting smartd as daemon: "
566 $SMARTD_BIN -p $PID_FILE $smartd_opts
571 echo -n "Shutting down smartd: "
572 pid
="`cat $PID_FILE 2>/dev/null`" && kill "$pid"
576 echo -n "Reloading smartd configuration: "
577 pid
="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid"
581 echo -n "Checking SMART devices now: "
582 pid
="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid"
593 [ $# -eq 0 ] || smartd_opts
="$*"
595 if cygrunsrv
-L 2>/dev
/null |
grep "^syslogd$" >/dev
/null
2>&1; then
598 if cygrunsrv
-L 2>/dev
/null |
grep "^syslog-ng" >/dev
/null
2>&1; then
601 if [ -z "$dep" ]; then
602 if [ -z "$dep2" ]; then
603 echo "Warning: no syslog service installed, smartd will write to windows event log.";
608 if [ -z "$dep2" ]; then
612 echo "Warning: both syslogd and syslog-ng installed, dependency not set."
615 echo "Installing service ${smartd_svcname}${dep:+ (depending on '$dep')}${smartd_opts:+ with options '$smartd_opts'}:"
616 cygrunsrv
-I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" ${dep:+-y} $dep \
617 -e CYGWIN
="$CYGWIN" -p $SMARTD_BIN -a "-n -p ${PID_FILE}${smartd_opts:+ }$smartd_opts"
621 echo "Removing service $smartd_svcname:"
622 cygrunsrv
-R "$smartd_svcname"
626 echo -n "Checking smartd status: "
627 if cygrunsrv
-L 2>/dev
/null |
grep "^${smartd_svcname}$" >/dev
/null
2>&1; then
628 if cygrunsrv
-Q "$smartd_svcname" 2>/dev
/null |
grep "State *: Running" >/dev
/null
2>&1; then
629 echo "running as service '$smartd_svcname'."
630 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
631 echo "installed as service '$smartd_svcname' but running as daemon."
633 echo "installed as service '$smartd_svcname' but not running."
636 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
637 echo "running as daemon."
645 echo "Usage: $0 {start|stop|restart|reload|report|status}"
646 echo " $0 {install [options]|remove}"
650 if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi
653 # Add other OSes HERE, using elif...
655 report_unsupported
"Unknown"
658 # One should NEVER arrive here, except for a badly written case above,
659 # that fails to exit.
660 echo "SOMETHING IS WRONG WITH THE SMARTD STARTUP SCRIPT"
661 echo "PLEASE CONTACT smartmontools-support@lists.sourceforge.net"