Eventscripts: 10.interface clean-ups - minor tweaks and new comments.
authorMartin Schwenke <martin@meltin.net>
Tue, 28 Jun 2011 07:07:39 +0000 (17:07 +1000)
committerMartin Schwenke <martin@meltin.net>
Fri, 12 Aug 2011 06:34:13 +0000 (16:34 +1000)
* sed can read files, it doesn't need a file piped to it
* use $() subshells instead of `` - they seem to quote better in dash
* tweak the uniquifying code so that it is easier to read
* add comments
* remove some extraneous semicolons at ends of lines

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/events.d/10.interface

index 6443f415e533b0fdcdf7936d013cf88ec034062c..4e33aa48c30da90a9ced1d3161096eb53d35a02f 100755 (executable)
@@ -30,18 +30,19 @@ mark_down ()
 
 monitor_interfaces()
 {
-       all_interfaces=`cat $CTDB_PUBLIC_ADDRESSES |
-               sed -e "s/^[^\t ]*[\t ]*//" -e "s/,/ /g" -e "s/[\t ]*$//"`
+       # Get all the interfaces listed in the public_addresses file
+       all_interfaces=$(sed -e "s/^[^\t ]*[\t ]*//" -e "s/,/ /g" -e "s/[\t ]*$//" $CTDB_PUBLIC_ADDRESSES)
 
+       # Add some special interfaces if they're defined
        [ "$CTDB_PUBLIC_INTERFACE" ] && all_interfaces="$CTDB_PUBLIC_INTERFACE $all_interfaces"
        [ "$CTDB_NATGW_PUBLIC_IFACE" ] && all_interfaces="$CTDB_NATGW_PUBLIC_IFACE $all_interfaces"
 
 
        # For all but the 1st line, get the 2nd last field with commas
        # changes to spaces.
-       ctdb_ifaces=`ctdb -Y ip -v | sed -e '1d' -e 's/:[^:]*:$//' -e 's/^.*://' -e 's/,/ /g'`
+       ctdb_ifaces=$(ctdb -Y ip -v | sed -e '1d' -e 's/:[^:]*:$//' -e 's/^.*://' -e 's/,/ /g')
 
-       all_interfaces=`for iface in $all_interfaces $ctdb_ifaces ; do echo $iface ; done | sort | uniq`
+       all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort | uniq)
 
        fail=false
        up_interfaces_found=false
@@ -61,14 +62,17 @@ monitor_interfaces()
                echo "$bi" | grep -q 'Currently Active Slave: None' && {
                        echo "ERROR: No active slaves for bond device $realiface"
                        mark_down $iface
-                       continue;
+                       continue
                }
                echo "$bi" | grep -q '^MII Status: up' || {
                        echo "ERROR: public network interface $realiface is down"
                        mark_down $iface
-                       continue;
+                       continue
                }
                echo "$bi" | grep -q '^Bonding Mode: IEEE 802.3ad Dynamic link aggregation' && {
+                       # This works around a bug in the driver where the
+                       # overall bond status can be up but none of the actual
+                       # physical interfaces have a link.
                        echo "$bi" | grep 'MII Status:' | tail -n +2 | grep -q '^MII Status: up' || {
                                echo No active slaves for 802.ad bond device $realiface
                                mark_down $iface
@@ -76,7 +80,7 @@ monitor_interfaces()
                        }
                }
                mark_up $iface
-               continue;
+               continue
            }
 
            case $iface in