3 # Author: Petter Reinholdtsen <pere@hungry.com>
4 # License: GNU General Public License v2 or later
6 # mpt-statusd - Check mpt-status values in the background.
9 # description: Check mpt-status values in the background \
10 # using daemonize and the mpt-status utility.
13 # Provides: mpt-statusd
14 # Required-Start: $remote_fs $syslog
15 # Required-Stop: $remote_fs $syslog
16 # Default-Start: 2 3 4 5
18 # Short-Description: Check mpt-status values in the background.
21 PATH=/sbin:/bin:/usr/sbin:/usr/bin
22 DESC="mpt-status monitor"
24 PIDFILE=/var/run/$NAME.pid
25 STATUSFILE=/var/run/$NAME.status
26 SCRIPTNAME=/etc/init.d/$NAME
29 # Do not touch you can configure this in /etc/default/mpt-statusd
30 MAILTO=root # Where to report problems
31 PERIOD=600 # Seconds between each check (default 10 minutes)
32 REMIND=7200 # Seconds between each reminder (default 2 hours)
36 [ -e /etc/default/mpt-statusd ] && . /etc/default/mpt-statusd
38 # Gracefully exit if the package has been removed.
39 test -x /usr/sbin/mpt-status || exit 0
41 # Source function library.
42 . /etc/rc.d/init.d/functions
43 . /lib/lsb/init-functions
45 if [ $RUN_DAEMON = "no" ] ; then
46 log_failure_msg $"mpt-statusd is disabled in /etc/default/mpt-statusd, not starting."
51 #Try to blindly load the mptctl module
52 modprobe mptctl || true
54 if ! [ -e "/proc/mpt/version" ] ; then
55 log_failure_msg "The mptctl module is missing."
60 echo $$ > $PIDFILE.new && mv $PIDFILE.new $PIDFILE
62 # Check ever $PERIOD seconds, send email on every status
63 # change and repeat ever $REMIND seconds if the raid is still
65 if (mpt-status -i $ID) |grep -q 'state OPTIMAL' ; then
69 logger -t mpt-statusd "detected non-optimal RAID status"
72 if [ true = "$BADRAID" ] ; then
74 (mpt-status -i $ID) > $STATUSFILE.new
75 if [ ! -f $STATUSFILE ] ; then # RAID just became broken
77 mv $STATUSFILE.new $STATUSFILE
78 elif cmp -s $STATUSFILE $STATUSFILE.new ; then
79 # No change. Should we send reminder?
80 LASTTIME="`stat -c '%Z' $STATUSFILE`"
82 SINCELAST="`expr $NOW - $LASTTIME`"
83 if [ $REMIND -le "$SINCELAST" ]; then
84 # Time to send reminder
86 mv $STATUSFILE.new $STATUSFILE
92 mv $STATUSFILE.new $STATUSFILE
96 if [ -f $STATUSFILE ] ; then
102 if [ true = "$STATUSCHANGE" ]; then
103 hostname="`uname -n`"
106 This is a RAID status update from mpt-statusd. The mpt-status
107 program reports that one of the RAIDs changed state:
110 if [ -f $STATUSFILE ] ; then
116 echo "Report from $0 on $hostname"
117 ) | mail -s "info: mpt raid status change on $hostname" $MAILTO
124 # Let's check if there is a daemon which is really running and not timing out
125 DAEMON_RUN=`ps aux | grep "/etc/init.d/mpt-statusd check_mpt" | grep -v grep | grep -v daemon`
126 if [ -n "$DAEMON_RUN" ] ; then
134 # Function that starts the daemon/service.
137 [ -f $PIDFILE ] && PID="`cat $PIDFILE`"
139 log_warning_msg "Daemon already running. Refusing to start another"
141 elif check_daemon ; then
142 # Use daemonize to turn it into a daemon and start it with daemon().
143 daemon --pidfile $PIDFILE /usr/sbin/daemonize $SCRIPTNAME check_mpt
146 log_warning_msg "Daemon is already running. Refusing to start another"
152 # Function that stops the daemon/service.
155 if [ -f $PIDFILE ] ; then
156 killproc -p $PIDFILE $SCRIPTNAME > /dev/null 2>&1
159 log_warning_msg "Daemon is already stopped."
164 # This is a workaround function which does not directly exit and
165 # therefore can be used by a restart
166 d_stop_by_restart() {
167 if [ -f $PIDFILE ] ; then
168 killproc -p $PIDFILE $SCRIPTNAME > /dev/null 2>&1
171 log_warning_msg "Daemon is already stopped."
178 echo -n $"Starting $DESC: $NAME"
182 echo -n $"Stopping $DESC: $NAME"
188 restart|force-reload)
189 echo -n "Restarting $DESC: $NAME"
195 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2