]>
Commit | Line | Data |
---|---|---|
1 | #! /bin/sh | |
2 | ||
3 | # smartmontools init file for smartd | |
4 | # Copyright (C) 2002-8 Bruce Allen | |
5 | # SPDX-License-Identifier: GPL-2.0-or-later | |
6 | # $Id: smartd.initd.in 4760 2018-08-19 18:45:53Z chrfranke $ | |
7 | ||
8 | # For RedHat and cousins: | |
9 | # chkconfig: 2345 40 40 | |
10 | # description: Self Monitoring and Reporting Technology (SMART) Daemon | |
11 | # processname: smartd | |
12 | ||
13 | # For SuSE and cousins | |
14 | ### BEGIN INIT INFO | |
15 | # Provides: smartd | |
16 | # Required-Start: $syslog $remote_fs | |
17 | # Should-Start: sendmail | |
18 | # Required-Stop: $syslog $remote_fs | |
19 | # Should-Stop: sendmail | |
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 | # Uncomment the line below to pass options to smartd on startup. | |
27 | # Note that distribution specific configuration files like | |
28 | # /etc/{default,sysconfig}/smartmontools might override these | |
29 | #smartd_opts="--interval=1800" | |
30 | ||
31 | SMARTD_BIN=/usr/local/sbin/smartd | |
32 | ||
33 | report_unsupported () { | |
34 | echo "Currently the smartmontools package has no init script for" | |
35 | echo "the $1 OS/distribution. If you can provide one or this" | |
36 | echo "one works after removing some ifdefs, please contact" | |
37 | echo "smartmontools-support@listi.jpberlin.de." | |
38 | exit 1 | |
39 | } | |
40 | ||
41 | # Red Hat or Yellow Dog or Mandrake | |
42 | 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 | |
43 | ||
44 | # Source function library | |
45 | . /etc/rc.d/init.d/functions | |
46 | ||
47 | # Source configuration file. This should define the shell variable smartd_opts | |
48 | [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools | |
49 | ||
50 | RETVAL=0 | |
51 | ||
52 | prog=smartd | |
53 | pidfile=/var/lock/subsys/smartd | |
54 | config=/etc/smartd.conf | |
55 | ||
56 | start() | |
57 | { | |
58 | [ $UID -eq 0 ] || exit 4 | |
59 | [ -x $SMARTD_BIN ] || exit 5 | |
60 | [ -f $config ] || exit 6 | |
61 | echo -n $"Starting $prog: " | |
62 | daemon $SMARTD_BIN $smartd_opts | |
63 | RETVAL=$? | |
64 | echo | |
65 | [ $RETVAL = 0 ] && touch $pidfile | |
66 | return $RETVAL | |
67 | } | |
68 | ||
69 | stop() | |
70 | { | |
71 | [ $UID -eq 0 ] || exit 4 | |
72 | echo -n $"Shutting down $prog: " | |
73 | killproc $SMARTD_BIN | |
74 | RETVAL=$? | |
75 | echo | |
76 | rm -f $pidfile | |
77 | return $RETVAL | |
78 | } | |
79 | ||
80 | reload() | |
81 | { | |
82 | echo -n $"Reloading $prog daemon configuration: " | |
83 | killproc $SMARTD_BIN -HUP | |
84 | RETVAL=$? | |
85 | echo | |
86 | return $RETVAL | |
87 | } | |
88 | ||
89 | report() | |
90 | { | |
91 | echo -n $"Checking SMART devices now: " | |
92 | killproc $SMARTD_BIN -USR1 | |
93 | RETVAL=$? | |
94 | echo | |
95 | return $RETVAL | |
96 | } | |
97 | ||
98 | case "$1" in | |
99 | start) | |
100 | start | |
101 | ;; | |
102 | stop) | |
103 | stop | |
104 | ;; | |
105 | reload) | |
106 | reload | |
107 | ;; | |
108 | report) | |
109 | report | |
110 | ;; | |
111 | restart) | |
112 | stop | |
113 | start | |
114 | ;; | |
115 | condrestart|try-restart) | |
116 | if [ -f $pidfile ]; then | |
117 | stop | |
118 | start | |
119 | fi | |
120 | ;; | |
121 | force-reload) | |
122 | reload || (stop; start) | |
123 | ;; | |
124 | status) | |
125 | status $prog | |
126 | RETVAL=$? | |
127 | ;; | |
128 | *) | |
129 | echo $"Usage: $0 {start|stop|restart|status|condrestart|try-restart|reload|force-reload|report}" | |
130 | RETVAL=2 | |
131 | [ "$1" = 'usage' ] && RETVAL=0 | |
132 | esac | |
133 | exit $RETVAL | |
134 | ||
135 | # Slackware | |
136 | elif [ -f /etc/slackware-version ] ; then | |
137 | ||
138 | # Source configuration file. This should define the shell variable smartd_opts. | |
139 | # Email smartmontools-support mailing list if there is a better choice | |
140 | # of path for Slackware. | |
141 | ||
142 | [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools | |
143 | ||
144 | RETVAL=0 | |
145 | case "$1" in | |
146 | start) | |
147 | echo -n "Starting smartd: " | |
148 | $SMARTD_BIN $smartd_opts | |
149 | RETVAL=$? | |
150 | echo | |
151 | ;; | |
152 | stop) | |
153 | echo -n "Shutting down smartd: " | |
154 | killall $SMARTD_BIN | |
155 | RETVAL=$? | |
156 | echo | |
157 | ;; | |
158 | restart) | |
159 | $0 stop | |
160 | sleep 1 | |
161 | $0 start | |
162 | RETVAL=$? | |
163 | ;; | |
164 | try-restart) | |
165 | if pidof $SMARTD_BIN >/dev/null; then | |
166 | $0 restart | |
167 | RETVAL=$? | |
168 | fi | |
169 | ;; | |
170 | force-reload) | |
171 | $0 reload || $0 restart | |
172 | RETVAL=$? | |
173 | ;; | |
174 | reload) | |
175 | echo -n "Reloading smartd configuration: " | |
176 | killall -s HUP $SMARTD_BIN | |
177 | RETVAL=$? | |
178 | echo | |
179 | ;; | |
180 | report) | |
181 | echo -n "Checking SMART devices now: " | |
182 | killall -s USR1 $SMARTD_BIN | |
183 | RETVAL=$? | |
184 | echo | |
185 | ;; | |
186 | status) | |
187 | if pidof $SMARTD_BIN >/dev/null; then | |
188 | echo "$SMARTD_BIN is running." | |
189 | else | |
190 | echo "$SMARTD_BIN is not running." | |
191 | RETVAL=1 | |
192 | fi | |
193 | ;; | |
194 | *) | |
195 | echo "Usage: $0 {start|stop|restart|try-restart|force-reload|reload|report|status}" | |
196 | RETVAL=1 | |
197 | esac | |
198 | exit $RETVAL | |
199 | ||
200 | # SuSE | |
201 | elif [ -f /etc/SuSE-release ] ; then | |
202 | test -x $SMARTD_BIN || exit 5 | |
203 | ||
204 | # Existence of config file is optional | |
205 | SMARTD_CONFIG=/etc/smartd.conf | |
206 | ||
207 | # source configuration file. | |
208 | [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools | |
209 | smartd_opts= | |
210 | if test -n "$SMARTD_CHECK_INTERVAL" -a "$SMARTD_CHECK_INTERVAL" != 1800 ; then | |
211 | smartd_opts=" -i $SMARTD_CHECK_INTERVAL" | |
212 | fi | |
213 | if test -n "$SMARTD_LOG_FACILITY" -a "$SMARTD_LOG_FACILITY" != "daemon" ; then | |
214 | smartd_opts="$smartd_opts -l $SMARTD_LOG_FACILITY" | |
215 | fi | |
216 | if test -n "$SMARTD_DRIVEDB" ; then | |
217 | smartd_opts="$smartd_opts -B $SMARTD_DRIVEDB" | |
218 | fi | |
219 | if test "$SMARTD_SAVESTATES" = "no" ; then | |
220 | smartd_opts="$smartd_opts -s \"\"" | |
221 | fi | |
222 | if test "$SMARTD_ATTRLOG" = "no" ; then | |
223 | smartd_opts="$smartd_opts -A \"\"" | |
224 | fi | |
225 | if test -n "$SMARTD_EXTRA_OPTS" ; then | |
226 | smartd_opts="$smartd_opts $SMARTD_EXTRA_OPTS" | |
227 | fi | |
228 | ||
229 | # Shell functions sourced from /etc/rc.status: | |
230 | # rc_check check and set local and overall rc status | |
231 | # rc_status check and set local and overall rc status | |
232 | # rc_status -v be verbose in local rc status and clear it afterwards | |
233 | # rc_status -v -r ditto and clear both the local and overall rc status | |
234 | # rc_status -s display "skipped" and exit with status 3 | |
235 | # rc_status -u display "unused" and exit with status 3 | |
236 | # rc_failed set local and overall rc status to failed | |
237 | # rc_failed <num> set local and overall rc status to <num> | |
238 | # rc_reset clear both the local and overall rc status | |
239 | # rc_exit exit appropriate to overall rc status | |
240 | # rc_active checks whether a service is activated by symlinks | |
241 | . /etc/rc.status | |
242 | ||
243 | # Reset status of this service | |
244 | rc_reset | |
245 | ||
246 | # Return values acc. to LSB for all commands but status: | |
247 | # 0 - success | |
248 | # 1 - generic or unspecified error | |
249 | # 2 - invalid or excess argument(s) | |
250 | # 3 - unimplemented feature (e.g. "reload") | |
251 | # 4 - user had insufficient privileges | |
252 | # 5 - program is not installed | |
253 | # 6 - program is not configured | |
254 | # 7 - program is not running | |
255 | # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) | |
256 | # | |
257 | # Note that starting an already running service, stopping | |
258 | # or restarting a not-running service as well as the restart | |
259 | # with force-reload (in case signaling is not supported) are | |
260 | # considered a success. | |
261 | ||
262 | case "$1" in | |
263 | start) | |
264 | echo -n "Starting smartd " | |
265 | ## Start daemon with startproc(8). If this fails | |
266 | ## the return value is set appropriately by startproc. | |
267 | ||
268 | # We don't use startproc - we need to check for return code 17. | |
269 | if ! /sbin/checkproc $SMARTD_BIN ; then | |
270 | eval $SMARTD_BIN$smartd_opts | |
271 | # Remember status and be verbose | |
272 | if test $? -ne 17 ; then | |
273 | rc_status -v | |
274 | else | |
275 | rc_status -u | |
276 | fi | |
277 | else | |
278 | rc_reset | |
279 | rc_status -v | |
280 | fi | |
281 | ;; | |
282 | stop) | |
283 | echo -n "Shutting down smartd " | |
284 | /sbin/killproc -TERM $SMARTD_BIN | |
285 | # Remember status and be verbose | |
286 | rc_status -v | |
287 | ;; | |
288 | try-restart) | |
289 | ## Do a restart only if the service was active before. | |
290 | ## Note: try-restart is now part of LSB (as of 1.9). | |
291 | $0 status | |
292 | if test $? = 0; then | |
293 | $0 restart | |
294 | else | |
295 | rc_reset # Not running is not a failure. | |
296 | fi | |
297 | # Remember status and be quiet | |
298 | rc_status | |
299 | ;; | |
300 | restart) | |
301 | $0 stop | |
302 | $0 start | |
303 | # Remember status and be quiet | |
304 | rc_status | |
305 | ;; | |
306 | force-reload|reload) | |
307 | echo -n "Reload service smartd " | |
308 | /sbin/killproc -HUP $SMARTD_BIN | |
309 | rc_status -v | |
310 | ;; | |
311 | report) | |
312 | ## Checking SMART devices now (smartd specific function) | |
313 | echo -n "Checking SMART devices now " | |
314 | /sbin/killproc -USR1 $SMARTD_BIN | |
315 | rc_status -v | |
316 | ;; | |
317 | status) | |
318 | echo -n "Checking for service smartd " | |
319 | ## Check status with checkproc(8), if process is running | |
320 | ## checkproc will return with exit status 0. | |
321 | ||
322 | # Return value is slightly different for the status command: | |
323 | # 0 - service up and running | |
324 | # 1 - service dead, but /var/run/ pid file exists | |
325 | # 2 - service dead, but /var/lock/ lock file exists | |
326 | # 3 - service not running (unused) | |
327 | # 4 - service status unknown :-( | |
328 | # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) | |
329 | ||
330 | # NOTE: checkproc returns LSB compliant status values. | |
331 | /sbin/checkproc $SMARTD_BIN | |
332 | rc_status -v | |
333 | ;; | |
334 | probe) | |
335 | ## Optional: Probe for the necessity of a reload, print out the | |
336 | ## argument to this init script which is required for a reload. | |
337 | ## Note: probe is not (yet) part of LSB (as of 1.9) | |
338 | ||
339 | test $SMARTD_CONFIG -nt /var/run/smartd.pid && echo reload | |
340 | ;; | |
341 | *) | |
342 | echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|report|probe}" | |
343 | exit 1 | |
344 | esac | |
345 | rc_exit | |
346 | ||
347 | # Debian case | |
348 | elif [ -f /etc/debian_version ] ; then | |
349 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
350 | SMARTDPID=/var/run/smartd.pid | |
351 | [ -x $SMARTD_BIN ] || exit 0 | |
352 | RET=0 | |
353 | ||
354 | # source configuration file | |
355 | [ -r /etc/default/rcS ] && . /etc/default/rcS | |
356 | [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools | |
357 | ||
358 | smartd_opts="--pidfile $SMARTDPID $smartd_opts" | |
359 | ||
360 | case "$1" in | |
361 | start) | |
362 | echo -n "Starting S.M.A.R.T. daemon: smartd" | |
363 | if start-stop-daemon --start --quiet --pidfile $SMARTDPID \ | |
364 | --exec $SMARTD_BIN -- $smartd_opts; then | |
365 | echo "." | |
366 | else | |
367 | echo " (failed)" | |
368 | RET=1 | |
369 | fi | |
370 | ;; | |
371 | stop) | |
372 | echo -n "Stopping S.M.A.R.T. daemon: smartd" | |
373 | start-stop-daemon --stop --quiet --oknodo --pidfile $SMARTDPID | |
374 | echo "." | |
375 | ;; | |
376 | restart) | |
377 | $0 stop | |
378 | $0 start | |
379 | ;; | |
380 | force-reload) | |
381 | $0 reload || $0 restart | |
382 | ;; | |
383 | reload) | |
384 | echo -n "Reload S.M.A.R.T. daemon: smartd" | |
385 | if start-stop-daemon --stop --quiet --signal 1 \ | |
386 | --pidfile $SMARTDPID; then | |
387 | echo "." | |
388 | else | |
389 | echo " (failed)" | |
390 | RET=1 | |
391 | fi | |
392 | ;; | |
393 | report) | |
394 | echo -n "Checking SMART devices now" | |
395 | if start-stop-daemon --stop --quiet --signal 10 \ | |
396 | --pidfile $SMARTDPID; then | |
397 | echo "." | |
398 | else | |
399 | echo " (failed)" | |
400 | RET=1 | |
401 | fi | |
402 | ;; | |
403 | status) | |
404 | if pidof $SMARTD_BIN >/dev/null; then | |
405 | echo "$SMARTD_BIN is running." | |
406 | else | |
407 | echo "$SMARTD_BIN is not running." | |
408 | RET=1 | |
409 | fi | |
410 | ;; | |
411 | *) | |
412 | echo "Usage: $0 {start|stop|restart|force-reload|reload|report|status}" | |
413 | exit 1 | |
414 | esac | |
415 | exit $RET | |
416 | ||
417 | elif [ -f /etc/gentoo-release ] ; then | |
418 | report_unsupported "Gentoo" | |
419 | ||
420 | elif [ -f /etc/turbolinux-release ] ; then | |
421 | report_unsupported "Turbolinux" | |
422 | ||
423 | elif [ -f /etc/environment.corel ] ; then | |
424 | report_unsupported "Corel" | |
425 | ||
426 | # PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif | |
427 | ||
428 | elif uname -a | grep SunOS > /dev/null 2>&1 ; then | |
429 | ||
430 | # Source configuration file. This should define the shell variable smartd_opts. | |
431 | # Email smartmontools-support mailing list if there is a better choice | |
432 | # of path for Solaris | |
433 | ||
434 | [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools | |
435 | ||
436 | PID_FILE=/var/run/smartd.pid | |
437 | ||
438 | case "$1" in | |
439 | start) | |
440 | $SMARTD_BIN -p $PID_FILE $smartd_opts | |
441 | echo -n "smartd " | |
442 | ;; | |
443 | stop) | |
444 | [ -f $PID_FILE ] && kill `cat $PID_FILE` | |
445 | echo -n "smartd " | |
446 | ;; | |
447 | restart) | |
448 | $0 stop | |
449 | sleep 1 | |
450 | $0 start | |
451 | ;; | |
452 | reload) | |
453 | kill -s HUP `cat $PID_FILE` | |
454 | ;; | |
455 | report) | |
456 | kill -s USR1 `cat $PID_FILE` | |
457 | ;; | |
458 | *) | |
459 | echo "Usage: $0 {start|stop|restart|reload|report}" | |
460 | exit 1 | |
461 | esac | |
462 | exit 0 | |
463 | ||
464 | # Add other OSes HERE, using elif... | |
465 | else | |
466 | report_unsupported "Unknown" | |
467 | fi | |
468 | ||
469 | # One should NEVER arrive here, except for a badly written case above, | |
470 | # that fails to exit. | |
471 | echo "SOMETHING IS WRONG WITH THE SMARTD STARTUP SCRIPT" | |
472 | echo "PLEASE CONTACT smartmontools-support@listi.jpberlin.de" | |
473 | exit 1 |