ctdb-scripts: Improve CTDB wrapper shutdown code
authorMartin Schwenke <martin@meltin.net>
Fri, 23 Oct 2015 03:04:04 +0000 (14:04 +1100)
committerMichael Adam <obnox@samba.org>
Mon, 9 Nov 2015 06:53:19 +0000 (07:53 +0100)
This will make it easier to run things after CTDB is stopped.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/config/ctdbd_wrapper

index c98c1906eb904a54e994d0c7a7f75b815004372d..2ff8183b6fa55845f1e86e00e245b8291c21e9a7 100755 (executable)
@@ -249,23 +249,29 @@ stop()
     # Wait for remaining CTDB processes to exit...
     _timeout=${CTDB_SHUTDOWN_TIMEOUT:-30}
     _count=0
+    _terminated=false
     while [ $_count -lt $_timeout ] ; do
-       pkill -0 -s "$_session" 2>/dev/null || return 0
+       if ! pkill -0 -s "$_session" 2>/dev/null ; then
+           _terminated=true
+           break
+       fi
 
        _count=$(($_count + 1))
        sleep 1
     done
 
-    echo "Timed out waiting for CTDB to shutdown.  Killing CTDB processes."
-    kill_ctdbd "$_session"
-    drop_all_public_ips >/dev/null 2>&1
+    if ! $_terminated ; then
+       echo "Timed out waiting for CTDB to shutdown.  Killing CTDB processes."
+       kill_ctdbd "$_session"
+       drop_all_public_ips >/dev/null 2>&1
 
-    sleep 1
+       sleep 1
 
-    if pkill -0 -s "$_session" ; then
-       # If SIGKILL didn't work then things are bad...
-       echo "Failed to kill all CTDB processes.  Giving up."
-       return 1
+       if pkill -0 -s "$_session" ; then
+           # If SIGKILL didn't work then things are bad...
+           echo "Failed to kill all CTDB processes.  Giving up."
+           return 1
+       fi
     fi
 
     return 0