scripts: Improve CTDB wrapper shutdown code
authorMartin Schwenke <martin@meltin.net>
Fri, 23 Oct 2015 03:04:04 +0000 (14:04 +1100)
committerMartin Schwenke <martin@meltin.net>
Wed, 24 Feb 2016 05:15:14 +0000 (16:15 +1100)
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>
(Imported from commit f05c6d32cce334d29e373f1e74f0b52cab14409d)

config/ctdbd_wrapper

index fa0a2691bbcfa73d03cbf1a969547074dc01c4d2..76d21baaa16009d437b5a9d3408634b77f24c170 100755 (executable)
@@ -239,23 +239,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