blob: 7584d0269f9450ff4c16d39bfd0ee27571bcd321 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#!/bin/sh -e
#
# smartmontools init.d startup script
#
# (C) 2003,04,07 Guido G�nther <agx@sigxcpu.org>
#
# loosely based on the init script that comes with smartmontools which is
# copyrighted 2002 by Bruce Allen <smartmontools-support@lists.sourceforge.net>
#
### BEGIN INIT INFO
# Provides: smartmontools
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SMART monitoring daemon
### END INIT INFO
SMARTCTL=/usr/sbin/smartctl
DAEMON=/usr/sbin/smartd
PIDFILE=/var/run/smartd.pid
[ -x $SMARTCTL ] || exit 0
[ -x $DAEMON ] || exit 0
. /lib/lsb/init-functions
RET=0
[ -r /etc/default/rcS ] && . /etc/default/rcS
[ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
smartd_opts="--pidfile $PIDFILE $smartd_opts"
enable_smart() {
log_action_begin_msg "Enabling S.M.A.R.T."
for device in $enable_smart; do
log_action_cont_msg "$device"
if ! $SMARTCTL --quietmode=errorsonly --smart=on $device; then
log_action_cont_msg "(failed)"
RET=2
fi
done
log_action_end_msg 0
}
running_pid()
{
# Check if a given process pid's cmdline matches a given name
pid=$1
name=$2
[ -z "$pid" ] && return 1
[ ! -d /proc/$pid ] && return 1
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
# Is this the expected child?
[ "$cmd" != "$name" ] && return 1
return 0
}
running()
{
# Check if the process is running looking at /proc
# (works for all users)
# No pidfile, probably no daemon present
[ ! -f "$PIDFILE" ] && return 1
# Obtain the pid and check it against the binary name
pid=`cat $PIDFILE`
running_pid $pid $DAEMON || return 1
return 0
}
case "$1" in
start)
[ -n "$enable_smart" ] && enable_smart
log_daemon_msg "Starting S.M.A.R.T. daemon" "smartd"
if running; then
log_progress_msg "already running"
log_end_msg 0
exit 0
fi
rm -f $PIDFILE
if start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $smartd_opts; then
log_end_msg 0
else
log_end_msg 1
RET=1
fi
;;
stop)
log_daemon_msg "Stopping S.M.A.R.T. daemon" "smartd"
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
log_end_msg 0
;;
reload|force-reload)
log_daemon_msg "Reloading S.M.A.R.T. daemon" "smartd"
if start-stop-daemon --stop --quiet --signal 1 \
--pidfile $PIDFILE; then
log_end_msg 0
else
log_end_msg 1
RET=1
fi
;;
restart)
log_daemon_msg "Restarting S.M.A.R.T. daemon" "smartd"
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
rm -f $PIDFILE
if start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $smartd_opts; then
log_end_msg 0
else
log_end_msg 1
RET=1
fi
;;
status)
status_of_proc $DAEMON smartd && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/smartmontools {start|stop|restart|reload|force-reload|status}"
exit 1
esac
exit $RET
|