]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - smartd.initd.in
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.35 2006/10/24 13:29:24 sbrabec 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 # Required-Stop: $syslog
18 # X-UnitedLinux-Should-Stop:
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
67 echo -n $
"Starting $prog: "
68 daemon
$SMARTD_BIN $smartd_opts
69 touch /var
/lock
/subsys
/smartd
73 echo -n $
"Shutting down $prog: "
75 rm -f /var
/lock
/subsys
/smartd
79 echo -n $
"Reloading $prog daemon configuration: "
80 killproc
$SMARTD_BIN -HUP
85 echo -n $
"Checking SMART devices now: "
86 killproc
$SMARTD_BIN -USR1
98 echo $
"Usage: $0 {start|stop|reload|report|restart|status}"
105 elif [ -f /etc
/slackware-version
] ; then
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.
111 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
115 echo -n "Starting smartd: "
116 $SMARTD_BIN $smartd_opts
120 echo -n "Shutting down smartd: "
130 echo "Usage: smartd {start|stop|restart}"
137 elif [ -f /etc
/SuSE-release
] ; then
138 test -x $SMARTD_BIN ||
exit 5
140 # Existence of config file is optional
141 SMARTD_CONFIG
=/etc
/smartd.conf
143 # source configuration file. This should set the shell variable smartd_opts
144 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
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
156 # First reset status of this service
159 # Return values acc. to LSB for all commands but status:
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
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.
174 echo -n "Starting smartd "
175 ## Start daemon with startproc(8). If this fails
176 ## the echo return value is set appropriate.
178 # startproc should return 0, even if service is
179 # already running to match LSB spec.
180 startproc
$SMARTD_BIN $smartd_opts
182 # Remember status and be verbose
186 echo -n "Shutting down smartd "
187 killproc
-TERM $SMARTD_BIN
189 # Remember status and be verbose
192 try-restart|condrestart
)
193 ## Do a restart only if the service was active before.
194 ## Note: try-restart is now part of LSB (as of 1.9).
195 ## RH has a similar command named condrestart.
196 if test "$1" = "condrestart"; then
197 echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
203 rc_reset
# Not running is not a failure.
205 # Remember status and be quiet
208 restart | force-reload
)
213 ## Like force-reload, but if daemon does not support
214 ## signaling, do nothing (!)
219 echo -n "Checking for service smartd "
220 ## Check status with checkproc(8), if process is running
221 ## checkproc will return with exit status 0.
223 # Status has a slightly different for the status command:
224 # 0 - service running
225 # 1 - service dead, but /var/run/ pid file exists
226 # 2 - service dead, but /var/lock/ lock file exists
227 # 3 - service not running
229 # NOTE: checkproc returns LSB compliant status values.
230 checkproc
$SMARTD_BIN
234 ## Optional: Probe for the necessity of a reload, print out the
235 ## argument to this init script which is required for a reload.
236 ## Note: probe is not (yet) part of LSB (as of 1.2)
238 test $SMARTD_CONFIG -nt /var
/run
/smartd.pid
&& echo reload
241 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
249 elif [ -f /etc
/debian_version
] ; then
250 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
251 SMARTDPID
=/var
/run
/smartd.pid
252 [ -x $SMARTD_BIN ] ||
exit 0
255 # source configuration file
256 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
258 smartd_opts
="--pidfile $SMARTDPID $smartd_opts"
262 echo -n "Starting S.M.A.R.T. daemon: smartd"
263 if start-stop-daemon
--start --quiet --pidfile $SMARTDPID \
264 --exec $SMARTD_BIN -- $smartd_opts; then
272 echo -n "Stopping S.M.A.R.T. daemon: smartd"
273 start-stop-daemon
--stop --quiet --oknodo --pidfile $SMARTDPID
276 restart|force-reload
)
281 echo "Usage: /etc/init.d/smartmontools {start|stop|restart|force-reload}"
286 elif [ -f /etc
/gentoo-release
] ; then
287 report_unsupported
"Gentoo"
289 elif [ -f /etc
/turbolinux-release
] ; then
290 report_unsupported
"Turbolinux"
292 elif [ -f /etc
/environment.corel
] ; then
293 report_unsupported
"Corel"
295 # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif
297 elif uname
-a |
grep FreeBSD
> /dev
/null
2>&1 ; then
298 # following is replaced by port install
301 # Updated to try both the RCNG version of things from 5.x, or fallback to
302 # oldfashioned rc.conf
304 if [ -r /etc
/rc.subr
]; then
305 # This is RC-NG, pick up our values
308 rcvar
="smartd_enable"
309 command="$SMARTD_BIN"
311 elif [ -r /etc
/defaults
/rc.conf
]; then
312 # Not a 5.x system, try the default location for variables
313 .
/etc
/defaults
/rc.conf
315 elif [ -r /etc
/rc.conf
]; then
316 # Worst case, fallback to system config file
320 if [ -r /etc
/rc.subr
]; then
321 # Use new functionality from RC-NG
324 PID_FILE
=/var
/run
/smartd.pid
327 $SMARTD_BIN -p $PID_FILE $smartd_flags
340 echo "Usage: smartd {start|stop|restart}"
346 elif uname
-a |
grep SunOS
> /dev
/null
2>&1 ; then
348 # Source configuration file. This should define the shell variable smartd_opts.
349 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
350 # of path for Solaris
352 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
354 PID_FILE
=/var
/run
/smartd.pid
358 $SMARTD_BIN -p $PID_FILE $smartd_opts
362 [ -f $PID_FILE ] && kill `cat $PID_FILE`
371 echo "Usage: smartd {start|stop|restart}"
378 elif uname |
grep -i CYGWIN
> /dev
/null
2>&1 ; then
380 # The following settings may be changed by the configuration file below
381 # Service Name (must be unique)
382 smartd_svcname
=smartd
383 # Service display name
384 smartd_svcdisp
="CYGWIN smartd"
385 # Service description
387 Controls and monitors storage devices using the Self-Monitoring \
388 Analysis and Reporting Technology System (S.M.A.R.T.) \
389 built into ATA and SCSI Hard Drives. \
390 http://smartmontools.sourceforge.net/"
392 # Source configuration file. This should define the shell variable smartd_opts.
393 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
396 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
398 PID_FILE
=/var
/run
/smartd.pid
401 # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may
402 # return success even if the file is present but cannot be read by current user.
403 # If smartd is running as service, smartd.pid is owned by local system account
404 # which is different from any user ever executing this script.
408 if cygrunsrv
-L 2>/dev
/null |
grep "^${smartd_svcname}$" >/dev
/null
2>&1; then
409 echo -n "Starting service $smartd_svcname: "
410 cygrunsrv
-S "$smartd_svcname"
412 echo -n "Starting smartd as daemon: "
413 $SMARTD_BIN -p $PID_FILE $smartd_opts
418 echo -n "Shutting down smartd: "
419 pid
="`cat $PID_FILE 2>/dev/null`" && kill "$pid"
423 echo -n "Reloading smartd configuration: "
424 pid
="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid"
428 echo -n "Checking SMART devices now: "
429 pid
="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid"
440 [ $# -eq 0 ] || smartd_opts
="$*"
442 if cygrunsrv
-L 2>/dev
/null |
grep "^syslogd$" >/dev
/null
2>&1; then
445 echo "Warning: syslogd service not installed, smartd will write to windows event log.";
447 echo "Installing service ${smartd_svcname}${smartd_opts+ with options '$smartd_opts'}:"
448 cygrunsrv
-I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" $dep \
449 -e CYGWIN
="$CYGWIN" -p $SMARTD_BIN -a "--service -p ${PID_FILE}${smartd_opts+ }$smartd_opts"
453 echo "Removing service $smartd_svcname:"
454 cygrunsrv
-R "$smartd_svcname"
458 echo -n "Checking smartd status: "
459 if cygrunsrv
-L 2>/dev
/null |
grep "^${smartd_svcname}$" >/dev
/null
2>&1; then
460 if cygrunsrv
-Q "$smartd_svcname" 2>/dev
/null |
grep "State *: Running" >/dev
/null
2>&1; then
461 echo "running as service '$smartd_svcname'."
462 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
463 echo "installed as service '$smartd_svcname' but running as daemon."
465 echo "installed as service '$smartd_svcname' but not running."
468 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
469 echo "running as daemon."
477 echo "Usage: $0 {start|stop|restart|reload|report|status}"
478 echo " $0 {install [options]|remove}"
482 if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi
485 # Add other OSes HERE, using elif...
487 report_unsupported
"Unknown"
490 # One should NEVER arrive here, except for a badly written case above,
491 # that fails to exit.
492 echo "SOMETHING IS WRONG WITH THE SMARTD STARTUP SCRIPT"
493 echo "PLEASE CONTACT smartmontools-support@lists.sourceforge.net"