| 4 |
- |
1 |
#!/bin/bash
|
|
|
2 |
#
|
|
|
3 |
# mdmonitor This starts, stops, and reloads the mdadm-based
|
|
|
4 |
# software RAID monitoring and management facility
|
|
|
5 |
#
|
|
|
6 |
# chkconfig: 2345 15 85
|
|
|
7 |
# description: software RAID monitoring and management
|
|
|
8 |
# config: /etc/mdadm.conf
|
|
|
9 |
#
|
|
|
10 |
# 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
|
|
|
25 |
RETVAL=0
|
|
|
26 |
OPTIONS="--monitor --scan -f --pid-file=$PIDFILE"
|
|
|
27 |
|
|
|
28 |
prog=mdmonitor
|
|
|
29 |
|
|
|
30 |
# Source function library.
|
|
|
31 |
. /etc/rc.d/init.d/functions
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
usage ()
|
|
|
35 |
{
|
|
|
36 |
echo "Usage: service $prog {start|stop|status|restart|try-restart|force-reload}"
|
|
|
37 |
RETVAL=1
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
start ()
|
|
|
42 |
{
|
|
|
43 |
# (Re)start mdmon to take over monitoring of mdmon started from the initrd
|
|
|
44 |
for i in /dev/md/*.pid; do
|
|
|
45 |
if [ -r $i ]; then
|
|
|
46 |
origprog="$prog"; prog="mdmon"
|
|
|
47 |
action $"Starting $prog: " /sbin/mdmon --takeover --all
|
|
|
48 |
prog="$origprog"
|
|
|
49 |
break
|
|
|
50 |
fi
|
|
|
51 |
done
|
|
|
52 |
# Make sure configuration file exists and has information we can use
|
|
|
53 |
# MAILADDR or PROGRAM or both must be set in order to run mdadm --monitor
|
|
|
54 |
[ -f /etc/mdadm.conf ] || return 6
|
|
|
55 |
grep '^\(MAILADDR\|PROGRAM\) .' /etc/mdadm.conf >/dev/null 2>&1 || return 6
|
|
|
56 |
if [ -f "$PIDFILE" ]; then
|
|
|
57 |
checkpid `cat $PIDFILE` && return 0
|
|
|
58 |
fi
|
|
|
59 |
echo -n $"Starting $prog: "
|
|
|
60 |
cd /
|
|
|
61 |
daemon --user=root mdadm ${OPTIONS}
|
|
|
62 |
ret=$?
|
|
|
63 |
[ $ret -eq "0" ] && touch /var/lock/subsys/$prog
|
|
|
64 |
echo
|
|
|
65 |
return $ret
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
stop ()
|
|
|
69 |
{
|
|
|
70 |
[ -f /var/lock/subsys/$prog ] || return 0
|
|
|
71 |
echo -n "Killing $prog: "
|
|
|
72 |
killproc mdadm
|
|
|
73 |
echo
|
|
|
74 |
rm -f $PIDFILE
|
|
|
75 |
rm -f /var/lock/subsys/$prog
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
restart ()
|
|
|
79 |
{
|
|
|
80 |
stop
|
|
|
81 |
start
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
condrestart ()
|
|
|
85 |
{
|
|
|
86 |
[ -e /var/lock/subsys/$prog ] && restart || return 0
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
case "$1" in
|
|
|
91 |
start|stop|restart|condrestart|try-restart|force-reload)
|
|
|
92 |
[ `id -u` != "0" ] && exit 4 ;;
|
|
|
93 |
esac
|
|
|
94 |
|
|
|
95 |
case "$1" in
|
|
|
96 |
start) start; RETVAL=$? ;;
|
|
|
97 |
stop) stop; RETVAL=$? ;;
|
|
|
98 |
status) status -p $PIDFILE $prog ; RETVAL=$? ;;
|
|
|
99 |
restart) restart; RETVAL=$? ;;
|
|
|
100 |
reload) RETVAL=3 ;;
|
|
|
101 |
condrestart|try-restart|force-reload) condrestart; RETVAL=$? ;;
|
|
|
102 |
*) usage ; RETVAL=2 ;;
|
|
|
103 |
esac
|
|
|
104 |
|
|
|
105 |
exit $RETVAL
|