Repository: ranger
Updated Branches:
  refs/heads/ranger-1 028de96b8 -> 2a392edc1


RANGER-2229 : Perform graceful terminate with retries before doing forceful 
kill for usersync and tagsync

Change-Id: I5608a64dec91f7ccbd85cc8a671158f9c0764dc2

Signed-off-by: Mehul Parikh <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/2a392edc
Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/2a392edc
Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/2a392edc

Branch: refs/heads/ranger-1
Commit: 2a392edc11df2383c2d32c9833a6a7930538cce1
Parents: 3d5e5eb
Author: Bhavik Patel <[email protected]>
Authored: Wed Sep 19 16:05:32 2018 +0530
Committer: Mehul Parikh <[email protected]>
Committed: Mon Oct 8 18:59:02 2018 +0530

----------------------------------------------------------------------
 tagsync/scripts/ranger-tagsync-services.sh      | 44 +++++++++++++++-----
 .../scripts/ranger-usersync-services.sh         | 41 ++++++++++++++----
 2 files changed, 67 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/2a392edc/tagsync/scripts/ranger-tagsync-services.sh
----------------------------------------------------------------------
diff --git a/tagsync/scripts/ranger-tagsync-services.sh 
b/tagsync/scripts/ranger-tagsync-services.sh
index 5686390..a4ad7b1 100755
--- a/tagsync/scripts/ranger-tagsync-services.sh
+++ b/tagsync/scripts/ranger-tagsync-services.sh
@@ -111,17 +111,41 @@ elif [ "${action}" == "STOP" ]; then
        NR_ITER_FOR_SHUTDOWN_CHECK=15
        if [ -f "$pidf" ] ; then
                pid=`cat $pidf` > /dev/null 2>&1
-               echo "Found Apache Ranger TagSync Service with pid $pid, 
Stopping..."
-               kill -9 $pid > /dev/null 2>&1
-               sleep 1 #Give kill -9 sometime to "kill"
-               if ps -p $pid > /dev/null; then
-                       echo "Wow, even kill -9 failed, giving up! Sorry.."
-                else
-                       rm -f $pidf
-                       echo "Apache Ranger Tagsync Service pid = ${pid} has 
been stopped."
-                fi
+               echo "Getting pid from $pidf .."
        else
-            echo "Ranger Tagsync Service not running"
+               pid=`ps -ef | grep java | grep -- '-Dproc_rangertagsync' | grep 
-v grep | awk '{ print $2 }'`
+               if [ "$pid" != "" ];then
+                       echo "pid file($pidf) not present, taking pid from 
\'ps\' command.."
+               else
+                       echo "Apache Ranger Tagsync Service is not running"
+                       exit 1  
+               fi
+       fi
+       echo "Found Apache Ranger Tagsync Service with pid $pid, Stopping it..."
+       kill -15 $pid
+       for ((i=0; i<$NR_ITER_FOR_SHUTDOWN_CHECK; i++))
+       do
+               sleep $WAIT_TIME_FOR_SHUTDOWN
+               if ps -p $pid > /dev/null ; then
+                       echo "Shutdown in progress. Will check after 
$WAIT_TIME_FOR_SHUTDOWN secs again.."
+                       continue;
+               else
+                       break;
+               fi
+       done
+       # if process is still around, use kill -9
+       if ps -p $pid > /dev/null ; then
+               echo "Initial kill failed, getting serious now..."
+               kill -9 $pid
+       fi
+       sleep 1 #give kill -9  sometime to "kill"
+       if ps -p $pid > /dev/null ; then
+               echo "Wow, even kill -9 failed, giving up! Sorry.."
+               exit 1
+
+       else
+               rm -rf $pidf
+               echo "Apache Ranger Tagsync Service with pid ${pid} has been 
stopped."
        fi
        exit;
        

http://git-wip-us.apache.org/repos/asf/ranger/blob/2a392edc/unixauthservice/scripts/ranger-usersync-services.sh
----------------------------------------------------------------------
diff --git a/unixauthservice/scripts/ranger-usersync-services.sh 
b/unixauthservice/scripts/ranger-usersync-services.sh
index 028ad08..476aa0c 100644
--- a/unixauthservice/scripts/ranger-usersync-services.sh
+++ b/unixauthservice/scripts/ranger-usersync-services.sh
@@ -129,18 +129,43 @@ if [ "${action}" == "START" ]; then
 elif [ "${action}" == "STOP" ]; then
        WAIT_TIME_FOR_SHUTDOWN=2
        NR_ITER_FOR_SHUTDOWN_CHECK=15
-       if [ -f $pidf ]; then
+       if [ -f "$pidf" ] ; then
                pid=`cat $pidf` > /dev/null 2>&1
-               kill -9 $pid > /dev/null 2>&1
-               sleep 1 #Give kill -9 sometime to "kill"
-               if ps -p $pid > /dev/null; then
-                       echo "Wow, even kill -9 failed, giving up! Sorry.."
+               echo "Getting pid from $pidf .."
+       else
+               pid=`ps -ef | grep java | grep -- '-Dproc_rangerusersync' | 
grep -v grep | awk '{ print $2 }'`
+               if [ "$pid" != "" ];then
+                       echo "pid file($pidf) not present, taking pid from 
\'ps\' command.."
                else
-                       rm -f $pidf
-                       echo "Apache Ranger Usersync Service [pid = ${pid}] has 
been stopped."
+                       echo "Apache Ranger Usersync Service is not running"
+                       exit 1  
                fi
+       fi
+       echo "Found Apache Ranger Usersync Service with pid $pid, Stopping 
it..."
+       kill -15 $pid
+       for ((i=0; i<$NR_ITER_FOR_SHUTDOWN_CHECK; i++))
+       do
+               sleep $WAIT_TIME_FOR_SHUTDOWN
+               if ps -p $pid > /dev/null ; then
+                       echo "Shutdown in progress. Will check after 
$WAIT_TIME_FOR_SHUTDOWN secs again.."
+                       continue;
+               else
+                       break;
+               fi
+       done
+       # if process is still around, use kill -9
+       if ps -p $pid > /dev/null ; then
+               echo "Initial kill failed, getting serious now..."
+               kill -9 $pid
+       fi
+       sleep 1 #give kill -9  sometime to "kill"
+       if ps -p $pid > /dev/null ; then
+               echo "Wow, even kill -9 failed, giving up! Sorry.."
+               exit 1
+
        else
-               echo "Apache Ranger Usersync Service not running"
+               rm -rf $pidf
+               echo "Apache Ranger Usersync Service with pid ${pid} has been 
stopped."
        fi
        exit;
        

Reply via email to