--- rpms/mdadm/sme7/mdmonitor.init 2007/06/12 16:34:41 1.1 +++ rpms/mdadm/sme7/mdmonitor.init 2007/12/01 02:32:57 1.2 @@ -7,57 +7,68 @@ # description: software RAID monitoring and management # config: /etc/mdadm.conf # - # Copyright 2002 Red Hat, Inc. +# +### BEGIN INIT INFO +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start and stop the MD software RAID monitor +# Description: The mdmonitor service checks the status of all software +# RAID arrays on the system. In the event that any of the arrays +# transition into a degraded state, it notifies the system +# administrator. Other options are available, see the mdadm.conf +# and mdadm man pages for possible ways to configure this service. +### END INIT INFO +PIDFILE=/var/run/mdadm/mdadm.pid PATH=/sbin:/usr/sbin:$PATH RETVAL=0 +OPTIONS="--monitor --scan -f --pid-file=$PIDFILE" prog=mdmonitor # Source function library. . /etc/rc.d/init.d/functions -# Make sure configuration file exists and has information we can use -# MAILADDR or PROGRAM or both must be set in order to run mdadm --monitor -[ -f /etc/mdadm.conf ] || exit 0 -grep '^\(MAILADDR\|PROGRAM\) .' /etc/mdadm.conf >/dev/null 2>&1 || exit 0 - usage () { - echo "Usage: service $prog {start|stop|status|restart|condrestart}" + echo "Usage: service $prog {start|stop|status|restart|try-restart|force-reload}" RETVAL=1 } start () { - ulimit -S -c 0 >/dev/null 2>&1 - echo -n $"Starting $prog: " - daemon --check mdadm \ - "/bin/bash -c \"mdadm --monitor --scan -f > /var/run/mdadm/mdadm.pid\"" - # hack: wait for mdadm to die, assume success if it doesn't die quickly - usleep 100000 - if [ -s /var/run/mdadm/mdadm.pid -a -d /proc/$(cat /var/run/mdadm/mdadm.pid) ] ; then - success $"mdadm" - RETVAL=0 - touch /var/lock/subsys/$prog - else - failure $"mdadm" - rm -f /var/run/mdadm/mdadm.pid - rm -f /var/lock/subsys/$prog - RETVAL=1 + # Check we are being started with root perms or exit as mdadm won't + # necessarily be able to open the devices it is supposed to monitor + # otherwise, and will also spew SELinux warnings about being in the / + # directory when spawning sendmail on a notification attempt + [ `id -u` -eq 0 ] || return 4 + # Make sure configuration file exists and has information we can use + # MAILADDR or PROGRAM or both must be set in order to run mdadm --monitor + [ -f /etc/mdadm.conf ] || return 6 + grep '^\(MAILADDR\|PROGRAM\) .' /etc/mdadm.conf >/dev/null 2>&1 || return 6 + [ -x /sbin/mdadm ] || return 1 + if [ -f "$PIDFILE" ]; then + checkpid `cat $PIDFILE` && return 0 fi + echo -n $"Starting $prog: " + cd / + daemon --user=root mdadm ${OPTIONS} + ret=$? + [ $ret -eq "0" ] && touch /var/lock/subsys/$prog echo + return $ret } stop () { + [ `id -u` -eq 0 ] || return 4 + [ -f /var/lock/subsys/$prog ] || return 0 echo -n "Killing $prog: " killproc mdadm echo - rm -f /var/run/mdadm/mdadm.pid rm -f /var/lock/subsys/$prog } @@ -69,17 +80,18 @@ restart () condrestart () { - [ -e /var/lock/subsys/$prog ] && restart + [ -e /var/lock/subsys/$prog ] && restart || return 0 } case "$1" in - start) start ;; - stop) stop ;; - status) status mdadm ;; - restart|reload) restart ;; - condrestart) condrestart ;; - *) usage ;; + start) start; RETVAL=$? ;; + stop) stop; RETVAL=$? ;; + status) status mdadm; RETVAL=$? ;; + restart) restart; RETVAL=$? ;; + reload) RETVAL=3 ;; + condrestart|try-restart|force-reload) condrestart; RETVAL=$? ;; + *) usage ; RETVAL=2 ;; esac exit $RETVAL