7 |
# description: software RAID monitoring and management |
# description: software RAID monitoring and management |
8 |
# config: /etc/mdadm.conf |
# config: /etc/mdadm.conf |
9 |
# |
# |
|
|
|
10 |
# Copyright 2002 Red Hat, Inc. |
# Copyright 2002 Red Hat, Inc. |
11 |
|
# |
12 |
|
### BEGIN INIT INFO |
13 |
|
# Default-Start: 2 3 4 5 |
14 |
|
# Default-Stop: 0 1 6 |
15 |
|
# Short-Description: Start and stop the MD software RAID monitor |
16 |
|
# Description: The mdmonitor service checks the status of all software |
17 |
|
# RAID arrays on the system. In the event that any of the arrays |
18 |
|
# transition into a degraded state, it notifies the system |
19 |
|
# administrator. Other options are available, see the mdadm.conf |
20 |
|
# and mdadm man pages for possible ways to configure this service. |
21 |
|
### END INIT INFO |
22 |
|
|
23 |
|
PIDFILE=/var/run/mdadm/mdadm.pid |
24 |
PATH=/sbin:/usr/sbin:$PATH |
PATH=/sbin:/usr/sbin:$PATH |
25 |
RETVAL=0 |
RETVAL=0 |
26 |
|
OPTIONS="--monitor --scan -f --pid-file=$PIDFILE" |
27 |
|
|
28 |
prog=mdmonitor |
prog=mdmonitor |
29 |
|
|
30 |
# Source function library. |
# Source function library. |
31 |
. /etc/rc.d/init.d/functions |
. /etc/rc.d/init.d/functions |
32 |
|
|
|
# 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 |
|
|
|
|
33 |
|
|
34 |
usage () |
usage () |
35 |
{ |
{ |
36 |
echo "Usage: service $prog {start|stop|status|restart|condrestart}" |
echo "Usage: service $prog {start|stop|status|restart|try-restart|force-reload}" |
37 |
RETVAL=1 |
RETVAL=1 |
38 |
} |
} |
39 |
|
|
40 |
|
|
41 |
start () |
start () |
42 |
{ |
{ |
43 |
ulimit -S -c 0 >/dev/null 2>&1 |
# Check we are being started with root perms or exit as mdadm won't |
44 |
echo -n $"Starting $prog: " |
# necessarily be able to open the devices it is supposed to monitor |
45 |
daemon --check mdadm \ |
# otherwise, and will also spew SELinux warnings about being in the / |
46 |
"/bin/bash -c \"mdadm --monitor --scan -f > /var/run/mdadm/mdadm.pid\"" |
# directory when spawning sendmail on a notification attempt |
47 |
# hack: wait for mdadm to die, assume success if it doesn't die quickly |
[ `id -u` -eq 0 ] || return 4 |
48 |
usleep 100000 |
# Make sure configuration file exists and has information we can use |
49 |
if [ -s /var/run/mdadm/mdadm.pid -a -d /proc/$(cat /var/run/mdadm/mdadm.pid) ] ; then |
# MAILADDR or PROGRAM or both must be set in order to run mdadm --monitor |
50 |
success $"mdadm" |
[ -f /etc/mdadm.conf ] || return 6 |
51 |
RETVAL=0 |
grep '^\(MAILADDR\|PROGRAM\) .' /etc/mdadm.conf >/dev/null 2>&1 || return 6 |
52 |
touch /var/lock/subsys/$prog |
[ -x /sbin/mdadm ] || return 1 |
53 |
else |
if [ -f "$PIDFILE" ]; then |
54 |
failure $"mdadm" |
checkpid `cat $PIDFILE` && return 0 |
|
rm -f /var/run/mdadm/mdadm.pid |
|
|
rm -f /var/lock/subsys/$prog |
|
|
RETVAL=1 |
|
55 |
fi |
fi |
56 |
|
echo -n $"Starting $prog: " |
57 |
|
cd / |
58 |
|
daemon --user=root mdadm ${OPTIONS} |
59 |
|
ret=$? |
60 |
|
[ $ret -eq "0" ] && touch /var/lock/subsys/$prog |
61 |
echo |
echo |
62 |
|
return $ret |
63 |
} |
} |
64 |
|
|
65 |
stop () |
stop () |
66 |
{ |
{ |
67 |
|
[ `id -u` -eq 0 ] || return 4 |
68 |
|
[ -f /var/lock/subsys/$prog ] || return 0 |
69 |
echo -n "Killing $prog: " |
echo -n "Killing $prog: " |
70 |
killproc mdadm |
killproc mdadm |
71 |
echo |
echo |
|
rm -f /var/run/mdadm/mdadm.pid |
|
72 |
rm -f /var/lock/subsys/$prog |
rm -f /var/lock/subsys/$prog |
73 |
} |
} |
74 |
|
|
80 |
|
|
81 |
condrestart () |
condrestart () |
82 |
{ |
{ |
83 |
[ -e /var/lock/subsys/$prog ] && restart |
[ -e /var/lock/subsys/$prog ] && restart || return 0 |
84 |
} |
} |
85 |
|
|
86 |
|
|
87 |
case "$1" in |
case "$1" in |
88 |
start) start ;; |
start) start; RETVAL=$? ;; |
89 |
stop) stop ;; |
stop) stop; RETVAL=$? ;; |
90 |
status) status mdadm ;; |
status) status mdadm; RETVAL=$? ;; |
91 |
restart|reload) restart ;; |
restart) restart; RETVAL=$? ;; |
92 |
condrestart) condrestart ;; |
reload) RETVAL=3 ;; |
93 |
*) usage ;; |
condrestart|try-restart|force-reload) condrestart; RETVAL=$? ;; |
94 |
|
*) usage ; RETVAL=2 ;; |
95 |
esac |
esac |
96 |
|
|
97 |
exit $RETVAL |
exit $RETVAL |