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

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

commit 5926c9d8ddcdeff63d3762afc432d1de42c2d0ff
Author: Jan Høydahl <[email protected]>
AuthorDate: Fri Nov 13 22:04:33 2026 +0100

    SOLR-18644: bin/solr.cmd should honour SOLR_PID_DIR (#5325)
    
    branch_9x's solr.cmd still reads the solr-*.port files in its status and 
healthcheck paths, so those references use SOLR_PID_DIR too.
    
    (cherry picked from commit 686f3e02d459d63ee1abdc5e4282068e980da355)
    (cherry picked from commit c7178d186c326a0bc72e1cf2692a5a10fb6d6bac)
---
 .../SOLR-18644-solr-cmd-honours-solr-pid-dir.yml   | 14 +++++++++++
 solr/bin/solr.cmd                                  | 27 ++++++++++++----------
 solr/bin/solr.in.cmd                               |  4 ++++
 3 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/changelog/unreleased/SOLR-18644-solr-cmd-honours-solr-pid-dir.yml 
b/changelog/unreleased/SOLR-18644-solr-cmd-honours-solr-pid-dir.yml
new file mode 100644
index 00000000000..cabb2ffcf28
--- /dev/null
+++ b/changelog/unreleased/SOLR-18644-solr-cmd-honours-solr-pid-dir.yml
@@ -0,0 +1,14 @@
+# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
+
+title: >
+  `bin\solr.cmd` now honours the `SOLR_PID_DIR` environment variable, instead 
of always writing the
+  files that record running nodes into the installation's `bin` directory. 
`bin/solr` and
+  `SolrProcessManager` already read it, so Windows now behaves like the other 
platforms and like the
+  documentation.
+type: fixed
+authors:
+  - name: Jan Høydahl
+    url: https://home.apache.org/phonebook.html?uid=janhoy
+links:
+  - name: SOLR-18644
+    url: https://issues.apache.org/jira/browse/SOLR-18644
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index ac67559faa5..27a96da8b44 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -30,6 +30,9 @@ pushd %SOLR_TIP%
 set SOLR_TIP=%CD%
 popd
 
+REM Where the per-node files recording running Solr instances live
+IF NOT DEFINED SOLR_PID_DIR set "SOLR_PID_DIR=%SOLR_TIP%\bin"
+
 REM Used to report errors before exiting the script
 set SCRIPT_ERROR=
 set NO_USER_PROMPT=0
@@ -858,9 +861,9 @@ IF "%SCRIPT_CMD%"=="stop" (
   IF "%SOLR_PORT%"=="" (
     IF "%STOP_ALL%"=="1" (
       set found_it=0
-      for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i 
"^solr-.*\.port$"`) do (
+      for /f "usebackq" %%i in (`dir /b "%SOLR_PID_DIR%" ^| findstr /i 
"^solr-.*\.port$"`) do (
         set SOME_SOLR_PORT=
-        For /F "delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set 
SOME_SOLR_PORT=%%~J
+        For /F "delims=" %%J In ('type "%SOLR_PID_DIR%\%%i"') do set 
SOME_SOLR_PORT=%%~J
         if NOT "!SOME_SOLR_PORT!"=="" (
           for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 
" ^| find ":!SOME_SOLR_PORT! "') do (
             @REM j is the ip:port and k is the pid
@@ -874,7 +877,7 @@ IF "%SCRIPT_CMD%"=="stop" (
                   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% 
--stop
-                del "%SOLR_TIP%"\bin\solr-!SOME_SOLR_PORT!.port
+                del "%SOLR_PID_DIR%"\solr-!SOME_SOLR_PORT!.port
                 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 shutdown
@@ -902,7 +905,7 @@ IF "%SCRIPT_CMD%"=="stop" (
           @echo Stopping Solr process %%N running on port %SOLR_PORT%
           IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000
           "%JAVA%" %SOLR_SSL_OPTS% %SOLR_TOOL_OPTS% 
-Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" 
%SOLR_JETTY_CONFIG% STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stop
-          del "%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
+          del "%SOLR_PID_DIR%"\solr-%SOLR_PORT%.port
           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 shutdown
@@ -1245,7 +1248,7 @@ IF "%DEFAULT_CONFDIR%"=="" set 
"DEFAULT_CONFDIR=%SOLR_SERVER_DIR%\solr\configset
 IF "%FG%"=="1" (
   REM run solr in the foreground
   title "Solr-%SOLR_PORT%"
-  echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
+  echo %SOLR_PORT%>"%SOLR_PID_DIR%"\solr-%SOLR_PORT%.port
   "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% ^
     -Dlog4j.configurationFile="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! 
-DSTOP.KEY=%STOP_KEY% ^
     -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" 
-Dsolr.install.symDir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%" ^
@@ -1259,7 +1262,7 @@ IF "%FG%"=="1" (
     -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" 
-Dsolr.install.symDir="%SOLR_TIP%" -Dsolr.default.confdir="%DEFAULT_CONFDIR%" ^
     -Djetty.port=%SOLR_PORT% -Djetty.home="%SOLR_SERVER_DIR%" ^
     -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
+  echo %SOLR_PORT%>"%SOLR_PID_DIR%"\solr-%SOLR_PORT%.port
 
   IF "!SOLR_START_WAIT!"=="" (
     set SOLR_START_WAIT=180
@@ -1463,9 +1466,9 @@ IF "!CREATE_CONFNAME!"=="" set 
CREATE_CONFNAME=!CREATE_NAME!
 
 REM Find a port that Solr is running on
 if "!CREATE_PORT!"=="" (
-  for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i 
"^solr-.*\.port$"`) do (
+  for /f "usebackq" %%i in (`dir /b "%SOLR_PID_DIR%" ^| findstr /i 
"^solr-.*\.port$"`) do (
     set SOME_SOLR_PORT=
-    For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set 
SOME_SOLR_PORT=%%~J
+    For /F "Delims=" %%J In ('type "%SOLR_PID_DIR%\%%i"') do set 
SOME_SOLR_PORT=%%~J
     if NOT "!SOME_SOLR_PORT!"=="" (
       for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " 
^| find ":!SOME_SOLR_PORT! "') do (
         IF NOT "%%k"=="0" set CREATE_PORT=!SOME_SOLR_PORT!
@@ -1550,9 +1553,9 @@ IF "!DELETE_NAME!"=="" (
 
 REM Find a port that Solr is running on
 if "!DELETE_PORT!"=="" (
-  for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i 
"^solr-.*\.port$"`) do (
+  for /f "usebackq" %%i in (`dir /b "%SOLR_PID_DIR%" ^| findstr /i 
"^solr-.*\.port$"`) do (
     set SOME_SOLR_PORT=
-    For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set 
SOME_SOLR_PORT=%%~J
+    For /F "Delims=" %%J In ('type "%SOLR_PID_DIR%\%%i"') do set 
SOME_SOLR_PORT=%%~J
     if NOT "!SOME_SOLR_PORT!"=="" (
       for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " 
^| find ":!SOME_SOLR_PORT! "') do (
         IF NOT "%%k"=="0" set DELETE_PORT=!SOME_SOLR_PORT!
@@ -1614,9 +1617,9 @@ IF NOT EXIST "%SOLR_HOME%\" (
 )
 
 if "!AUTH_PORT!"=="" (
-  for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i 
"^solr-.*\.port$"`) do (
+  for /f "usebackq" %%i in (`dir /b "%SOLR_PID_DIR%" ^| findstr /i 
"^solr-.*\.port$"`) do (
     set SOME_SOLR_PORT=
-    For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set 
SOME_SOLR_PORT=%%~J
+    For /F "Delims=" %%J In ('type "%SOLR_PID_DIR%\%%i"') do set 
SOME_SOLR_PORT=%%~J
     if NOT "!SOME_SOLR_PORT!"=="" (
       for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":0 " 
^| find ":!SOME_SOLR_PORT! "') do (
         IF NOT "%%k"=="0" set AUTH_PORT=!SOME_SOLR_PORT!
diff --git a/solr/bin/solr.in.cmd b/solr/bin/solr.in.cmd
index 77b1117208a..f939a0f70d1 100755
--- a/solr/bin/solr.in.cmd
+++ b/solr/bin/solr.in.cmd
@@ -105,6 +105,10 @@ REM Most properties have an environment variable 
equivalent.
 REM A naming convention is that SOLR_FOO_BAR maps to solr.foo.bar
 REM SOLR_CLUSTERING_ENABLED=true
 
+REM Location where the bin\solr script will save the files recording running 
instances
+REM If not set, the script will create them in %SOLR_TIP%\bin
+REM set SOLR_PID_DIR=
+
 REM Path to a directory for Solr to store cores and their data. By default, 
Solr will use server\solr
 REM If solr.xml is not stored in ZooKeeper, this directory needs to contain 
solr.xml
 REM set SOLR_HOME=

Reply via email to