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
/smartmontools
] && .
/etc
/default
/smartmontools
30 smartd_opts
="--pidfile $PIDFILE $smartd_opts"
33 log_action_begin_msg
"Enabling S.M.A.R.T."
34 for device
in $enable_smart; do
35 log_action_cont_msg
"$device"
36 if ! $SMARTCTL --quietmode=errorsonly
--smart=on
$device; then
37 log_action_cont_msg
"(failed)"
44 check_start_smartd_option
() {
45 if [ ! "$start_smartd" = "yes" ]; then
46 log_warning_msg
"Not starting S.M.A.R.T. daemon smartd, disabled via /etc/default/smartmontools"
55 # Check if a given process pid's cmdline matches a given name
58 [ -z "$pid" ] && return 1
59 [ ! -d /proc
/$pid ] && return 1
60 cmd
=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
61 # Is this the expected child?
62 [ "$cmd" != "$name" ] && return 1
68 # Check if the process is running looking at /proc
69 # (works for all users)
70 # No pidfile, probably no daemon present
71 [ ! -f "$PIDFILE" ] && return 1
72 # Obtain the pid and check it against the binary name
74 running_pid
$pid $DAEMON ||
return 1
80 [ -n "$enable_smart" ] && enable_smart
81 if check_start_smartd_option
; then
83 log_daemon_msg
"Starting S.M.A.R.T. daemon" "smartd"
85 log_progress_msg
"already running"
90 if start-stop-daemon
--start --quiet --pidfile $PIDFILE \
91 --exec $DAEMON -- $smartd_opts; then
100 log_daemon_msg
"Stopping S.M.A.R.T. daemon" "smartd"
101 start-stop-daemon
--stop --quiet --oknodo --pidfile $PIDFILE
105 log_daemon_msg
"Reloading S.M.A.R.T. daemon" "smartd"
106 if start-stop-daemon
--stop --quiet --signal 1 \
107 --pidfile $PIDFILE; then
115 if check_start_smartd_option
; then
116 log_daemon_msg
"Restarting S.M.A.R.T. daemon" "smartd"
117 start-stop-daemon
--stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
119 if start-stop-daemon
--start --quiet --pidfile $PIDFILE \
120 --exec $DAEMON -- $smartd_opts; then
129 status_of_proc
$DAEMON smartd
&& exit 0 ||
exit $?
132 echo "Usage: /etc/init.d/smartmontools {start|stop|restart|reload|force-reload|status}"