Eventscripts - 10.interfaces should not check orphaned interfaces.
authorMartin Schwenke <martin@meltin.net>
Mon, 1 Aug 2011 03:37:06 +0000 (13:37 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 2 Aug 2011 05:53:24 +0000 (15:53 +1000)
If the last IP address on an interfaces is removed then that
interfaces should no longer be checked by 10.interfaces.  However,
"ctdb ifaces" still lists such interfaces so they are currently
checked.

The problem really needs to be addressed in ctdbd but a neat quick
eventscript fix will be minimally invasive...

This changes the code to use "ctdb -Y ip -v" instead of "ctdb -Y
ifaces".  The former includes details of all public addresses and
associated interfaces, so when an address is removed there is no
output for it.  This avoids orphaned interfaces from being listed.

The logic is also slightly improved so that $IFACES includes just a
(non-uniquified) list of interfaces, allowing an existing loop to be
removed.

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

index f79367320e94720e0be196d0374aafe7aa7d2046..8f0c0bc20f51ce117d2f1458f9c8e014d9c024c2 100755 (executable)
@@ -24,17 +24,14 @@ monitor_interfaces()
        [ "$CTDB_PUBLIC_INTERFACE" ] && INTERFACES="$CTDB_PUBLIC_INTERFACE $INTERFACES"
        [ "$CTDB_NATGW_PUBLIC_IFACE" ] && INTERFACES="$CTDB_NATGW_PUBLIC_IFACE $INTERFACES"
 
-       local IFACES=`ctdb ifaces -Y | grep -v '^:Name:LinkStatus:References:'`
 
-       local I
-       local IFACE
+       # For all but the 1st line, get the 2nd last field with commas
+       # changes to spaces.
+       local IFACES=`ctdb -Y ip -v | sed -e '1d' -e 's/:[^:]*:$//' -e 's/^.*://' -e 's/,/ /g'`
 
-       for I in $IFACES; do
-               IFACE=`echo -n "$I" | cut -d ':' -f2`
-               INTERFACES="$IFACE $INTERFACES"
-       done
+       local IFACE
 
-       INTERFACES=`for IFACE in $INTERFACES ; do echo $IFACE ; done | sort | uniq`
+       INTERFACES=`for IFACE in $INTERFACES $IFACES ; do echo $IFACE ; done | sort | uniq`
 
        local fail=0
        local ok=0