]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - smartd.initd.in
import smartmontools 7.0
[mirror_smartmontools-debian.git] / smartd.initd.in
CommitLineData
832b75ed
GG
1#! /bin/sh
2
3# smartmontools init file for smartd
f9e10201 4# Copyright (C) 2002-8 Bruce Allen
ff28b140
TL
5# SPDX-License-Identifier: GPL-2.0-or-later
6# $Id: smartd.initd.in 4760 2018-08-19 18:45:53Z chrfranke $
832b75ed
GG
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
34ad0c5f 15# Provides: smartd
a7e8ffec
GI
16# Required-Start: $syslog $remote_fs
17# Should-Start: sendmail
18# Required-Stop: $syslog $remote_fs
19# Should-Stop: sendmail
34ad0c5f 20# Default-Start: 2 3 5
832b75ed 21# Default-Stop:
34ad0c5f
GG
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.
832b75ed
GG
24### END INIT INFO
25
832b75ed
GG
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
31SMARTD_BIN=/usr/local/sbin/smartd
32
33report_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"
f9e10201 37 echo "smartmontools-support@listi.jpberlin.de."
832b75ed
GG
38 exit 1
39}
40
41# Red Hat or Yellow Dog or Mandrake
42if [ -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
a7e8ffec
GI
43
44 # Source function library
832b75ed
GG
45 . /etc/rc.d/init.d/functions
46
a7e8ffec 47 # Source configuration file. This should define the shell variable smartd_opts
832b75ed 48 [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
a7e8ffec 49
832b75ed 50 RETVAL=0
a7e8ffec 51
832b75ed 52 prog=smartd
a7e8ffec
GI
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
832b75ed
GG
98 case "$1" in
99 start)
a7e8ffec
GI
100 start
101 ;;
832b75ed 102 stop)
a7e8ffec
GI
103 stop
104 ;;
832b75ed 105 reload)
a7e8ffec
GI
106 reload
107 ;;
832b75ed 108 report)
a7e8ffec
GI
109 report
110 ;;
832b75ed 111 restart)
a7e8ffec
GI
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 ;;
832b75ed 124 status)
a7e8ffec
GI
125 status $prog
126 RETVAL=$?
127 ;;
832b75ed 128 *)
a7e8ffec
GI
129 echo $"Usage: $0 {start|stop|restart|status|condrestart|try-restart|reload|force-reload|report}"
130 RETVAL=2
131 [ "$1" = 'usage' ] && RETVAL=0
832b75ed 132 esac
832b75ed
GG
133 exit $RETVAL
134
135# Slackware
136elif [ -f /etc/slackware-version ] ; then
a7e8ffec
GI
137
138 # Source configuration file. This should define the shell variable smartd_opts.
f9e10201 139 # Email smartmontools-support mailing list if there is a better choice
a7e8ffec 140 # of path for Slackware.
832b75ed
GG
141
142 [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
143
a7e8ffec 144 RETVAL=0
832b75ed
GG
145 case "$1" in
146 start)
147 echo -n "Starting smartd: "
148 $SMARTD_BIN $smartd_opts
a7e8ffec 149 RETVAL=$?
832b75ed
GG
150 echo
151 ;;
152 stop)
153 echo -n "Shutting down smartd: "
154 killall $SMARTD_BIN
a7e8ffec 155 RETVAL=$?
832b75ed
GG
156 echo
157 ;;
158 restart)
159 $0 stop
160 sleep 1
161 $0 start
a7e8ffec
GI
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
832b75ed
GG
193 ;;
194 *)
a7e8ffec
GI
195 echo "Usage: $0 {start|stop|restart|try-restart|force-reload|reload|report|status}"
196 RETVAL=1
832b75ed 197 esac
a7e8ffec
GI
198 exit $RETVAL
199
832b75ed
GG
200# SuSE
201elif [ -f /etc/SuSE-release ] ; then
202 test -x $SMARTD_BIN || exit 5
a7e8ffec 203
832b75ed
GG
204 # Existence of config file is optional
205 SMARTD_CONFIG=/etc/smartd.conf
206
a7e8ffec
GI
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
ee38a438
GI
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
832b75ed 228
a7e8ffec
GI
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
832b75ed 241 . /etc/rc.status
a7e8ffec
GI
242
243 # Reset status of this service
832b75ed 244 rc_reset
a7e8ffec
GI
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
832b75ed
GG
262 case "$1" in
263 start)
ba59cff1 264 echo -n "Starting smartd "
a7e8ffec
GI
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
ee38a438 270 eval $SMARTD_BIN$smartd_opts
a7e8ffec
GI
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
832b75ed
GG
281 ;;
282 stop)
ba59cff1 283 echo -n "Shutting down smartd "
a7e8ffec
GI
284 /sbin/killproc -TERM $SMARTD_BIN
285 # Remember status and be verbose
286 rc_status -v
832b75ed 287 ;;
a7e8ffec 288 try-restart)
ba59cff1
GG
289 ## Do a restart only if the service was active before.
290 ## Note: try-restart is now part of LSB (as of 1.9).
ba59cff1
GG
291 $0 status
292 if test $? = 0; then
a7e8ffec
GI
293 $0 restart
294 else
295 rc_reset # Not running is not a failure.
ba59cff1
GG
296 fi
297 # Remember status and be quiet
298 rc_status
299 ;;
a7e8ffec 300 restart)
832b75ed
GG
301 $0 stop
302 $0 start
a7e8ffec
GI
303 # Remember status and be quiet
304 rc_status
832b75ed 305 ;;
a7e8ffec
GI
306 force-reload|reload)
307 echo -n "Reload service smartd "
308 /sbin/killproc -HUP $SMARTD_BIN
832b75ed
GG
309 rc_status -v
310 ;;
a7e8ffec
GI
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)
832b75ed
GG
335 ## Optional: Probe for the necessity of a reload, print out the
336 ## argument to this init script which is required for a reload.
a7e8ffec 337 ## Note: probe is not (yet) part of LSB (as of 1.9)
832b75ed
GG
338
339 test $SMARTD_CONFIG -nt /var/run/smartd.pid && echo reload
340 ;;
341 *)
a7e8ffec 342 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|report|probe}"
832b75ed 343 exit 1
832b75ed 344 esac
832b75ed
GG
345 rc_exit
346
347# Debian case
348elif [ -f /etc/debian_version ] ; then
a7e8ffec
GI
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
832b75ed 357
a7e8ffec 358 smartd_opts="--pidfile $SMARTDPID $smartd_opts"
832b75ed 359
a7e8ffec 360 case "$1" in
832b75ed
GG
361 start)
362 echo -n "Starting S.M.A.R.T. daemon: smartd"
363 if start-stop-daemon --start --quiet --pidfile $SMARTDPID \
a7e8ffec
GI
364 --exec $SMARTD_BIN -- $smartd_opts; then
365 echo "."
832b75ed 366 else
a7e8ffec 367 echo " (failed)"
832b75ed 368 RET=1
a7e8ffec
GI
369 fi
370 ;;
832b75ed
GG
371 stop)
372 echo -n "Stopping S.M.A.R.T. daemon: smartd"
373 start-stop-daemon --stop --quiet --oknodo --pidfile $SMARTDPID
374 echo "."
a7e8ffec
GI
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}"
832b75ed 413 exit 1
a7e8ffec
GI
414 esac
415 exit $RET
832b75ed
GG
416
417elif [ -f /etc/gentoo-release ] ; then
418 report_unsupported "Gentoo"
419
420elif [ -f /etc/turbolinux-release ] ; then
421 report_unsupported "Turbolinux"
422
423elif [ -f /etc/environment.corel ] ; then
424 report_unsupported "Corel"
425
426# PLEASE ADD OTHER LINUX DISTRIBUTIONS JUST BEFORE THIS LINE, USING elif
427
832b75ed 428elif uname -a | grep SunOS > /dev/null 2>&1 ; then
a7e8ffec
GI
429
430 # Source configuration file. This should define the shell variable smartd_opts.
f9e10201 431 # Email smartmontools-support mailing list if there is a better choice
a7e8ffec 432 # of path for Solaris
832b75ed
GG
433
434 [ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
435
436 PID_FILE=/var/run/smartd.pid
a7e8ffec 437
832b75ed
GG
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 ;;
a7e8ffec
GI
452 reload)
453 kill -s HUP `cat $PID_FILE`
454 ;;
455 report)
456 kill -s USR1 `cat $PID_FILE`
457 ;;
832b75ed 458 *)
a7e8ffec 459 echo "Usage: $0 {start|stop|restart|reload|report}"
832b75ed
GG
460 exit 1
461 esac
832b75ed
GG
462 exit 0
463
832b75ed
GG
464# Add other OSes HERE, using elif...
465else
466 report_unsupported "Unknown"
467fi
468
469# One should NEVER arrive here, except for a badly written case above,
a7e8ffec 470# that fails to exit.
832b75ed 471echo "SOMETHING IS WRONG WITH THE SMARTD STARTUP SCRIPT"
f9e10201 472echo "PLEASE CONTACT smartmontools-support@listi.jpberlin.de"
832b75ed 473exit 1