SOLR-14442: call jstack before force kill; force kill regardles of open port.

This commit is contained in:
Mikhail Khludnev 2020-05-28 23:29:35 +03:00
parent 89784ad7be
commit c8e4334692
2 changed files with 24 additions and 17 deletions

View File

@ -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"

View File

@ -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
)
)
)