Apache Solr open-source search software
SOLR-15558: Identify zombie processes when stopping
Colvin Cowiec63be9cfb4e2
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 46cd130aed1..b8e0bf1d59c 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -612,6 +612,8 @@ Bug Fixes* SOLR-15968: Hide annoying WARN log from bin/solr zk command (janhoy, Mike Drob)+* SOLR-15558: Don't wait for zombie processes to exit when stopping. (Colvin Cowie)+================== 8.11.2 ==================Bug Fixesdiff --git a/solr/bin/solr b/solr/bin/solrindex 3a6f0e493e4..cfc6f3032c8 100755--- a/solr/bin/solr+++ b/solr/bin/solr@@ -699,7 +699,7 @@ function solr_pid_by_port() {THE_PORT="$1"if [ -e "$SOLR_PID_DIR/solr-$THE_PORT.pid" ]; thenPID=`cat "$SOLR_PID_DIR/solr-$THE_PORT.pid"`- CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $PID | sort -r | tr -d ' '`+ CHECK_PID=`ps -o pid='' $PID | tr -d ' '`if [ "$CHECK_PID" != "" ]; thenlocal solrPID=$PIDfi@@ -843,14 +843,17 @@ function stop_solr() {STOP_KEY="$3"SOLR_PID="$4"- if [ "$SOLR_PID" != "" ]; then+ if [ -n "$SOLR_PID" ]; thenecho -e "Sending stop command to Solr running on port $SOLR_PORT ... waiting up to $SOLR_STOP_WAIT seconds to allow Jetty process $SOLR_PID to stop gracefully.""$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS -jar "$DIR/start.jar" "STOP.PORT=$THIS_STOP_PORT" "STOP.KEY=$STOP_KEY" --stop || true(loops=0while truedo- CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`- if [ "$CHECK_PID" != "" ]; then+ # Check if a process is running with the specified PID.+ # -o stat will output the STAT, where Z indicates a zombie+ # stat='' removes the header (--no-headers isn't supported on all platforms)+ STAT=`ps -o stat='' $SOLR_PID | tr -d ' '`+ if [[ "$STAT" != "" && "$STAT" != "Z" ]]; thenslept=$((loops * 2))if [ $slept -lt $SOLR_STOP_WAIT ]; thensleep 2@@ -869,8 +872,8 @@ function stop_solr() {exit 0fi- CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`- if [ "$CHECK_PID" != "" ]; then+ STAT=`ps -o stat='' $SOLR_PID | tr -d ' '`+ if [[ "$STAT" != "" && "$STAT" != "Z" ]]; thenif [ "$JSTACK" != "" ]; thenecho -e "Solr process $SOLR_PID is still running; jstacking it now."$JSTACK $SOLR_PID@@ -885,8 +888,13 @@ function stop_solr() {sleep 10fi- CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`- if [ "$CHECK_PID" != "" ]; then+ STAT=`ps -o stat='' $SOLR_PID | tr -d ' '`+ if [ "$STAT" == "Z" ]; then+ # This can happen if, for example, you are running Solr inside a docker container with multiple processes+ # rather than running it is as the only service. The --init flag on docker avoids that particular problem.+ echo -e "Solr process $SOLR_PID has terminated abnormally. Solr has exited but a zombie process entry remains."+ exit 1+ elif [ "$STAT" != "" ]; thenecho "ERROR: Failed to kill previous Solr Java process $SOLR_PID ... script fails."exit 1fi@@ -1871,7 +1879,7 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "$SOLR_PORT" ]]; thenif [ $numSolrs -eq 1 ]; then# only do this if there is only 1 node running, otherwise they must provide the -p or -allPID="$(cat "$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)")"- CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $PID | sort -r | tr -d ' '`+ CHECK_PID=`ps -o pid='' $PID | tr -d ' '`if [ "$CHECK_PID" != "" ]; thenport=`jetty_port "$CHECK_PID"`if [ "$port" != "" ]; then