KYLIN-2573 'kylin.sh stop' can't kill kylin's process by sometimes.

Signed-off-by: Billy Liu <billy...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/901b10ce
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/901b10ce
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/901b10ce

Branch: refs/heads/KYLIN-2624
Commit: 901b10cee549a9c1e8d2df711a8c8d83789d7717
Parents: 42f7e7d
Author: mango77881 <12169...@qq.com>
Authored: Fri May 5 15:25:56 2017 +0800
Committer: Billy Liu <billy...@apache.org>
Committed: Tue May 9 13:47:32 2017 +0800

----------------------------------------------------------------------
 build/bin/kylin.sh | 41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/901b10ce/build/bin/kylin.sh
----------------------------------------------------------------------
diff --git a/build/bin/kylin.sh b/build/bin/kylin.sh
index cd87436..d9e932e 100644
--- a/build/bin/kylin.sh
+++ b/build/bin/kylin.sh
@@ -131,20 +131,47 @@ then
     if [ -f "${KYLIN_HOME}/pid" ]
     then
         PID=`cat $KYLIN_HOME/pid`
+        WAIT_TIME=2
+        LOOP_COUNTER=10
         if ps -p $PID > /dev/null
         then
-           echo "Stopping Kylin: $PID"
-           kill $PID
-           rm ${KYLIN_HOME}/pid
-           exit 0
+            echo "Stopping Kylin: $PID"
+            kill $PID
+
+            for ((i=0; i<$LOOP_COUNTER; i++))
+            do
+                # wait to process stopped 
+                sleep $WAIT_TIME
+                if ps -p $PID > /dev/null ; then
+                    echo "Stopping in progress. Will check after $WAIT_TIME 
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
+                sleep 1 #give kill -9  sometime to "kill"
+                if ps -p $PID > /dev/null
+                then
+                   quit "Warning, even kill -9 failed, giving up! Sorry..."
+                fi
+            fi
+
+            # process is killed , remove pid file              
+            rm -rf ${KYLIN_HOME}/pid
+            echo "Kylin with pid ${PID} has been stopped."
+            exit 0
         else
-           quit "Kylin is not running"
+           quit "Kylin with pid ${PID} is not running"
         fi
-        
     else
         quit "Kylin is not running"
     fi
-
 elif [ "$1" = "version" ]
 then
     retrieveDependency

Reply via email to