Eventscripts: 10.interfaces - new function get_all_interfaces().
authorMartin Schwenke <martin@meltin.net>
Tue, 5 Jul 2011 07:18:30 +0000 (17:18 +1000)
committerMartin Schwenke <martin@meltin.net>
Fri, 12 Aug 2011 06:34:34 +0000 (16:34 +1000)
Move existing interface listing code to new function in preparation
for using it in startup event.

While we're here change the "sort | uniq" into "sort -u" and save some
complexity.

Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit cd1442531ad079b11c60f46ee9d34f5104bef219)

ctdb/config/events.d/10.interface

index 4e33aa48c30da90a9ced1d3161096eb53d35a02f..cad5bf85fe2b56f60fbcac53cf9d71f7d31f4c00 100755 (executable)
@@ -28,21 +28,27 @@ mark_down ()
     ctdb setifacelink $1 down >/dev/null 2>&1
 }
 
-monitor_interfaces()
+# This sets $all_interfaces as a side-effect.
+get_all_interfaces ()
 {
-       # 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)
+    # 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"
+    # 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')
 
-       # 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')
+    # Add $ctdb_interfaces and uniquify
+    all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort -u)
+}
 
-       all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort | uniq)
+monitor_interfaces()
+{
+       get_all_interfaces
 
        fail=false
        up_interfaces_found=false