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

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


The following commit(s) were added to refs/heads/main by this push:
     new f5e9165773d SOLR-18665: Make bin/solr start wait for readiness (#5358)
f5e9165773d is described below

commit f5e9165773d8b571d1706dc9fe50d4efb3886aaf
Author: Jan Høydahl <[email protected]>
AuthorDate: Wed Nov 18 16:16:10 2026 +0100

    SOLR-18665: Make bin/solr start wait for readiness (#5358)
---
 .../unreleased/SOLR-18665-start-readiness.yml      | 13 +++++
 solr/bin/install_solr_service.sh                   |  1 -
 solr/bin/solr                                      | 59 +++++++++-------------
 .../src/java/org/apache/solr/cli/StatusTool.java   |  8 ++-
 solr/docker/templates/Dockerfile.body.template     |  2 +-
 solr/packaging/test/test_basic_auth.bats           |  7 +++
 .../pages/taking-solr-to-production.adoc           |  1 -
 7 files changed, 53 insertions(+), 38 deletions(-)

diff --git a/changelog/unreleased/SOLR-18665-start-readiness.yml 
b/changelog/unreleased/SOLR-18665-start-readiness.yml
new file mode 100644
index 00000000000..bae9a225e9b
--- /dev/null
+++ b/changelog/unreleased/SOLR-18665-start-readiness.yml
@@ -0,0 +1,13 @@
+# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
+
+title: >
+  `bin/solr start` now waits for the node to be ready, instead of for its port 
to be listening, so a
+  command that runs right after it no longer races the node's startup. A start 
that never completes
+  now also exits non-zero.
+type: fixed
+authors:
+  - name: Jan Høydahl
+    url: https://home.apache.org/phonebook.html?uid=janhoy
+links:
+  - name: SOLR-18665
+    url: https://issues.apache.org/jira/browse/SOLR-18665
diff --git a/solr/bin/install_solr_service.sh b/solr/bin/install_solr_service.sh
index 9f98b66e928..ebe0598ac7e 100755
--- a/solr/bin/install_solr_service.sh
+++ b/solr/bin/install_solr_service.sh
@@ -196,7 +196,6 @@ if [[ $SOLR_START == "true" ]] ; then
   systemctl --version &>/dev/null || print_error "Script requires the 
'systemctl' command"
   java -version &>/dev/null       || print_error "Solr requires java, please 
install or set JAVA_HOME properly"
 fi
-lsof -h &>/dev/null             || echo "We recommend installing the 'lsof' 
command for more stable start/stop of Solr"
 
 
 if [ -z "$SOLR_EXTRACT_DIR" ]; then
diff --git a/solr/bin/solr b/solr/bin/solr
index 8c5efd40161..7b8f851852c 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -56,9 +56,9 @@ JAVA_VER_REQ=21
 stop_all=false
 
 # for now, we don't support running this script from cygwin due to problems
-# like not having lsof, ps auxww, curl, and awkward directory handling
+# like not having ps auxww, curl, and awkward directory handling
 if [ "${THIS_OS:0:6}" == "CYGWIN" ]; then
-  echo -e "This script does not support cygwin due to severe limitations and 
lack of adherence\nto BASH standards, such as lack of lsof, curl, and ps 
options.\n\nPlease use the native solr.cmd script on Windows!"
+  echo -e "This script does not support cygwin due to severe limitations and 
lack of adherence\nto BASH standards, such as lack of curl, and ps 
options.\n\nPlease use the native solr.cmd script on Windows!"
   exit 1
 fi
 # Alpine Linux BusyBox comes with a stripped down ps, make sure we have a 
fully featured one
@@ -513,6 +513,21 @@ function run_tool() {
   return $?
 } # end run_tool function
 
+# Wait for the node on $SOLR_PORT_LISTEN to answer, as bin/solr.cmd does. 
Jetty binds its
+# connectors before the Solr webapp starts, so a listening port is no proof of 
readiness.
+function wait_for_solr_ready() {
+  local status_output
+  if status_output=$(run_tool status -p "$SOLR_PORT_LISTEN" --max-wait-secs 
"$SOLR_START_WAIT" 2>&1); then
+    return 0
+  fi
+  echo -e "Still not seeing Solr running on port $SOLR_PORT_LISTEN after 
$SOLR_START_WAIT seconds!"
+  if $verbose ; then
+    echo "$status_output"
+  fi
+  tail -30 "$SOLR_LOGS_DIR/solr.log"
+  return 1
+} # end wait_for_solr_ready function
+
 # tries to gracefully stop Solr using the Jetty
 # stop command and if that fails, then uses kill -9
 # (will attempt to thread dump before killing)
@@ -1396,38 +1411,14 @@ function start_solr() {
       fi
     fi
 
-    # no lsof on cygwin though
-    if lsof -v 2>&1 | grep -q revision; then
-      echo -n "Waiting up to $SOLR_START_WAIT seconds to see Solr running on 
port $SOLR_PORT_LISTEN"
-      # Launch in a subshell to show the spinner
-      (loops=0
-      while true
-      do
-        running=$(lsof -t -PniTCP:$SOLR_PORT_LISTEN -sTCP:LISTEN || :)
-        if [ -z "${running:-}" ]; then
-          slept=$((loops * 2))
-          if [ $slept -lt $SOLR_START_WAIT ]; then
-            sleep 2
-            loops=$((loops+1))
-          else
-            echo -e "Still not seeing Solr listening on $SOLR_PORT_LISTEN 
after $SOLR_START_WAIT seconds!"
-            tail -30 "$SOLR_LOGS_DIR/solr.log"
-            exit # subshell!
-          fi
-        else
-          SOLR_PID=$(solr_pid_by_ps "$SOLR_PORT_LISTEN")
-          echo -e "\nStarted Solr server on port $SOLR_PORT_LISTEN 
(pid=$SOLR_PID). Happy searching!\n"
-          exit # subshell!
-        fi
-      done) &
-      spinner $!
-    else
-      echo -e "NOTE: Please install lsof as this script needs it to determine 
if Solr is listening on port $SOLR_PORT_LISTEN."
-      sleep 10
-      SOLR_PID=$(solr_pid_by_ps "$SOLR_PORT_LISTEN")
-      echo -e "\nStarted Solr server on port $SOLR_PORT_LISTEN 
(pid=$SOLR_PID). Happy searching!\n"
-      return;
-    fi
+    echo -n "Waiting up to $SOLR_START_WAIT seconds to see Solr running on 
port $SOLR_PORT_LISTEN"
+    # Launch in a subshell to show the spinner, then propagate its exit status
+    (wait_for_solr_ready || exit 1 # subshell!
+    SOLR_PID=$(solr_pid_by_ps "$SOLR_PORT_LISTEN")
+    echo -e "\nStarted Solr server on port $SOLR_PORT_LISTEN (pid=$SOLR_PID). 
Happy searching!\n") &
+    wait_pid=$!
+    spinner "$wait_pid"
+    wait "$wait_pid" || return 1
   fi
 }
 
diff --git a/solr/core/src/java/org/apache/solr/cli/StatusTool.java 
b/solr/core/src/java/org/apache/solr/cli/StatusTool.java
index d9f0c789577..155f9b17223 100644
--- a/solr/core/src/java/org/apache/solr/cli/StatusTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/StatusTool.java
@@ -306,7 +306,8 @@ public class StatusTool extends ToolBase {
   }
 
   /**
-   * Wait for Solr to come online and return true if it does, false otherwise.
+   * Wait for Solr to come online and return true if it does, false otherwise. 
A node that rejects
+   * the request as unauthenticated or unauthorized counts as online.
    *
    * @return true if Solr comes online, false otherwise
    */
@@ -316,6 +317,11 @@ public class StatusTool extends ToolBase {
       return true;
     } catch (TimeoutException timeout) {
       return false;
+    } catch (Exception e) {
+      if (CLIUtils.exceptionIsAuthRelated(e)) {
+        return true;
+      }
+      throw e;
     }
   }
 
diff --git a/solr/docker/templates/Dockerfile.body.template 
b/solr/docker/templates/Dockerfile.body.template
index f10eb027bc6..6d3de192e5d 100644
--- a/solr/docker/templates/Dockerfile.body.template
+++ b/solr/docker/templates/Dockerfile.body.template
@@ -69,7 +69,7 @@ RUN set -ex; \
 
 RUN set -ex; \
     apt-get update; \
-    apt-get -y --no-install-recommends install curl acl lsof procps wget 
netcat-openbsd tini jattach; \
+    apt-get -y --no-install-recommends install curl acl procps wget 
netcat-openbsd tini jattach; \
     rm -rf /var/lib/apt/lists/*;
 
 VOLUME /var/solr
diff --git a/solr/packaging/test/test_basic_auth.bats 
b/solr/packaging/test/test_basic_auth.bats
index b85a168833b..ea3b397bf51 100644
--- a/solr/packaging/test/test_basic_auth.bats
+++ b/solr/packaging/test/test_basic_auth.bats
@@ -92,6 +92,13 @@ run solr create -c COLL_NAME
   #refute_output --partial "Invalid collection"
 }
 
+@test "start succeeds when the node rejects unauthenticated requests" {
+  solr stop --all
+  run solr start
+  assert_success
+  assert_output --partial "Happy searching!"
+}
+
 @test "admin UI static content is excepted from basic auth" {
   run curl -I -s http://localhost:${SOLR_PORT}/solr/
   assert_output --partial "HTTP/1.1 200"
diff --git 
a/solr/solr-ref-guide/modules/deployment-guide/pages/taking-solr-to-production.adoc
 
b/solr/solr-ref-guide/modules/deployment-guide/pages/taking-solr-to-production.adoc
index e911e1c8af6..8910c2b9170 100644
--- 
a/solr/solr-ref-guide/modules/deployment-guide/pages/taking-solr-to-production.adoc
+++ 
b/solr/solr-ref-guide/modules/deployment-guide/pages/taking-solr-to-production.adoc
@@ -72,7 +72,6 @@ tar xzf solr-{solr-full-version}.tgz 
solr-{solr-full-version}/bin/install_solr_s
 ----
 
 The previous command extracts the `install_solr_service.sh` script from the 
archive into the current directory.
-If installing on Red Hat, please make sure *lsof* is installed before running 
the Solr installation script (`sudo yum install lsof`).
 The installation script must be run as root:
 
 [source,bash,subs="attributes"]

Reply via email to