3 # Author: Petter Reinholdtsen <pere@hungry.com>
4 # Author: Sven Hoexter <sven@timegate.de>
5 # License: GNU General Public License v2 or later
7 # mpt-statusd - Check mpt-status values in the background.
10 # description: Check mpt-status values in the background \
11 # using daemonize and the mpt-status utility.
14 # Provides: mpt-statusd
15 # Required-Start: $remote_fs $syslog
16 # Required-Stop: $remote_fs $syslog
17 # Short-Description: Check mpt-status values in the background.
20 PATH=/sbin:/bin:/usr/sbin:/usr/bin
21 DESC="mpt-status monitor"
23 PIDFILE=/var/run/$NAME.pid
24 STATUSFILE=/var/run/$NAME.status
25 SCRIPTNAME=/etc/init.d/$NAME
26 LOCKFILE=/var/lock/subsys/$NAME
28 # Do not touch you can configure this in /etc/default/mpt-statusd
29 MAILTO=root # Where to report problems
30 PERIOD=600 # Seconds between each check (default 10 minutes)
31 REMIND=7200 # Seconds between each reminder (default 2 hours)
35 [ -e /etc/default/mpt-statusd ] && . /etc/default/mpt-statusd
37 # Gracefully exit if the package has been removed.
38 test -x /usr/sbin/mpt-status || exit 0
40 # Source function library.
41 . /etc/rc.d/init.d/functions
43 if [ $RUN_DAEMON = "no" ] ; then
44 echo "mpt-statusd is disabled in /etc/default/mpt-statusd, not starting." && failure
49 #Try to blindly load the mptctl module
50 modprobe mptctl || true
52 if ! [ -e "/proc/mpt/version" ] ; then
53 echo "The mptctl module is missing." && failure
58 echo $$ > $PIDFILE.new && mv $PIDFILE.new $PIDFILE
60 # Check ever $PERIOD seconds, send email on every status
61 # change and repeat ever $REMIND seconds if the raid is still
63 if (mpt-status -i $ID) |grep -q 'state OPTIMAL' ; then
67 logger -t mpt-statusd "detected non-optimal RAID status"
70 if [ true = "$BADRAID" ] ; then
72 (mpt-status -i $ID) > $STATUSFILE.new
73 if [ ! -f $STATUSFILE ] ; then # RAID just became broken
75 mv $STATUSFILE.new $STATUSFILE
76 elif cmp -s $STATUSFILE $STATUSFILE.new ; then
77 # No change. Should we send reminder?
78 LASTTIME="`stat -c '%Z' $STATUSFILE`"
80 SINCELAST="`expr $NOW - $LASTTIME`"
81 if [ $REMIND -le "$SINCELAST" ]; then
82 # Time to send reminder
84 mv $STATUSFILE.new $STATUSFILE
90 mv $STATUSFILE.new $STATUSFILE
94 if [ -f $STATUSFILE ] ; then
100 if [ true = "$STATUSCHANGE" ]; then
101 hostname="`uname -n`"
104 This is a RAID status update from mpt-statusd. The mpt-status
105 program reports that one of the RAIDs changed state:
108 if [ -f $STATUSFILE ] ; then
114 echo "Report from $0 on $hostname"
115 ) | mail -s "info: mpt raid status change on $hostname" $MAILTO
122 # Let's check if there is a daemon which is really running and not timing out
123 DAEMON_RUN=`ps aux | grep "/etc/init.d/mpt-statusd check_mpt" | grep -v grep | grep -v daemon`
124 if [ -n "$DAEMON_RUN" ] ; then
132 # Function that starts the daemon/service.
135 [ -f $PIDFILE ] && PID="`cat $PIDFILE`"
137 echo "Daemon already running. Refusing to start another" && warning
139 elif check_daemon ; then
140 # Use daemonize to turn it into a daemon and start it with daemon().
141 daemon --pidfile $PIDFILE /usr/sbin/daemonize $SCRIPTNAME check_mpt
143 [ $RETVAL -eq 0 ] && touch $LOCKFILE
146 echo "Daemon is already running. Refusing to start another" && warning
152 # Function that stops the daemon/service.
155 if [ -f $PIDFILE ] ; then
158 if [ $RETVAL -eq 0 ] ; then
159 success "$NAME stopped"
160 rm -f $PIDFILE $LOCKFILE
163 echo "$NAME failed to stop" && failure
167 echo "$NAME is already stopped." && warning
172 # This is a workaround function which does not directly exit and
173 # therefore can be used by a restart
174 d_stop_by_restart() {
175 if [ -f $PIDFILE ] ; then
176 killproc -p $PIDFILE $SCRIPTNAME > /dev/null 2>&1
177 rm -f $PIDFILE $LOCKFILE
179 echo "Daemon is already stopped." && warning
185 echo $"Starting $DESC: $NAME"
190 echo $"Stopping $DESC: $NAME"
197 restart|force-reload)
198 echo "Restarting $DESC: $NAME"
205 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2