3 # Author: Petter Reinholdtsen <pere@hungry.com>
4 # License: GNU General Public License v2 or later
7 # Provides: mpt-statusd
8 # Required-Start: $remote_fs $syslog
9 # Required-Stop: $remote_fs $syslog
10 # Default-Start: 2 3 4 5
12 # Short-Description: Check mpt-status values in the background.
15 PATH=/sbin:/bin:/usr/sbin:/usr/bin
16 DESC="mpt-status monitor"
18 PIDFILE=/var/run/$NAME.pid
19 STATUSFILE=/var/run/$NAME.status
20 SCRIPTNAME=/etc/init.d/$NAME
23 # Do not touch you can configure this in /etc/default/mpt-statusd
24 MAILTO=root # Where to report problems
25 PERIOD=600 # Seconds between each check (default 10 minutes)
26 REMIND=7200 # Seconds between each reminder (default 2 hours)
30 [ -e /etc/default/mpt-statusd ] && . /etc/default/mpt-statusd
32 # Gracefully exit if the package has been removed.
33 test -x /usr/sbin/mpt-status || exit 0
35 . /lib/lsb/init-functions
36 [ -e /etc/default/rcS ] && . /etc/default/rcS
38 if [ $RUN_DAEMON = "no" ] ; then
39 log_begin_msg "mpt-statusd is disabled in /etc/default/mpt-statusd, not starting."
44 if ! [ -e "/proc/mpt/version" ] ; then
45 log_failure_msg "The mptctl module is missing. Please have a look at the README.Debian.gz."
51 echo $$ > $PIDFILE.new && mv $PIDFILE.new $PIDFILE
53 # Check ever $PERIOD seconds, send email on every status
54 # change and repeat ever $REMIND seconds if the raid is still
56 if (mpt-status -i $ID) |grep -q 'state OPTIMAL' ; then
60 logger -t mpt-statusd "detected non-optimal RAID status"
63 if [ true = "$BADRAID" ] ; then
65 (mpt-status -i $ID) > $STATUSFILE.new
66 if [ ! -f $STATUSFILE ] ; then # RAID just became broken
68 mv $STATUSFILE.new $STATUSFILE
69 elif cmp -s $STATUSFILE $STATUSFILE.new ; then
70 # No change. Should we send reminder?
71 LASTTIME="`stat -c '%Z' $STATUSFILE`"
73 SINCELAST="`expr $NOW - $LASTTIME`"
74 if [ $REMIND -le "$SINCELAST" ]; then
75 # Time to send reminder
77 mv $STATUSFILE.new $STATUSFILE
83 mv $STATUSFILE.new $STATUSFILE
87 if [ -f $STATUSFILE ] ; then
93 if [ true = "$STATUSCHANGE" ]; then
97 This is a RAID status update from mpt-statusd. The mpt-status
98 program reports that one of the RAIDs changed state:
101 if [ -f $STATUSFILE ] ; then
107 echo "Report from $0 on $hostname"
108 ) | mail -s "info: mpt raid status change on $hostname" $MAILTO
115 # Let's check if there is a daemon which is really running and not timing out
116 DAEMON_RUN=`ps aux | grep "/etc/init.d/mpt-statusd check_mpt" | grep -v grep | grep -v daemon`
117 if [ -n "$DAEMON_RUN" ] ; then
125 # Function that starts the daemon/service.
128 [ -f $PIDFILE ] && PID="`cat $PIDFILE`"
130 log_progress_msg "Daemon already running. Refusing to start another"
132 elif check_daemon ; then
133 # Use the daemon package to turn this script into a daemon
134 start-stop-daemon --start --quiet --pidfile $PIDFILE \
135 --oknodo --exec /usr/bin/daemon /usr/bin/daemon $SCRIPTNAME check_mpt
138 log_progress_msg "Daemon is already running. Refusing to start another"
144 # Function that stops the daemon/service.
147 if [ -f $PIDFILE ] ; then
148 start-stop-daemon --stop --oknodo --quiet --pidfile $PIDFILE > /dev/null 2>&1
151 log_progress_msg "Daemon is already stopped."
156 # This is a workaround function which does not directly exit and
157 # therefore can be used by a restart
158 d_stop_by_restart() {
159 if [ -f $PIDFILE ] ; then
160 start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE
164 log_progress_msg "Daemon is already stopped."
172 log_begin_msg "Starting $DESC: $NAME"
177 log_begin_msg "Stopping $DESC: $NAME"
184 restart|force-reload)
185 log_begin_msg "Restarting $DESC: $NAME"
192 # echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
193 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2