3 # smartmontools init.d startup script
5 # (C) 2003,04,07 Guido Günther <agx@sigxcpu.org>
7 # loosely based on the init script that comes with smartmontools which is
8 # copyrighted 2002 by Bruce Allen <smartmontools-support@lists.sourceforge.net>
11 # Provides: smartmontools
12 # Required-Start: $syslog $remote_fs
13 # Required-Stop: $syslog $remote_fs
14 # Default-Start: 2 3 4 5
16 # Short-Description: SMART monitoring daemon
19 SMARTCTL
=/usr
/sbin
/smartctl
20 DAEMON
=/usr
/sbin
/smartd
21 PIDFILE
=/var
/run
/smartd.pid
22 [ -x $SMARTCTL ] ||
exit 0
23 [ -x $DAEMON ] ||
exit 0
24 .
/lib
/lsb
/init-functions
28 [ -r /etc
/default
/rcS
] && .
/etc
/default
/rcS
29 [ -r /etc
/default
/smartmontools
] && .
/etc
/default
/smartmontools
31 smartd_opts
="--pidfile $PIDFILE $smartd_opts"
34 log_action_begin_msg
"Enabling S.M.A.R.T."
35 for device
in $enable_smart; do
36 log_action_cont_msg
"$device"
37 if ! $SMARTCTL --quietmode=errorsonly
--smart=on
$device; then
38 log_action_cont_msg
"(failed)"
45 check_start_smartd_option
() {
46 if [ ! "$start_smartd" = "yes" ]; then
47 [ "$VERBOSE" = "yes" ] && log_warning_msg
"Not starting S.M.A.R.T. daemon smartd, disabled via /etc/default/smartmontools"
56 # Check if a given process pid's cmdline matches a given name
59 [ -z "$pid" ] && return 1
60 [ ! -d /proc
/$pid ] && return 1
61 cmd
=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
62 # Is this the expected child?
63 [ "$cmd" != "$name" ] && return 1
69 # Check if the process is running looking at /proc
70 # (works for all users)
71 # No pidfile, probably no daemon present
72 [ ! -f "$PIDFILE" ] && return 1
73 # Obtain the pid and check it against the binary name
75 running_pid
$pid $DAEMON ||
return 1
81 [ -n "$enable_smart" ] && enable_smart
82 if check_start_smartd_option
; then
84 log_daemon_msg
"Starting S.M.A.R.T. daemon" "smartd"
86 log_progress_msg
"already running"
91 if start-stop-daemon
--start --quiet --pidfile $PIDFILE \
92 --exec $DAEMON -- $smartd_opts; then
101 log_daemon_msg
"Stopping S.M.A.R.T. daemon" "smartd"
102 start-stop-daemon
--stop --quiet --oknodo --pidfile $PIDFILE
106 log_daemon_msg
"Reloading S.M.A.R.T. daemon" "smartd"
107 if start-stop-daemon
--stop --quiet --signal 1 \
108 --pidfile $PIDFILE; then
116 if check_start_smartd_option
; then
117 log_daemon_msg
"Restarting S.M.A.R.T. daemon" "smartd"
118 start-stop-daemon
--stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
120 if start-stop-daemon
--start --quiet --pidfile $PIDFILE \
121 --exec $DAEMON -- $smartd_opts; then
130 status_of_proc
$DAEMON smartd
&& exit 0 ||
exit $?
133 echo "Usage: /etc/init.d/smartmontools {start|stop|restart|reload|force-reload|status}"