eventscripts: 11.natgw should not call ctdb tool in "init" event
authorMartin Schwenke <martin@meltin.net>
Fri, 11 Jan 2013 05:02:31 +0000 (16:02 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 24 May 2013 04:08:07 +0000 (14:08 +1000)
The current code calls "ctdb setnatgwstate ..." on every event.
However, calling the ctdb tool in the "init" event is not permitted.

Instead, update the capability when it is needed and at regular
intervals via the "monitor" event.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>

config/events.d/11.natgw

index a6e05238f900b8d265c71c751169f87bbabbcc5a..c6c45cabf9f18688b8f70ac96667605a274f768a 100755 (executable)
@@ -13,12 +13,15 @@ loadconfig
 
 [ -z "$CTDB_NATGW_NODES" ] && exit 0
 
-# Update capabilities to show whether we support teh NATGW capability or not
-if [ "$CTDB_NATGW_SLAVE_ONLY" = "yes" ] ; then
+set_natgw_capability ()
+{
+    # Set NATGW capability depending on configuration
+    if [ "$CTDB_NATGW_SLAVE_ONLY" = "yes" ] ; then
        ctdb setnatgwstate off
-else
+    else
        ctdb setnatgwstate on
-fi
+    fi
+}
 
 delete_all() {
        _ip="${CTDB_NATGW_PUBLIC_IP%/*}"
@@ -58,6 +61,10 @@ ensure_natgwmaster ()
 }
 
 case "$1" in 
+    setup)
+       set_natgw_capability
+       ;;
+
     startup)
        # Error if CTDB_NATGW_PUBLIC_IP is listed in public addresses
        grep -q "^$CTDB_NATGW_PUBLIC_IP[[:space:]]" "${CTDB_PUBLIC_ADDRESSES:-/etc/ctdb/public_addresses}" && \
@@ -70,6 +77,7 @@ case "$1" in
     recovered|updatenatgw|ipreallocated)
        mypnn=$(ctdb pnn | cut -d: -f2)
 
+       set_natgw_capability
        ensure_natgwmaster "$1"
 
        delete_all
@@ -103,6 +111,7 @@ case "$1" in
        ;;
 
     monitor)
+       set_natgw_capability
        ensure_natgwmaster "$1"
        ;;