Mdadm monitor

Descrizione

Script rc per il monitoring del raid, in pratica usa mdadm per fare la lista dei device raid attivi e usa il monitoring di mdadm per tenere sotto controllo i raid attivi con notifica via mail.

#!/bin/sh
# Start/stop/restart mdadm monitor.
#
# Copyright 2006 Davide Consonni, Milano, IT
#
# This program comes with NO WARRANTY, to the extent permitted by law.
# You may redistribute copies of this program under the terms of the
# GNU General Public License.

MD_COMMAND_LINE='--monitor --scan --mail=root@localhost --delay=1800 --daemonise -y'

MD_BIN='/sbin/mdadm'
MD_PID='/var/run/mdadm.pid'

mdadm_start() {
  if [ -f $MD_PID ]; then
    echo "mdadm is already runnig. if not please remove $MD_PID "
  else 
   if [ -x $MD_BIN ]; then
      echo -n "Starting raid monitor:  "

      MD_RAID_DEVICES=''
      for md in $($MD_BIN --detail --scan | awk '{print $2}'); do
        MD_RAID_DEVICES="$MD_RAID_DEVICES $md"
      done

      echo "$MD_BIN $MD_COMMAND_LINE $MD_RAID_DEVICES"
      $MD_BIN $MD_COMMAND_LINE $MD_RAID_DEVICES > $MD_PID
   fi
  fi
}

mdadm_stop() {
  if [ -f $MD_PID ]; then
    echo -n "Stopping raid monitor: "
    kill $(cat $MD_PID)
    echo "Deleting pid file $MD_PID "
    rm $MD_PID
  fi 
}

mdadm_restart() {
  mdadm_stop
  sleep 1
  mdadm_start
}

mdadm_status() {
  if [ -f $MD_PID ]; then
    echo "running"
  else
    echo "stopped"
  fi
}

case "$1" in
'start')
  mdadm_start
  ;;
'stop')
  mdadm_stop
  ;;
'restart')
  mdadm_restart
  ;;
'status')
  mdadm_status
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac

Autore: Davide Consonni