]> git.openstreetmap.org Git - chef.git/blob - cookbooks/hardware/templates/default/cciss-vol-statusd.erb
Add local implementation of cciss-vol-statusd
[chef.git] / cookbooks / hardware / templates / default / cciss-vol-statusd.erb
1 #!/bin/sh
2
3 NAME="cciss-vol-statusd"
4 STATUSFILE=/var/run/$NAME.status
5
6 # Do not touch you can configure this in /etc/default/cciss-vol-statusd
7 MAILTO=root   # Where to report problems
8 PERIOD=600    # Seconds between each check    (default 10 minutes)
9 REMIND=7200   # Seconds between each reminder (default 2 hours)
10 ID=/dev/cciss/c0d0
11
12 [ -e /etc/default/cciss-vol-statusd ] && . /etc/default/cciss-vol-statusd
13
14 # Gracefully exit if the package has been removed.
15 test -x /usr/bin/cciss_vol_status || exit 0
16
17 while true ; do
18     # Check ever $PERIOD seconds, send email on every status
19     # change and repeat ever $REMIND seconds if the raid is still
20     # bad.
21     if (cciss_vol_status $ID); then
22         BADRAID=false
23     else
24         BADRAID=true
25         logger -t cciss-vol-statusd "detected non-optimal RAID status"
26     fi
27     STATUSCHANGE=false
28     if [ true = "$BADRAID" ] ; then
29         # RAID not OK
30         (cciss_vol_status $ID) > $STATUSFILE.new
31         if [ ! -f $STATUSFILE ] ; then # RAID just became broken
32             STATUSCHANGE=true
33             mv $STATUSFILE.new $STATUSFILE
34         elif cmp -s $STATUSFILE $STATUSFILE.new ; then
35             # No change.  Should we send reminder?
36             LASTTIME="`stat -c '%Z' $STATUSFILE`"
37             NOW="`date +%s`"
38             SINCELAST="`expr $NOW - $LASTTIME`"
39             if [ $REMIND -le "$SINCELAST" ]; then
40                 # Time to send reminder
41                 STATUSCHANGE=true
42                 mv $STATUSFILE.new $STATUSFILE
43             else
44                 rm $STATUSFILE.new
45             fi
46         else
47             STATUSCHANGE=true
48             mv $STATUSFILE.new $STATUSFILE
49         fi
50     else
51         # RAID OK
52         if [ -f $STATUSFILE ] ; then
53             rm $STATUSFILE
54             STATUSCHANGE=true
55         fi
56     fi
57
58     if [ true = "$STATUSCHANGE" ]; then
59         hostname="`uname -n`"
60         (
61             cat <<EOF
62 This is a RAID status update from cciss-vol-statusd.  The cciss_vol_status
63 program reports that one of the RAIDs changed state:
64
65 EOF
66             if [ -f $STATUSFILE ] ; then
67                 cat $STATUSFILE
68             else
69                 (cciss_vol_status $ID)
70             fi
71             echo
72             echo "Report from $0 on $hostname"
73         ) | mail -s "info: CCISS raid status change on $hostname" $MAILTO
74     fi
75
76     sleep $PERIOD
77 done