Sophie

Sophie

distrib > Mandriva > current > i586 > media > contrib-release-src > by-pkgid > 330d23739d2091aabf309a2b6b951b73 > files > 5

megactl-0.4.1-8mdv2010.0.src.rpm

#!/bin/sh

# Author: Adam Cécile <acecile@mandriva.com>
# License: GNU General Public License v2 or later
#
# Based on work by Petter Reinholdtsen <pere@hungry.com>
# In Debian's package "mpt-status"

PATH=/sbin:/bin:/usr/sbin:/usr/bin
STATUSFILE=/var/run/megactl.status
MAILTO=root   # Where to report problems (default root)
REMIND=7200   # Seconds between each reminder (default 2 hours)

. /etc/megactl/megactl-cron.conf

# One line for each broken thing in silent mode
if [ `megactl -H $PARAMS | wc -l` -eq 0 ]; then
  BADRAID=false
else
  BADRAID=true
  logger -t MegaCTL "Detected non-optimal RAID status"
fi
STATUSCHANGE=false
if [ true = "$BADRAID" ] ; then
  # RAID not OK
  (megactl $PARAMS) > $STATUSFILE.new
  if [ ! -f $STATUSFILE ] ; then # RAID just became broken
    STATUSCHANGE=true
    mv $STATUSFILE.new $STATUSFILE
  elif cmp -s $STATUSFILE $STATUSFILE.new ; then
    # No change.  Should we send reminder?
    LASTTIME="`stat -c '%Z' $STATUSFILE`"
    NOW="`date +%s`"
    SINCELAST="`expr $NOW - $LASTTIME`"
    if [ $REMIND -le "$SINCELAST" ]; then
      # Time to send reminder
      STATUSCHANGE=true
      mv $STATUSFILE.new $STATUSFILE
    else
      rm $STATUSFILE.new
    fi
  else
    STATUSCHANGE=true
    mv $STATUSFILE.new $STATUSFILE
  fi
else
  # RAID OK
  if [ -f $STATUSFILE ] ; then
    rm $STATUSFILE
    STATUSCHANGE=true
  fi
fi

if [ true = "$STATUSCHANGE" ]; then
  hostname="`uname -n`"
  (
    cat <<EOF
This is a RAID status update from MegaCTL. 
The MegaCTL program reports that one of the RAIDs changed state:

EOF
    if [ -f $STATUSFILE ] ; then
      cat $STATUSFILE
    else
      (megactl $PARAMS)
    fi
    echo
    echo "Report from MegaCTL on $hostname"
  ) | mail -s "info: MegaCTL raid status change on $hostname" $MAILTO
fi