Apache Solr open-source search software
SOLR-14442: call jstack before force kill; force kill regardles of open port.
Mikhail Khludnevc8e43346928b
diff --git a/solr/bin/solr b/solr/bin/solrindex 0f5760797e6..87f56bc4fcc 100755--- a/solr/bin/solr+++ b/solr/bin/solr@@ -103,10 +103,17 @@ fiif [ -n "$SOLR_JAVA_HOME" ]; thenJAVA="$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."+ fibreakfidone@@ -119,6 +126,7 @@ elif [ -n "$JAVA_HOME" ]; thenfielseJAVA=java+ JSTACK=jstackfiif [ -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+ fiecho -e "Solr process $SOLR_PID is still running; forcefully killing it now."kill -9 $SOLR_PIDecho "Killed process $SOLR_PID"diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmdindex 8001245ab1f..8dddbc90c98 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!.porttimeout /T 5REM 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%.porttimeout /T 5REM 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)))