#!/bin/sh
#
# Start the RAID monitor daemon for all active md arrays if desired.
#
# Copyright (c) 2001,2002 Mario Jou/3en <joussen@debian.org>
# Distributable under the terms of the GNU GPL version 2.

MDADM=/sbin/mdadm
DEBIANCONFIG=/etc/mdadm/debian.conf
PIDFILE=/var/run/mdadm.pid

test -x $MDADM || exit 0

if [ ! -f /proc/mdstat ] && [ -x /sbin/modprobe ] ; then
  modprobe -k md > /dev/null 2>&1  
fi
test -f /proc/mdstat || exit 0

. /lib/lsb/init-functions

MAIL_TO=root
START_DAEMON=true
test -f $DEBIANCONFIG && . $DEBIANCONFIG

case "$1" in
    start)
        if [ "x$START_DAEMON" = "xtrue" ] ; then
            log_begin_msg "Starting RAID monitoring services..."
            start-stop-daemon -S -qbm -p $PIDFILE -x $MDADM -- -F -m $MAIL_TO -s
            log_end_msg $?
        fi
        ;;
    stop)
        if [ -f $PIDFILE ] ; then
            log_begin_msg "Stopping RAID monitoring services..."
            start-stop-daemon -K -q -p $PIDFILE -x $MDADM
	    ES=$?
            rm -f $PIDFILE
	    log_end_msg $ES
        fi
        ;;
    restart|reload|force-reload)
        $0 stop
        $0 start
        ;;
    *)
        log_success_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
        exit 1
        ;;
esac

exit 0
