dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/mdmonitor.init

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