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