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

mdrob pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 94fc474  SOLR-15558: Identify zombie processes when stopping
94fc474 is described below

commit 94fc474c6787caf3ad0ba3af0e828b4a03068df3
Author: Colvin Cowie <[email protected]>
AuthorDate: Sat Aug 7 11:11:16 2021 +0100

    SOLR-15558: Identify zombie processes when stopping
    
    resolves #250
    
    (cherry picked from commit c63be9cfb4e292768aa9a25ad26d360ff54fd5d3)
---
 solr/CHANGES.txt |  2 ++
 solr/bin/solr    | 26 +++++++++++++++++---------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 534f151..d4366b9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -589,6 +589,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 Fixes
diff --git a/solr/bin/solr b/solr/bin/solr
index 3a6f0e4..cfc6f30 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" ]; then
     PID=`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" != "" ]; then
       local solrPID=$PID
     fi
@@ -843,14 +843,17 @@ function stop_solr() {
   STOP_KEY="$3"
   SOLR_PID="$4"
 
-  if [ "$SOLR_PID" != "" ]; then
+  if [ -n "$SOLR_PID"  ]; then
     echo -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=0
       while true
       do
-        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" ]]; then
           slept=$((loops * 2))
           if [ $slept -lt $SOLR_STOP_WAIT ]; then
             sleep 2
@@ -869,8 +872,8 @@ function stop_solr() {
     exit 0
   fi
 
-  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" ]]; then
     if [ "$JSTACK" != "" ]; then
       echo -e "Solr process $SOLR_PID is still running; jstacking it now."
       $JSTACK $SOLR_PID
@@ -885,8 +888,13 @@ function stop_solr() {
     sleep 10
   fi
 
-  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" != "" ]; then
     echo "ERROR: Failed to kill previous Solr Java process $SOLR_PID ... 
script fails."
     exit 1
   fi
@@ -1871,7 +1879,7 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "$SOLR_PORT" ]]; then
     if [ $numSolrs -eq 1 ]; then
       # only do this if there is only 1 node running, otherwise they must 
provide the -p or -all
       PID="$(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" != "" ]; then
         port=`jetty_port "$CHECK_PID"`
         if [ "$port" != "" ]; then

Reply via email to