]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - smartd.initd.in
Merge branch 'upstream'
[mirror_smartmontools-debian.git] / smartd.initd.in
1 #! /bin/sh
2
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 $
6
7 # For RedHat and cousins:
8 # chkconfig: 2345 40 40
9 # description: Self Monitoring and Reporting Technology (SMART) Daemon
10 # processname: smartd
11
12 # For SuSE and cousins
13 ### BEGIN INIT INFO
14 # Provides: smartd
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
21 # Default-Stop:
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.
24 ### END INIT INFO
25
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
29 # version.
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/.
37
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"
42
43 SMARTD_BIN=/usr/local/sbin/smartd
44
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."
50 exit 1
51 }
52
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
55
56 # Source function library
57 . /etc/rc.d/init.d/functions
58
59 # Source configuration file. This should define the shell variable smartd_opts
60 [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
61
62 RETVAL=0
63
64 prog=smartd
65
66 case "$1" in
67 start)
68 echo -n $"Starting $prog: "
69 daemon $SMARTD_BIN $smartd_opts
70 touch /var/lock/subsys/smartd
71 echo
72 ;;
73 stop)
74 echo -n $"Shutting down $prog: "
75 killproc $SMARTD_BIN
76 rm -f /var/lock/subsys/smartd
77 echo
78 ;;
79 reload)
80 echo -n $"Reloading $prog daemon configuration: "
81 killproc $SMARTD_BIN -HUP
82 RETVAL=$?
83 echo
84 ;;
85 report)
86 echo -n $"Checking SMART devices now: "
87 killproc $SMARTD_BIN -USR1
88 RETVAL=$?
89 echo
90 ;;
91 restart)
92 $0 stop
93 $0 start
94 ;;
95 status)
96 status $prog
97 ;;
98 *)
99 echo $"Usage: $0 {start|stop|reload|report|restart|status}"
100 RETVAL=1
101 esac
102
103 exit $RETVAL
104
105 # Slackware
106 elif [ -f /etc/slackware-version ] ; then
107
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.
111
112 [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
113
114 case "$1" in
115 start)
116 echo -n "Starting smartd: "
117 $SMARTD_BIN $smartd_opts
118 echo
119 ;;
120 stop)
121 echo -n "Shutting down smartd: "
122 killall $SMARTD_BIN
123 echo
124 ;;
125 restart)
126 $0 stop
127 sleep 1
128 $0 start
129 ;;
130 *)
131 echo "Usage: smartd {start|stop|restart}"
132 exit 1
133 esac
134
135 exit 0
136
137 # SuSE
138 elif [ -f /etc/SuSE-release ] ; then
139 test -x $SMARTD_BIN || exit 5
140
141 # Existence of config file is optional
142 SMARTD_CONFIG=/etc/smartd.conf
143
144 # source configuration file. This should set the shell variable smartd_opts
145 [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
146
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
155 . /etc/rc.status
156
157 # First reset status of this service
158 rc_reset
159
160 # Return values acc. to LSB for all commands but status:
161 # 0 - success
162 # 1 - misc error
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
168 #
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.
173 case "$1" in
174 start)
175 echo -n "Starting smartd "
176 ## Start daemon with startproc(8). If this fails
177 ## the echo return value is set appropriate.
178
179 # startproc should return 0, even if service is
180 # already running to match LSB spec.
181 startproc $SMARTD_BIN $smartd_opts
182
183 # Remember status and be verbose
184 rc_status -v
185 ;;
186 stop)
187 echo -n "Shutting down smartd "
188 killproc -TERM $SMARTD_BIN
189
190 # Remember status and be verbose
191 rc_status -v
192 ;;
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}"
199 fi
200 $0 status
201 if test $? = 0; then
202 $0 restart
203 else
204 rc_reset # Not running is not a failure.
205 fi
206 # Remember status and be quiet
207 rc_status
208 ;;
209 restart | force-reload)
210 $0 stop
211 $0 start
212 ;;
213 reload)
214 ## Like force-reload, but if daemon does not support
215 ## signaling, do nothing (!)
216 rc_failed 3
217 rc_status -v
218 ;;
219 status)
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.
223
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
229
230 # NOTE: checkproc returns LSB compliant status values.
231 checkproc $SMARTD_BIN
232 rc_status -v
233 ;;
234 probe)
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)
238
239 test $SMARTD_CONFIG -nt /var/run/smartd.pid && echo reload
240 ;;
241 *)
242 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
243 exit 1
244 ;;
245 esac
246
247 rc_exit
248
249 # Debian case
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
254 RET=0
255
256 # source configuration file
257 [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
258
259 smartd_opts="--pidfile $SMARTDPID $smartd_opts"
260
261 case "$1" in
262 start)
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
266 echo "."
267 else
268 echo " (failed)"
269 RET=1
270 fi
271 ;;
272 stop)
273 echo -n "Stopping S.M.A.R.T. daemon: smartd"
274 start-stop-daemon --stop --quiet --oknodo --pidfile $SMARTDPID
275 echo "."
276 ;;
277 restart|force-reload)
278 $0 stop
279 $0 start
280 ;;
281 *)
282 echo "Usage: /etc/init.d/smartmontools {start|stop|restart|force-reload}"
283 exit 1
284 esac
285 exit $RET
286
287 elif [ -f /etc/gentoo-release ] ; then
288 report_unsupported "Gentoo"
289
290 elif [ -f /etc/turbolinux-release ] ; then
291 report_unsupported "Turbolinux"
292
293 elif [ -f /etc/environment.corel ] ; then
294 report_unsupported "Corel"
295
296 # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif
297
298 elif uname -a | grep FreeBSD > /dev/null 2>&1 ; then
299 # following is replaced by port install
300 PREFIX=@@PREFIX@@
301
302 # Updated to try both the RCNG version of things from 5.x, or fallback to
303 # oldfashioned rc.conf
304
305 if [ -r /etc/rc.subr ]; then
306 # This is RC-NG, pick up our values
307 . /etc/rc.subr
308 name="smartd"
309 rcvar="smartd_enable"
310 command="$SMARTD_BIN"
311 load_rc_config $name
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
315 source_rc_confs
316 elif [ -r /etc/rc.conf ]; then
317 # Worst case, fallback to system config file
318 . /etc/rc.conf
319 fi
320
321 if [ -r /etc/rc.subr ]; then
322 # Use new functionality from RC-NG
323 run_rc_command "$1"
324 else
325 PID_FILE=/var/run/smartd.pid
326 case "$1" in
327 start)
328 $SMARTD_BIN -p $PID_FILE $smartd_flags
329 echo -n " smartd"
330 ;;
331 stop)
332 kill `cat $PID_FILE`
333 echo -n " smartd"
334 ;;
335 restart)
336 $0 stop
337 sleep 1
338 $0 start
339 ;;
340 *)
341 echo "Usage: smartd {start|stop|restart}"
342 exit 1
343 esac
344
345 exit 0
346 fi
347 elif uname -a | grep SunOS > /dev/null 2>&1 ; then
348
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
352
353 [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
354
355 PID_FILE=/var/run/smartd.pid
356
357 case "$1" in
358 start)
359 $SMARTD_BIN -p $PID_FILE $smartd_opts
360 echo -n "smartd "
361 ;;
362 stop)
363 [ -f $PID_FILE ] && kill `cat $PID_FILE`
364 echo -n "smartd "
365 ;;
366 restart)
367 $0 stop
368 sleep 1
369 $0 start
370 ;;
371 *)
372 echo "Usage: smartd {start|stop|restart}"
373 exit 1
374 esac
375
376 exit 0
377
378 # Cygwin
379 elif uname | grep -i CYGWIN > /dev/null 2>&1 ; then
380
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
387 smartd_svcdesc="\
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/"
392
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
395 # of path for Cygwin
396
397 [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
398
399 PID_FILE=/var/run/smartd.pid
400 RETVAL=0
401
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.
406
407 case "$1" in
408 start)
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"
412 else
413 echo -n "Starting smartd as daemon: "
414 $SMARTD_BIN -p $PID_FILE $smartd_opts
415 fi
416 RETVAL=$?
417 ;;
418 stop)
419 echo -n "Shutting down smartd: "
420 pid="`cat $PID_FILE 2>/dev/null`" && kill "$pid"
421 RETVAL=$?
422 ;;
423 reload)
424 echo -n "Reloading smartd configuration: "
425 pid="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid"
426 RETVAL=$?
427 ;;
428 report)
429 echo -n "Checking SMART devices now: "
430 pid="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid"
431 RETVAL=$?
432 ;;
433 restart)
434 $0 stop
435 sleep 1
436 $0 start
437 exit $?
438 ;;
439 install)
440 shift
441 [ $# -eq 0 ] || smartd_opts="$*"
442 dep=
443 if cygrunsrv -L 2>/dev/null | grep "^syslogd$" >/dev/null 2>&1; then
444 dep="-y syslogd"
445 else
446 echo "Warning: syslogd service not installed, smartd will write to windows event log.";
447 fi
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"
451 RETVAL=$?
452 ;;
453 remove)
454 echo "Removing service $smartd_svcname:"
455 cygrunsrv -R "$smartd_svcname"
456 RETVAL=$?
457 ;;
458 status)
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."
465 else
466 echo "installed as service '$smartd_svcname' but not running."
467 RETVAL=1
468 fi
469 elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then
470 echo "running as daemon."
471 else
472 echo "not running."
473 RETVAL=1
474 fi
475 exit $RETVAL
476 ;;
477 *)
478 echo "Usage: $0 {start|stop|restart|reload|report|status}"
479 echo " $0 {install [options]|remove}"
480 exit 1
481 esac
482
483 if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi
484 exit $RETVAL
485
486 # Add other OSes HERE, using elif...
487 else
488 report_unsupported "Unknown"
489 fi
490
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"
495 exit 1