dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/mdmonitor.init

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