dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone
2c1b57
#!/bin/bash
2c1b57
# 
2c1b57
# mdmonitor	This starts, stops, and reloads the mdadm-based
2c1b57
#		software RAID monitoring and management facility
2c1b57
#
2c1b57
# chkconfig: 2345 15 85
2c1b57
# description: software RAID monitoring and management
2c1b57
# config: /etc/mdadm.conf
2c1b57
#
2c1b57
# Copyright 2002 Red Hat, Inc.
2c1b57
#
2c1b57
### BEGIN INIT INFO
2c1b57
# Default-Start: 2 3 4 5
2c1b57
# Default-Stop: 0 1 6
2c1b57
# Short-Description: Start and stop the MD software RAID monitor
2c1b57
# Description: The mdmonitor service checks the status of all software
2c1b57
#	RAID arrays on the system.  In the event that any of the arrays
2c1b57
#	transition into a degraded state, it notifies the system
2c1b57
#	administrator.  Other options are available, see the mdadm.conf
2c1b57
#	and mdadm man pages for possible ways to configure this service.
2c1b57
### END INIT INFO
2c1b57
2c1b57
PIDPATH=/var/run/mdadm
2c1b57
PIDFILE=/var/run/mdadm/mdadm.pid
2c1b57
PATH=/sbin:/usr/sbin:$PATH
2c1b57
RETVAL=0
2c1b57
OPTIONS="--monitor --scan -f --pid-file=$PIDFILE"
2c1b57
2c1b57
prog=mdmonitor
2c1b57
2c1b57
# Source function library.
2c1b57
. /etc/rc.d/init.d/functions
2c1b57
2c1b57
2c1b57
usage ()
2c1b57
{
2c1b57
    echo "Usage: service $prog {start|stop|status|restart|try-restart|force-reload}"
2c1b57
    RETVAL=1
2c1b57
}
2c1b57
2c1b57
2c1b57
start ()
2c1b57
{
2c1b57
# (Re)start mdmon to take over monitoring of mdmon started from the initrd
2c1b57
    for i in /dev/md/*.pid; do
2c1b57
	if [ -r $i ]; then
2c1b57
            origprog="$prog"; prog="mdmon"
2c1b57
            action $"Starting $prog: " /sbin/mdmon --takeover --all
2c1b57
            prog="$origprog"
2c1b57
	    break
2c1b57
        fi
2c1b57
    done
2c1b57
# Make sure configuration file exists and has information we can use
2c1b57
# MAILADDR or PROGRAM or both must be set in order to run mdadm --monitor
2c1b57
    [ -f /etc/mdadm.conf ] || return 6
2c1b57
    grep '^\(MAILADDR\|PROGRAM\) .' /etc/mdadm.conf >/dev/null 2>&1 || return 6
2c1b57
    # Create our directory if it isn't there yet
2c1b57
    if [ ! -d $PIDPATH ]; then
2c1b57
        mkdir -m 0700 $PIDPATH >&/dev/null
2c1b57
	RC=$?
2c1b57
	[ -x /sbin/restorecon ] && /sbin/restorecon $PIDPATH
2c1b57
	if [ $RC -ne 0 ]; then
2c1b57
	    echo -n "Failed to create /var/run/mdadm"
2c1b57
            failure
2c1b57
	    echo
2c1b57
	    return 1
2c1b57
	fi
2c1b57
    fi
2c1b57
    if [ -f "$PIDFILE" ]; then
2c1b57
	checkpid `cat $PIDFILE` && return 0
2c1b57
    fi
2c1b57
    echo -n $"Starting $prog: "
2c1b57
    cd /
2c1b57
    daemon --user=root mdadm ${OPTIONS}
2c1b57
    ret=$?
2c1b57
    [ $ret -eq "0" ] && touch /var/lock/subsys/$prog
2c1b57
    echo
2c1b57
    return $ret
2c1b57
}
2c1b57
2c1b57
stop ()
2c1b57
{
2c1b57
    [ -f /var/lock/subsys/$prog ] || return 0
2c1b57
    echo -n "Killing $prog: "
2c1b57
    killproc mdadm
2c1b57
    echo
2c1b57
    rm -f $PIDFILE
2c1b57
    rm -f /var/lock/subsys/$prog
2c1b57
}
2c1b57
2c1b57
restart ()
2c1b57
{
2c1b57
    stop
2c1b57
    start
2c1b57
}
2c1b57
2c1b57
condrestart ()
2c1b57
{
2c1b57
    [ -e /var/lock/subsys/$prog ] && restart || return 0
2c1b57
}
2c1b57
2c1b57
2c1b57
case "$1" in
2c1b57
    start|stop|restart|condrestart|try-restart|force-reload)
2c1b57
    	[ `id -u` != "0" ] && exit 4 ;;
2c1b57
esac
2c1b57
2c1b57
case "$1" in
2c1b57
    start) start; RETVAL=$? ;;
2c1b57
    stop) stop; RETVAL=$? ;;
2c1b57
    status) status -p $PIDFILE $prog ; RETVAL=$? ;;
2c1b57
    restart) restart; RETVAL=$? ;;
2c1b57
    reload) RETVAL=3 ;;
2c1b57
    condrestart|try-restart|force-reload) condrestart; RETVAL=$? ;;
2c1b57
    *) usage ; RETVAL=2 ;;
2c1b57
esac
2c1b57
2c1b57
exit $RETVAL