#!/bin/sh # Script to control mdadm raid array monitoring # Written by John Jenkins mrgoblin@sastk.org # $Id: rc.mdadm 185 2011-05-04 00:14:12Z mrgoblin $ # # Please Note: /etc/rc.d/rc.local is likely the best place to call # this script from. If you do call this at start-up please remember # to also add it to your shutdown scripts or you will be left with # a stale PID file. Using the "fstop" parameter will remove this. # # Set some variables MDPID="" PIDFILE="/var/run/mdadm" CONFIG="/etc/mdadm.conf" PROG="/sbin/mdadm" # you may list each device seperated by spaces DEVICES="/dev/md[0-9]" # Sanity Checks if [ ! -f ${CONFIG} -o ! -x ${PROG} ]; then echo 'Either your mdadm binary or config file is missing! ' echo 'Is Mdadm installed? ' echo exit 1 fi # Get current PID if [ -f /var/run/mdadm ];then MDPID=$(cat /var/run/mdadm) fi # The functions start() { if [ "X${MDPID}" = "X" ];then ${PROG} --monitor --daemonise ${DEVICES} > ${PIDFILE} else echo "Mdadm Monitor already running : " if [ "${MDPID}" != "$(pidof mdadm)" ]; then echo "Removing stale PID file : " if [ -f "${PIDFILE}" ]; then rm -f "${PIDFILE}" fi ${PROG} --monitor --daemonise ${DEVICES} > ${PIDFILE} fi exit 1 fi } stop() { if [ "X${MDPID}" = "X" ];then echo "Mdadm Monitor not running :" exit 1 else echo -n "Stopping Mdadm monitor :" kill -15 ${MDPID} && rm ${PIDFILE} && echo " Success " || echo " Failed to stop Mdadm Monitor " unset MDPID fi } status() { if [ "X${MDPID}" = "X" ];then echo "Mdadm Monitor not running :" ${PROG} -D ${DEVICES} |awk '/(^\/dev|State\ :|Raid\ Level|Array Size|Failed)/ { print $0 }' echo else echo "Mdadm Monitor running on PID ${MDPID} :" ${PROG} -D ${DEVICES} |awk '/(^\/dev|State\ :|Raid\ Level|Array Size|Failed)/ { print $0 }' echo fi } forced_stop() { echo "Forcibly stopping Mmdadm Monitor :" /bin/killall -9 mdadm if [ -f "${PIDFILE}" ]; then rm -f "${PIDFILE}" fi unset MDPID } # Parse input case "$1" in start) start ;; stop) stop ;; restart) stop start ;; fstop) forced_stop ;; status) status ;; *) echo "*** Usage: $0 {start|stop|fstop|restart|status}" exit 1 esac exit 0 # $Id: rc.mdadm 185 2011-05-04 00:14:12Z mrgoblin $ # EOF