You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mk...@apache.org on 2020/06/06 10:08:13 UTC

[lucene-solr] branch master updated: SOLR-14442: call jstack before force kill; force kill regardles of open port.

This is an automated email from the ASF dual-hosted git repository.

mkhl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new c8e4334  SOLR-14442: call jstack before force kill; force kill regardles of open port.
c8e4334 is described below

commit c8e43346928b6d989d9e4d82c0334b322664c69a
Author: Mikhail Khludnev <mk...@apache.org>
AuthorDate: Thu May 28 23:29:35 2020 +0300

    SOLR-14442: call jstack before force kill; force kill regardles of open port.
---
 solr/bin/solr     | 19 ++++++++++++++++---
 solr/bin/solr.cmd | 22 ++++++++--------------
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/solr/bin/solr b/solr/bin/solr
index 0f57607..87f56bc 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -103,10 +103,17 @@ fi
 
 if [ -n "$SOLR_JAVA_HOME" ]; then
   JAVA="$SOLR_JAVA_HOME/bin/java"
+  JSTACK="$SOLR_JAVA_HOME/bin/jstack"
 elif [ -n "$JAVA_HOME" ]; then
-  for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
-    if [ -x "$java" ]; then
-      JAVA="$java"
+  for java in "$JAVA_HOME"/bin/amd64 "$JAVA_HOME"/bin; do
+    if [ -x "$java/java" ]; then
+      JAVA="$java/java"
+      if [ -x "$java/jstack" ]; then
+        JSTACK="$java/jstack"
+      else
+        echo >&2 "The currently defined JAVA_HOME ($JAVA_HOME) refers to a location"
+        echo >&2 "where java was found but jstack was not found. Continuing."
+      fi
       break
     fi
   done
@@ -119,6 +126,7 @@ elif [ -n "$JAVA_HOME" ]; then
   fi
 else
   JAVA=java
+  JSTACK=jstack
 fi
 
 if [ -z "$SOLR_STOP_WAIT" ]; then
@@ -821,6 +829,7 @@ function run_package() {
 
 # tries to gracefully stop Solr using the Jetty
 # stop command and if that fails, then uses kill -9
+# (will attempt to jstack before killing)
 function stop_solr() {
 
   DIR="$1"
@@ -857,6 +866,10 @@ function stop_solr() {
 
   CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
   if [ "$CHECK_PID" != "" ]; then
+    if [ "$JSTACK" != "" ]; then
+      echo -e "Solr process $SOLR_PID is still running; jstacking it now."
+      $JSTACK $SOLR_PID
+    fi
     echo -e "Solr process $SOLR_PID is still running; forcefully killing it now."
     kill -9 $SOLR_PID
     echo "Killed process $SOLR_PID"
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 8001245..8dddbc9 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -1042,13 +1042,10 @@ IF "%SCRIPT_CMD%"=="stop" (
                 del "%SOLR_TIP%"\bin\solr-!SOME_SOLR_PORT!.port
                 timeout /T 5
                 REM Kill it if it is still running after the graceful shutdown
-                For /f "tokens=2,5" %%M in ('netstat -nao ^| find "TCP " ^| find ":0 " ^| find ":!SOME_SOLR_PORT! "') do (
-                  IF "%%N"=="%%k" (
-                    IF "%%M"=="%SOLR_JETTY_HOST%:!SOME_SOLR_PORT!" (
-                      @echo Forcefully killing process %%N
-                      taskkill /f /PID %%N
-                    )
-                  )
+                IF EXIST "%JAVA_HOME%\bin\jstack.exe" (
+                  qprocess "%%k" >nul 2>nul && "%JAVA_HOME%\bin\jstack.exe" %%k && taskkill /f /PID %%k
+                ) else (
+                  qprocess "%%k" >nul 2>nul && taskkill /f /PID %%k
                 )
               )
             )
@@ -1072,13 +1069,10 @@ IF "%SCRIPT_CMD%"=="stop" (
           del "%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
           timeout /T 5
           REM Kill it if it is still running after the graceful shutdown
-          For /f "tokens=2,5" %%j in ('netstat -nao ^| find "TCP " ^| find ":0 " ^| find ":%SOLR_PORT% "') do (
-            IF "%%N"=="%%k" (
-              IF "%%j"=="%SOLR_JETTY_HOST%:%SOLR_PORT%" (
-                @echo Forcefully killing process %%N
-                taskkill /f /PID %%N
-              )
-            )
+          IF EXIST "%JAVA_HOME%\bin\jstack.exe" (
+            qprocess "%%N" >nul 2>nul && "%JAVA_HOME%\bin\jstack.exe" %%N && taskkill /f /PID %%N
+          ) else (
+            qprocess "%%N" >nul 2>nul && taskkill /f /PID %%N
           )
         )
       )