SOLR-7016: Fix bin\solr.cmd to work in a directory with spaces in the name.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1655070 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy Potter 2015-01-27 16:04:58 +00:00
parent 9c1e05d604
commit 1660e8acb3
3 changed files with 96 additions and 65 deletions

View File

@ -559,6 +559,9 @@ Bug Fixes
* SOLR-7037: bin/solr start -e techproducts -c fails to start Solr in cloud mode
(Timothy Potter)
* SOLR-7016: Fix bin\solr.cmd to work in a directory with spaces in the name.
(Timothy Potter, Uwe Schindler)
Optimizations
----------------------

View File

@ -628,42 +628,70 @@ IF NOT "%TMP%"=="%SOLR_HOME%" (
IF "%SCRIPT_CMD%"=="stop" (
IF "%SOLR_PORT%"=="" (
IF "%STOP_ALL%"=="1" (
for /f "usebackq" %%i in (`dir /b %SOLR_TIP%\bin ^| findstr /i "^solr-.*\.port$"`) do (
set found_it=0
for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
set SOME_SOLR_PORT=
For /F "Delims=" %%J In (%SOLR_TIP%\bin\%%i) do set SOME_SOLR_PORT=%%~J
For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
if NOT "!SOME_SOLR_PORT!"=="" (
for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":!SOME_SOLR_PORT!"') do (
for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":!SOME_SOLR_PORT! "') do (
@REM j is the ip:port and k is the pid
IF NOT "%%k"=="0" (
@echo Stopping Solr running on port !SOME_SOLR_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
del %SOLR_TIP%\bin\solr-!SOME_SOLR_PORT!.port
timeout /T 5
REM Kill it if it is still running after the graceful shutdown
For /f "tokens=5" %%M in ('netstat -nao ^| find "TCP " ^| find ":!SOME_SOLR_PORT!"') do (
IF NOT "%%M"=="0" taskkill /f /PID %%M
@REM split the ip:port var by colon to see if the ip is 0.0.0.0
for /f "delims=: tokens=1,2" %%x IN ("%%j") do (
@REM x is the ip
IF "%%x"=="0.0.0.0" (
set found_it=1
@echo Stopping Solr process %%k running on port !SOME_SOLR_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
del "%SOLR_TIP%"\bin\solr-!SOME_SOLR_PORT!.port
timeout /T 5
REM Kill it if it is still running after the graceful shutdown
For /f "tokens=2,5" %%M in ('netstat -nao ^| find "TCP " ^| find ":!SOME_SOLR_PORT! "') do (
IF "%%N"=="%%k" (
for /f "delims=: tokens=1,2" %%a IN ("%%M") do (
IF "%%a"=="0.0.0.0" (
@echo Forcefully killing process %%N
taskkill /f /PID %%N
)
)
)
)
)
)
)
)
)
)
if "!found_it!"=="0" echo No Solr nodes found to stop.
) ELSE (
set SCRIPT_ERROR=Must specify the port when trying to stop Solr, or use -all to stop all running nodes on this host.
goto err
)
) ELSE (
set found_it=0
For /f "tokens=5" %%M in ('netstat -nao ^| find "TCP " ^| find ":%SOLR_PORT%"') do (
IF NOT "%%M"=="0" (
set found_it=1
@echo Stopping Solr running on port %SOLR_PORT%
set /A STOP_PORT=%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
del %SOLR_TIP%\bin\solr-%SOLR_PORT%.port
timeout /T 5
REM Kill it if it is still running after the graceful shutdown
For /f "tokens=5" %%j in ('netstat -nao ^| find "TCP " ^| find ":%SOLR_PORT%"') do (
IF NOT "%%j"=="0" taskkill /f /PID %%j
For /f "tokens=2,5" %%M in ('netstat -nao ^| find "TCP " ^| find ":%SOLR_PORT% "') do (
IF NOT "%%N"=="0" (
for /f "delims=: tokens=1,2" %%x IN ("%%M") do (
IF "%%x"=="0.0.0.0" (
set found_it=1
@echo Stopping Solr process %%N running on port %SOLR_PORT%
set /A STOP_PORT=%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
del "%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
timeout /T 5
REM Kill it if it is still running after the graceful shutdown
For /f "tokens=2,5" %%j in ('netstat -nao ^| find "TCP " ^| find ":%SOLR_PORT% "') do (
IF "%%N"=="%%k" (
for /f "delims=: tokens=1,2" %%a IN ("%%j") do (
IF "%%a"=="0.0.0.0" (
@echo Forcefully killing process %%N
taskkill /f /PID %%N
)
)
)
)
)
)
)
)
@ -677,10 +705,14 @@ IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000
IF "%SCRIPT_CMD%"=="start" (
REM see if Solr is already running using netstat
For /f "tokens=5" %%j in ('netstat -aon ^| find "TCP " ^| find ":%SOLR_PORT%"') do (
IF NOT "%%j"=="0" (
set "SCRIPT_ERROR=Process %%j is already listening on port %SOLR_PORT%. If this is Solr, please stop it first before starting (or use restart). If this is not Solr, then please choose a different port using -p PORT"
goto err
For /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":%SOLR_PORT% "') do (
IF NOT "%%k"=="0" (
for /f "delims=: tokens=1,2" %%x IN ("%%j") do (
IF "%%x"=="0.0.0.0" (
set "SCRIPT_ERROR=Process %%k is already listening on port %SOLR_PORT%. If this is Solr, please stop it first before starting (or use restart). If this is not Solr, then please choose a different port using -p PORT"
goto err
)
)
)
)
)
@ -806,7 +838,8 @@ IF NOT "%SOLR_SSL_OPTS%"=="" (
IF DEFINED SOLR_SSL_PORT set "SSL_PORT_PROP=-Djetty.ssl.port=%SOLR_SSL_PORT%"
set "START_OPTS=%START_OPTS% %SOLR_SSL_OPTS% !SSL_PORT_PROP!"
)
IF NOT "%LOG4J_CONFIG%"=="" set "START_OPTS=%START_OPTS% -Dlog4j.configuration=%LOG4J_CONFIG%"
IF NOT DEFINED LOG4J_CONFIG set "LOG4J_CONFIG=file:%SOLR_SERVER_DIR%\resources\log4j.properties"
cd "%SOLR_SERVER_DIR%"
@ -824,13 +857,13 @@ IF NOT EXIST "%SOLR_SERVER_DIR%\tmp" (
IF "%FG%"=="1" (
REM run solr in the foreground
title "Solr-%SOLR_PORT%"
echo %SOLR_PORT%>%SOLR_TIP%\bin\solr-%SOLR_PORT%.port
"%JAVA%" -server -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
"%JAVA%" -server -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
-Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" -Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar
) ELSE (
START /B "Solr-%SOLR_PORT%" "%JAVA%" -server -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" "%JAVA%" -server -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
-Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" -Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar > "!SOLR_LOGS_DIR!\solr-%SOLR_PORT%-console.log"
echo %SOLR_PORT%>%SOLR_TIP%\bin\solr-%SOLR_PORT%.port
echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
)
@ -862,7 +895,7 @@ IF NOT "!CREATE_EXAMPLE_CONFIG!"=="" (
IF "%EXAMPLE%"=="techproducts" (
@echo.
@echo Indexing tech product example docs from %SOLR_TIP%\example\exampledocs
"%JAVA%" %SOLR_SSL_OPTS% -Durl=!SOLR_URL_SCHEME!://localhost:%SOLR_PORT%/solr/%EXAMPLE%/update -jar %SOLR_TIP%/example/exampledocs/post.jar %SOLR_TIP%/example/exampledocs/*.xml
"%JAVA%" %SOLR_SSL_OPTS% -Durl=!SOLR_URL_SCHEME!://localhost:%SOLR_PORT%/solr/%EXAMPLE%/update -jar "%SOLR_TIP%/example/exampledocs/post.jar" "%SOLR_TIP%/example/exampledocs/*.xml"
)
@echo.
@ -962,9 +995,9 @@ for /l %%x in (1, 1, !CLOUD_NUM_NODES!) do (
)
@echo Starting node1 on port !NODE_PORT! using command:
@echo solr -cloud -p !NODE_PORT! -s example\node1\solr !DASHZ! !DASHM!
START "Solr-!NODE_PORT!" "%SDIR%\solr" -f -cloud -p !NODE_PORT! -s %CLOUD_EXAMPLE_DIR%\node1\solr !DASHZ! !DASHM!
START "Solr-!NODE_PORT!" /D "%SDIR%" solr -f -cloud -p !NODE_PORT! !DASHZ! !DASHM! -s "%CLOUD_EXAMPLE_DIR%\node1\solr"
set NODE1_PORT=!NODE_PORT!
echo !NODE_PORT!>%SOLR_TIP%\bin\solr-!NODE_PORT!.port
echo !NODE_PORT!>"%SOLR_TIP%"\bin\solr-!NODE_PORT!.port
) ELSE (
IF "!ZK_HOST!"=="" (
set /A ZK_PORT=!NODE1_PORT!+1000
@ -972,8 +1005,8 @@ for /l %%x in (1, 1, !CLOUD_NUM_NODES!) do (
)
@echo Starting node%%x on port !NODE_PORT! using command:
@echo solr -cloud -p !NODE_PORT! -s example\node%%x\solr -z !ZK_HOST! !DASHM!
START "Solr-!NODE_PORT!" "%SDIR%\solr" -f -cloud -p !NODE_PORT! -s %CLOUD_EXAMPLE_DIR%\node%%x\solr -z !ZK_HOST! !DASHM!
echo !NODE_PORT!>%SOLR_TIP%\bin\solr-!NODE_PORT!.port
START "Solr-!NODE_PORT!" /D "%SDIR%" solr -f -cloud -p !NODE_PORT! -z !ZK_HOST! !DASHM! -s "%CLOUD_EXAMPLE_DIR%\node%%x\solr"
echo !NODE_PORT!>"%SOLR_TIP%"\bin\solr-!NODE_PORT!.port
)
timeout /T 10
@ -1034,20 +1067,22 @@ goto done
:get_info
REM Find all Java processes, correlate with those listening on a port
REM and then try to contact via that port using the status tool
for /f "usebackq" %%i in (`dir /b %SOLR_TIP%\bin ^| findstr /i "^solr-.*\.port$"`) do (
for /f "usebackq" %%i in (`dir /b "%SOLR_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
set SOME_SOLR_PORT=
For /F "Delims=" %%J In (%SOLR_TIP%\bin\%%i) do set SOME_SOLR_PORT=%%~J
For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
if NOT "!SOME_SOLR_PORT!"=="" (
for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":!SOME_SOLR_PORT! "') do (
IF NOT "%%k"=="0" (
for /f "delims=: tokens=1,2" %%x IN ("%%j") do (
@echo.
set has_info=1
echo Found Solr process %%k running on port !SOME_SOLR_PORT!
"%JAVA%" %SOLR_SSL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI status -solr !SOLR_URL_SCHEME!://localhost:!SOME_SOLR_PORT!/solr
@echo.
if "%%x"=="0.0.0.0" (
@echo.
set has_info=1
echo Found Solr process %%k running on port !SOME_SOLR_PORT!
"%JAVA%" %SOLR_SSL_OPTS% -Dsolr.install.dir="%SOLR_TIP%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
-classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.util.SolrCLI status -solr !SOLR_URL_SCHEME!://localhost:!SOME_SOLR_PORT!/solr
@echo.
)
)
)
)
@ -1156,9 +1191,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_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
set SOME_SOLR_PORT=
For /F "Delims=" %%J In (%SOLR_TIP%\bin\%%i) do set SOME_SOLR_PORT=%%~J
For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
if NOT "!SOME_SOLR_PORT!"=="" (
for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":!SOME_SOLR_PORT! "') do (
IF NOT "%%k"=="0" set CREATE_PORT=!SOME_SOLR_PORT!
@ -1224,9 +1259,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_TIP%\bin" ^| findstr /i "^solr-.*\.port$"`) do (
set SOME_SOLR_PORT=
For /F "Delims=" %%J In (%SOLR_TIP%\bin\%%i) do set SOME_SOLR_PORT=%%~J
For /F "Delims=" %%J In ('type "%SOLR_TIP%\bin\%%i"') do set SOME_SOLR_PORT=%%~J
if NOT "!SOME_SOLR_PORT!"=="" (
for /f "tokens=2,5" %%j in ('netstat -aon ^| find "TCP " ^| find ":!SOME_SOLR_PORT! "') do (
IF NOT "%%k"=="0" set DELETE_PORT=!SOME_SOLR_PORT!

View File

@ -56,27 +56,20 @@
<target name="run-example" depends="server"
description="Run Solr interactively, via Jetty. -Dexample.debug=true to enable JVM debugger">
<property name="example.solr.home" location="${server.dir}/solr"/>
<property name="example.debug.suspend" value="n"/>
<property name="example.jetty.port" value="8983"/>
<condition property="example.jvm.line" value="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=${example.debug.suspend},address=5005" else="">
<condition property="example.jvm.line" value="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=${example.debug.suspend},address=5005">
<isset property="example.debug"/>
</condition>
<property name="example.jvm.line" value=""/>
<property name="example.heap.size" value="512M"/>
<condition property="example.cmd" value="${common-solr.dir}/bin/solr.cmd" else="${common-solr.dir}/bin/solr">
<os family="windows"/>
</condition>
<exec executable="${example.cmd}" failonerror="true">
<arg value="-e"/>
<arg value="techproducts"/>
<arg value="-p"/>
<arg value="${example.jetty.port}"/>
<arg value="-m"/>
<arg value="${example.heap.size}"/>
<arg value="-d"/>
<arg file="${server.dir}"/>
<arg value="-a"/>
<arg value="${example.jvm.line}"/>
</exec>
<java jar="${server.dir}/start.jar" fork="true" dir="${server.dir}" maxmemory="${example.heap.size}">
<jvmarg line="${example.jvm.line}"/>
<sysproperty key="solr.solr.home" file="${example.solr.home}"/>
<sysproperty key="jetty.port" value="${example.jetty.port}"/>
<sysproperty key="jetty.home" value="${server.dir}"/>
</java>
</target>
<!-- setup proxy for download tasks -->