mkrupcale / rpms / mdadm

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