]>
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.33 2006/04/12 14:54:28 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 # 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 restart | force-reload
)
197 ## Like force-reload, but if daemon does not support
198 ## signaling, do nothing (!)
203 echo -n "Checking for service smartd: "
204 ## Check status with checkproc(8), if process is running
205 ## checkproc will return with exit status 0.
207 # Status has a slightly different for the status command:
208 # 0 - service running
209 # 1 - service dead, but /var/run/ pid file exists
210 # 2 - service dead, but /var/lock/ lock file exists
211 # 3 - service not running
213 # NOTE: checkproc returns LSB compliant status values.
214 checkproc
$SMARTD_BIN
218 ## Optional: Probe for the necessity of a reload, print out the
219 ## argument to this init script which is required for a reload.
220 ## Note: probe is not (yet) part of LSB (as of 1.2)
222 test $SMARTD_CONFIG -nt /var
/run
/smartd.pid
&& echo reload
225 echo "Usage: $0 {start|stop|status|restart|force-reload|reload|probe}"
233 elif [ -f /etc
/debian_version
] ; then
234 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
235 SMARTDPID
=/var
/run
/smartd.pid
236 [ -x $SMARTD_BIN ] ||
exit 0
239 # source configuration file
240 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
242 smartd_opts
="--pidfile $SMARTDPID $smartd_opts"
246 echo -n "Starting S.M.A.R.T. daemon: smartd"
247 if start-stop-daemon
--start --quiet --pidfile $SMARTDPID \
248 --exec $SMARTD_BIN -- $smartd_opts; then
256 echo -n "Stopping S.M.A.R.T. daemon: smartd"
257 start-stop-daemon
--stop --quiet --oknodo --pidfile $SMARTDPID
260 restart|force-reload
)
265 echo "Usage: /etc/init.d/smartmontools {start|stop|restart|force-reload}"
270 elif [ -f /etc
/gentoo-release
] ; then
271 report_unsupported
"Gentoo"
273 elif [ -f /etc
/turbolinux-release
] ; then
274 report_unsupported
"Turbolinux"
276 elif [ -f /etc
/environment.corel
] ; then
277 report_unsupported
"Corel"
279 # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif
281 elif uname
-a |
grep FreeBSD
> /dev
/null
2>&1 ; then
282 # following is replaced by port install
285 # Updated to try both the RCNG version of things from 5.x, or fallback to
286 # oldfashioned rc.conf
288 if [ -r /etc
/rc.subr
]; then
289 # This is RC-NG, pick up our values
292 rcvar
="smartd_enable"
293 command="$SMARTD_BIN"
295 elif [ -r /etc
/defaults
/rc.conf
]; then
296 # Not a 5.x system, try the default location for variables
297 .
/etc
/defaults
/rc.conf
299 elif [ -r /etc
/rc.conf
]; then
300 # Worst case, fallback to system config file
304 if [ -r /etc
/rc.subr
]; then
305 # Use new functionality from RC-NG
308 PID_FILE
=/var
/run
/smartd.pid
311 $SMARTD_BIN -p $PID_FILE $smartd_flags
324 echo "Usage: smartd {start|stop|restart}"
330 elif uname
-a |
grep SunOS
> /dev
/null
2>&1 ; then
332 # Source configuration file. This should define the shell variable smartd_opts.
333 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
334 # of path for Solaris
336 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
338 PID_FILE
=/var
/run
/smartd.pid
342 $SMARTD_BIN -p $PID_FILE $smartd_opts
346 [ -f $PID_FILE ] && kill `cat $PID_FILE`
355 echo "Usage: smartd {start|stop|restart}"
362 elif uname |
grep -i CYGWIN
> /dev
/null
2>&1 ; then
364 # The following settings may be changed by the configuration file below
365 # Service Name (must be unique)
366 smartd_svcname
=smartd
367 # Service display name
368 smartd_svcdisp
="CYGWIN smartd"
369 # Service description
371 Controls and monitors storage devices using the Self-Monitoring \
372 Analysis and Reporting Technology System (S.M.A.R.T.) \
373 built into ATA and SCSI Hard Drives. \
374 http://smartmontools.sourceforge.net/"
376 # Source configuration file. This should define the shell variable smartd_opts.
377 # Email smartmontools-support@lists.sourceforge.net if there is a better choice
380 [ -r /etc
/sysconfig
/smartmontools
] && .
/etc
/sysconfig
/smartmontools
382 PID_FILE
=/var
/run
/smartd.pid
385 # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may
386 # return success even if the file is present but cannot be read by current user.
387 # If smartd is running as service, smartd.pid is owned by local system account
388 # which is different from any user ever executing this script.
392 if cygrunsrv
-L 2>/dev
/null |
grep "^${smartd_svcname}$" >/dev
/null
2>&1; then
393 echo -n "Starting service $smartd_svcname: "
394 cygrunsrv
-S "$smartd_svcname"
396 echo -n "Starting smartd as daemon: "
397 $SMARTD_BIN -p $PID_FILE $smartd_opts
402 echo -n "Shutting down smartd: "
403 pid
="`cat $PID_FILE 2>/dev/null`" && kill "$pid"
407 echo -n "Reloading smartd configuration: "
408 pid
="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid"
412 echo -n "Checking SMART devices now: "
413 pid
="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid"
424 [ $# -eq 0 ] || smartd_opts
="$*"
426 if cygrunsrv
-L 2>/dev
/null |
grep "^syslogd$" >/dev
/null
2>&1; then
429 echo "Warning: syslogd service not installed, smartd will write to windows event log.";
431 echo "Installing service ${smartd_svcname}${smartd_opts+ with options '$smartd_opts'}:"
432 cygrunsrv
-I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" $dep \
433 -e CYGWIN
="$CYGWIN" -p $SMARTD_BIN -a "--service -p ${PID_FILE}${smartd_opts+ }$smartd_opts"
437 echo "Removing service $smartd_svcname:"
438 cygrunsrv
-R "$smartd_svcname"
442 echo -n "Checking smartd status: "
443 if cygrunsrv
-L 2>/dev
/null |
grep "^${smartd_svcname}$" >/dev
/null
2>&1; then
444 if cygrunsrv
-Q "$smartd_svcname" 2>/dev
/null |
grep "State *: Running" >/dev
/null
2>&1; then
445 echo "running as service '$smartd_svcname'."
446 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
447 echo "installed as service '$smartd_svcname' but running as daemon."
449 echo "installed as service '$smartd_svcname' but not running."
452 elif ps
-e 2>/dev
/null |
grep " ${SMARTD_BIN}$" >/dev
/null
2>&1; then
453 echo "running as daemon."
461 echo "Usage: $0 {start|stop|restart|reload|report|status}"
462 echo " $0 {install [options]|remove}"
466 if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi
469 # Add other OSes HERE, using elif...
471 report_unsupported
"Unknown"
474 # One should NEVER arrive here, except for a badly written case above,
475 # that fails to exit.
476 echo "SOMETHING IS WRONG WITH THE SMARTD STARTUP SCRIPT"
477 echo "PLEASE CONTACT smartmontools-support@lists.sourceforge.net"