Apache Solr open-source search software
SOLR-9698 - Fix start/stop wait time and RMI_PORT on Windows (#1329)
Colvin Cowief804af73397c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex d30e89870d5..560b8383263 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -209,6 +209,8 @@ Bug Fixes* SOLR-16658: List of permissions returned to Admin UI is not complete (janhoy)+* SOLR-9698: Fix start/stop wait time and RMI_PORT on Windows (Colvin Cowie)+Build---------------------* Upgrade forbiddenapis to 3.4 (Uwe Schindler)diff --git a/solr/bin/solr b/solr/bin/solrindex 28880369446..cbb34e09047 100644--- a/solr/bin/solr+++ b/solr/bin/solr@@ -2054,6 +2054,10 @@ if [ "${SOLR_MODE:-}" == 'solrcloud' ]; thenif [ -n "${ZK_HOST:-}" ]; thenCLOUD_MODE_OPTS+=("-DzkHost=$ZK_HOST")else+ if [ $SOLR_PORT -gt 55535 ]; then+ echo -e "\nZK_HOST is not set and Solr port is $SOLR_PORT, which would result in an invalid embedded Zookeeper port!\n"+ exit 1+ fiif $verbose ; thenecho "Configuring SolrCloud to launch an embedded Zookeeper using -DzkRun"fidiff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmdindex 8ed5c2aa216..167ef7fe165 100755--- a/solr/bin/solr.cmd+++ b/solr/bin/solr.cmd@@ -1042,6 +1042,9 @@ IF "%SCRIPT_CMD%"=="restart" ()@REM stop logic here+IF "%SOLR_STOP_WAIT%"=="" (+ set SOLR_STOP_WAIT=180+)IF "%SCRIPT_CMD%"=="stop" (IF "%SOLR_PORT%"=="" (IF "%STOP_ALL%"=="1" (@@ -1056,10 +1059,15 @@ IF "%SCRIPT_CMD%"=="stop" (IF "%%j"=="%SOLR_JETTY_HOST%:!SOME_SOLR_PORT!" (set found_it=1@echo Stopping Solr process %%k running on port !SOME_SOLR_PORT!- IF "%STOP_PORT%"=="" set /A STOP_PORT=!SOME_SOLR_PORT! - 1000- "%JAVA%" %SOLR_SSL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stop+ IF "%STOP_PORT%"=="" (+ set /A LOCAL_STOP_PORT=!SOME_SOLR_PORT! - 1000+ ) else (+ set LOCAL_STOP_PORT=%STOP_PORT%+ )+ "%JAVA%" %SOLR_SSL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" STOP.PORT=!LOCAL_STOP_PORT! STOP.KEY=%STOP_KEY% --stopdel "%SOLR_TIP%"\bin\solr-!SOME_SOLR_PORT!.port- timeout /T 5+ REM wait for the process to terminate+ CALL :wait_for_process_exit %%k !SOLR_STOP_WAIT!REM Kill it if it is still running after the graceful shutdownIF EXIST "%JAVA_HOME%\bin\jstack.exe" (qprocess "%%k" >nul 2>nul && "%JAVA_HOME%\bin\jstack.exe" %%k && taskkill /f /PID %%k@@ -1086,7 +1094,8 @@ IF "%SCRIPT_CMD%"=="stop" (IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000"%JAVA%" %SOLR_SSL_OPTS% -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" %SOLR_JETTY_CONFIG% STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stopdel "%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port- timeout /T 5+ REM wait for the process to terminate+ CALL :wait_for_process_exit %%N !SOLR_STOP_WAIT!REM Kill it if it is still running after the graceful shutdownIF EXIST "%JAVA_HOME%\bin\jstack.exe" (qprocess "%%N" >nul 2>nul && "%JAVA_HOME%\bin\jstack.exe" %%N && taskkill /f /PID %%N@@ -1165,6 +1174,10 @@ IF "%SOLR_MODE%"=="solrcloud" (IF NOT "%ZK_HOST%"=="" (set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -DzkHost=%ZK_HOST%") ELSE (+ IF %SOLR_PORT% GTR 55535 (+ set "SCRIPT_ERROR=ZK_HOST is not set and Solr port is %SOLR_PORT%, which would result in an invalid embedded Zookeeper port!"+ goto err+ )IF "%verbose%"=="1" echo Configuring SolrCloud to launch an embedded Zookeeper using -DzkRunset "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -DzkRun")@@ -1204,7 +1217,13 @@ set IP_ACL_OPTS=-Dsolr.jetty.inetaccess.includes="%SOLR_IP_ALLOWLIST%" ^REM These are useful for attaching remove profilers like VisualVM/JConsoleIF "%ENABLE_REMOTE_JMX_OPTS%"=="true" (- IF "!RMI_PORT!"=="" set RMI_PORT=1%SOLR_PORT%+ IF "!RMI_PORT!"=="" (+ set /A RMI_PORT=%SOLR_PORT%+10000+ IF !RMI_PORT! GTR 65535 (+ set "SCRIPT_ERROR=RMI_PORT is !RMI_PORT!, which is invalid!"+ goto err+ )+ )set REMOTE_JMX_OPTS=-Dcom.sun.management.jmxremote ^-Dcom.sun.management.jmxremote.local.only=false ^-Dcom.sun.management.jmxremote.ssl=false ^@@ -1409,11 +1428,19 @@ IF "%FG%"=="1" (-Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar %SOLR_JETTY_CONFIG% "%SOLR_JETTY_ADDL_CONFIG%" > "!SOLR_LOGS_DIR!\solr-%SOLR_PORT%-console.log"echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port+ REM default to 30 seconds for backwards compatibility.+ IF "!SOLR_START_WAIT!"=="" (+ set SOLR_START_WAIT=30+ )REM now wait to see Solr come online ..."%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%"^-Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^- org.apache.solr.util.SolrCLI status -maxWaitSecs 30 -solr !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr+ org.apache.solr.util.SolrCLI status -maxWaitSecs !SOLR_START_WAIT! -solr !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr+ IF NOT "!ERRORLEVEL!"=="0" (+ set "SCRIPT_ERROR=Solr did not start or was not reachable. Check the logs for errors."+ goto err+ ))goto done@@ -2099,3 +2126,37 @@ set "eout=%1"set eout=%eout:"=%echo !eout!GOTO :eof++:wait_for_process_exit+ REM Wait for a process to stop within a configured period.+ REM The timeout is approximate, since there is no standard+ REM timing mechanism on windows that works in all situations.+ REM ping can be used to provide a good approximation.+ set WAIT_FOR_PID=%1+ set WAIT_TIME=%2++ REM Check every N seconds+ set INTERVAL=1+ set ELAPSED=0++ REM ping timeout needs N + 1 for N seconds elapsed+ set /A PING_INTERVAL=INTERVAL+1++ echo Waiting up to %WAIT_TIME% seconds for process %WAIT_FOR_PID% to exit+ IF %WAIT_TIME% GEQ 30 (+ REM Reduce WAIT_TIME by 5% to roughly account for the drift in time for the untimed actions+ set /A WAIT_TIME=WAIT_TIME*95+ set /A WAIT_TIME=WAIT_TIME/100+ )++ :isalive+ REM Check if process is alive+ qprocess "%WAIT_FOR_PID%" >nul 2>nul+ IF %ERRORLEVEL% EQU 0 (+ ping 127.0.0.1 -n %PING_INTERVAL% > NUL+ set /A ELAPSED=ELAPSED+INTERVAL+ IF %ELAPSED% LEQ %WAIT_TIME% (+ goto isalive+ )+ )+GOTO :eofdiff --git a/solr/bin/solr.in.cmd b/solr/bin/solr.in.cmdindex c436a743d45..1363ee43d5f 100755--- a/solr/bin/solr.in.cmd+++ b/solr/bin/solr.in.cmd@@ -25,6 +25,16 @@ REM to use, but you can set a specific path for Solr to use withoutREM affecting other Java applications on your server/workstation.REM set SOLR_JAVA_HOME=+REM This controls the number of seconds that the solr script will wait for+REM Solr to stop gracefully. If the graceful stop fails, the script will+REM forcibly stop Solr.+REM set SOLR_STOP_WAIT=180++REM This controls the number of seconds that the solr script will wait for+REM Solr to start. If the start fails you should inspect the Solr log files+REM for more information.+REM set SOLR_START_WAIT=30+REM Increase Java Min/Max Heap as needed to support your indexing / query needsREM set SOLR_JAVA_MEM=-Xms512m -Xmx512mdiff --git a/solr/bin/solr.in.sh b/solr/bin/solr.in.shindex f88751e2cf3..84d85981c69 100644--- a/solr/bin/solr.in.sh+++ b/solr/bin/solr.in.sh@@ -22,12 +22,12 @@#SOLR_JAVA_HOME=""# This controls the number of seconds that the solr script will wait for-# Solr to stop gracefully. If the graceful stop fails, the script will+# Solr to stop gracefully. If the graceful stop fails, the script will# forcibly stop Solr.#SOLR_STOP_WAIT="180"# This controls the number of seconds that the solr script will wait for-# Solr to start. If the start fails, the script will give up waiting and+# Solr to start. If the start fails, the script will give up waiting and# display the last few lines of the logfile.#SOLR_START_WAIT="$SOLR_STOP_WAIT"diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.javaindex ac355547229..c7112bf6608 100755--- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java+++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java@@ -912,7 +912,7 @@ public class SolrCLI implements CLIO {String solrUrl = cli.getOptionValue("solr", DEFAULT_SOLR_URL);if (maxWaitSecs > 0) {int solrPort = (new URL(solrUrl)).getPort();- echo("Waiting up to " + maxWaitSecs + " to see Solr running on port " + solrPort);+ echo("Waiting up to " + maxWaitSecs + " seconds to see Solr running on port " + solrPort);try {waitToSeeSolrUp(solrUrl, maxWaitSecs);echo("Started Solr server on port " + solrPort + ". Happy searching!");