]>
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,v 1.38 2008/03/04 22:09:47 ballen4705 Exp $
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
16 # X-UnitedLinux-Should-Start: $sendmail
17 # Should-Start: $sendmail
18 # Required-Stop: $syslog
19 # X-UnitedLinux-Should-Stop:
20 # Default-Start: 2 3 5
22 # Short-Description: Monitors disk and tape health via S.M.A.R.T.
23 # Description: Start S.M.A.R.T. disk and tape monitor.
26 # This program is free software; you can redistribute it and/or modify it
27 # under the terms of the GNU General Public License as published by the Free
28 # Software Foundation; either version 2, or (at your option) any later
30 # You should have received a copy of the GNU General Public License (for
31 # example COPYING); if not, write to the Free Software Foundation, Inc., 675
32 # Mass Ave, Cambridge, MA 02139, USA.
33 # This code was originally developed as a Senior Thesis by Michael Cornwell
34 # at the Concurrent Systems Laboratory (now part of the Storage Systems
35 # Research Center), Jack Baskin School of Engineering, University of
36 # California, Santa Cruz. http://ssrc.soe.ucsc.edu/.
38 # Uncomment the line below to pass options to smartd on startup.
39 # Note that distribution specific configuration files like
40 # /etc/{default,sysconfig}/smartmontools might override these
41 #smartd_opts="--interval=1800"
43 SMARTD_BIN
=/usr
/local
/sbin
/smartd
45 report_unsupported
() {
46 echo "Currently the smartmontools package has no init script for"
47 echo "the $1 OS/distribution. If you can provide one or this"
48 echo "one works after removing some ifdefs, please contact"
49 echo "smartmontools-support@lists.sourceforge.net."
53 # Red Hat or Yellow Dog or Mandrake
54 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
56 # Source function library
57 .
/etc
/rc.d
/init.d
/functions
59 # Source configuration file. This should define the shell variable smartd_opts
60 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
68 echo -n $
"Starting $prog: "
69 daemon
$SMARTD_BIN $smartd_opts
70 touch /var
/lock
/subsys
/smartd
74 echo -n $
"Shutting down $prog: "
76 rm -f /var
/lock
/subsys
/smartd
80 echo -n $
"Reloading $prog daemon configuration: "
81 killproc
$SMARTD_BIN -HUP
86 echo -n $
"Checking SMART devices now: "
87 killproc
$SMARTD_BIN -USR1
99 echo $
"Usage: $0 {start|stop|reload|report|restart|status}"
106 elif [ -f /etc
/slackware-version
] ; then
108 # Source configuration file. This should define the shell variable smartd_opts.
109 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
110 # of path for Slackware.
112 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
116 echo -n "Starting smartd: "
117 $SMARTD_BIN $smartd_opts
121 echo -n "Shutting down smartd: "
131 echo "Usage: smartd {start|stop|restart}"
138 elif [ -f /etc
/SuSE-release
] ; then
139 test -x $SMARTD_BIN ||
exit 5
141 # Existence of config file is optional
142 SMARTD_CONFIG
=/etc
/smartd.conf
144 # source configuration file. This should set the shell variable smartd_opts
145 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
147 # Shell functions sourced from /etc/rc.status:
148 # rc_check check and set local and overall rc status
149 # rc_status check and set local and overall rc status
150 # rc_status -v ditto but be verbose in local rc status
151 # rc_status -v -r ditto and clear the local rc status
152 # rc_failed set local and overall rc status to failed
153 # rc_reset clear local rc status (overall remains)
154 # rc_exit exit appropriate to overall rc status
157 # First reset status of this service
160 # Return values acc. to LSB for all commands but status:
163 # 2 - invalid or excess args
164 # 3 - unimplemented feature (e.g. reload)
165 # 4 - insufficient privilege
166 # 5 - program not installed
167 # 6 - program not configured
169 # Note that starting an already running service, stopping
170 # or restarting a not-running service as well as the restart
171 # with force-reload (in case signalling is not supported) are
172 # considered a success.
175 echo -n "Starting smartd "
176 ## Start daemon with startproc(8). If this fails
177 ## the echo return value is set appropriate.
179 # startproc should return 0, even if service is
180 # already running to match LSB spec.
181 startproc
$SMARTD_BIN $smartd_opts
183 # Remember status and be verbose
187 echo -n "Shutting down smartd "
188 killproc
-TERM $SMARTD_BIN
190 # Remember status and be verbose
193 try-restart|condrestart
)
194 ## Do a restart only if the service was active before.
195 ## Note: try-restart is now part of LSB (as of 1.9).
196 ## RH has a similar command named condrestart.
197 if test "$1" = "condrestart"; then
198 echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
204 rc_reset
# Not running is not a failure.
206 # Remember status and be quiet
209 restart | force-reload
)
214 ## Like force-reload, but if daemon does not support
215 ## signaling, do nothing (!)
220 echo -n "Checking for service smartd "
221 ## Check status with checkproc(8), if process is running
222 ## checkproc will return with exit status 0.
224 # Status has a slightly different for the status command:
225 # 0 - service running
226 # 1 - service dead, but /var/run/ pid file exists
227 # 2 - service dead, but /var/lock/ lock file exists
228 # 3 - service not running
230 # NOTE: checkproc returns LSB compliant status values.
231 checkproc
$SMARTD_BIN
235 ## Optional: Probe for the necessity of a reload, print out the
236 ## argument to this init script which is required for a reload.
237 ## Note: probe is not (yet) part of LSB (as of 1.2)
239 test $SMARTD_CONFIG -nt /var
/run
/smartd.pid
&& echo reload
242 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
250 elif [ -f /etc
/debian_version
] ; then
251 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
252 SMARTDPID
=/var
/run
/smartd.pid
253 [ -x $SMARTD_BIN ] ||
exit 0
256 # source configuration file
257 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
259 smartd_opts
="--pidfile $SMARTDPID $smartd_opts"
263 echo -n "Starting S.M.A.R.T. daemon: smartd"
264 if start-stop-daemon
--start --quiet --pidfile $SMARTDPID \
265 --exec $SMARTD_BIN -- $smartd_opts; then
273 echo -n "Stopping S.M.A.R.T. daemon: smartd"
274 start-stop-daemon
--stop --quiet --oknodo --pidfile $SMARTDPID
277 restart|force-reload
)
282 echo "Usage: /etc/init.d/smartmontools {start|stop|restart|force-reload}"
287 elif [ -f /etc
/gentoo-release
] ; then
288 report_unsupported
"Gentoo"
290 elif [ -f /etc
/turbolinux-release
] ; then
291 report_unsupported
"Turbolinux"
293 elif [ -f /etc
/environment.corel
] ; then
294 report_unsupported
"Corel"
296 # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif
298 elif uname
-a |
grep FreeBSD
> /dev
/null
2>&1 ; then
299 # following is replaced by port install
302 # Updated to try both the RCNG version of things from 5.x, or fallback to
303 # oldfashioned rc.conf
305 if [ -r /etc
/rc.subr
]; then
306 # This is RC-NG, pick up our values
309 rcvar
="smartd_enable"
310 command="$SMARTD_BIN"
312 elif [ -r /etc
/defaults
/rc.conf
]; then
313 # Not a 5.x system, try the default location for variables
314 .
/etc
/defaults
/rc.conf
316 elif [ -r /etc
/rc.conf
]; then
317 # Worst case, fallback to system config file
321 if [ -r /etc
/rc.subr
]; then
322 # Use new functionality from RC-NG
325 PID_FILE
=/var
/run
/smartd.pid
328 $SMARTD_BIN -p $PID_FILE $smartd_flags
341 echo "Usage: smartd {start|stop|restart}"
347 elif uname
-a |
grep SunOS
> /dev
/null
2>&1 ; then
349 # Source configuration file. This should define the shell variable smartd_opts.
350 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
351 # of path for Solaris
353 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
355 PID_FILE
=/var
/run
/smartd.pid
359 $SMARTD_BIN -p $PID_FILE $smartd_opts
363 [ -f $PID_FILE ] && kill `cat $PID_FILE`
372 echo "Usage: smartd {start|stop|restart}"
379 elif uname |
grep -i CYGWIN
> /dev
/null
2>&1 ; then
381 # The following settings may be changed by the configuration file below
382 # Service Name (must be unique)
383 smartd_svcname
=smartd
384 # Service display name
385 smartd_svcdisp
="CYGWIN smartd"
386 # Service description
388 Controls and monitors storage devices using the Self-Monitoring \
389 Analysis and Reporting Technology System (S.M.A.R.T.) \
390 built into ATA and SCSI Hard Drives. \
391 http://smartmontools.sourceforge.net/"
393 # Source configuration file. This should define the shell variable smartd_opts.
394 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
397 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
399 PID_FILE
=/var
/run
/smartd.pid
402 # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may
403 # return success even if the file is present but cannot be read by current user.
404 # If smartd is running as service, smartd.pid is owned by local system account
405 # which is different from any user ever executing this script.
409 if cygrunsrv
-L 2>/dev
/null |
grep "^${smartd_svcname}$" >/dev
/null
2>&1; then
410 echo -n "Starting service $smartd_svcname: "
411 cygrunsrv
-S "$smartd_svcname"
413 echo -n "Starting smartd as daemon: "
414 $SMARTD_BIN -p $PID_FILE $smartd_opts
419 echo -n "Shutting down smartd: "
420 pid
="`cat $PID_FILE 2>/dev/null`" && kill "$pid"
424 echo -n "Reloading smartd configuration: "
425 pid
="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid"
429 echo -n "Checking SMART devices now: "
430 pid
="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid"
441 [ $# -eq 0 ] || smartd_opts
="$*"
443 if cygrunsrv
-L 2>/dev
/null |
grep "^syslogd$" >/dev
/null
2>&1; then
446 echo "Warning: syslogd service not installed, smartd will write to windows event log.";
448 echo "Installing service ${smartd_svcname}${smartd_opts+ with options '$smartd_opts'}:"
449 cygrunsrv
-I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" $dep \
450 -e CYGWIN
="$CYGWIN" -p $SMARTD_BIN -a "-n -p ${PID_FILE}${smartd_opts+ }$smartd_opts"
454 echo "Removing service $smartd_svcname:"
455 cygrunsrv
-R "$smartd_svcname"
459 echo -n "Checking smartd status: "
460 if cygrunsrv
-L 2>/dev
/null |
grep "^${smartd_svcname}$" >/dev
/null
2>&1; then
461 if cygrunsrv
-Q "$smartd_svcname" 2>/dev
/null |
grep "State *: Running" >/dev
/null
2>&1; then
462 echo "running as service '$smartd_svcname'."
463 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
464 echo "installed as service '$smartd_svcname' but running as daemon."
466 echo "installed as service '$smartd_svcname' but not running."
469 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
470 echo "running as daemon."
478 echo "Usage: $0 {start|stop|restart|reload|report|status}"
479 echo " $0 {install [options]|remove}"
483 if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi
486 # Add other OSes HERE, using elif...
488 report_unsupported
"Unknown"
491 # One should NEVER arrive here, except for a badly written case above,
492 # that fails to exit.
493 echo "SOMETHING IS WRONG WITH THE SMARTD STARTUP SCRIPT"
494 echo "PLEASE CONTACT smartmontools-support@lists.sourceforge.net"