You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2015/01/27 17:27:49 UTC

svn commit: r1655083 - in /lucene/dev/branches/lucene_solr_5_0: ./ solr/ solr/CHANGES.txt solr/bin/ solr/bin/solr.cmd solr/build.xml

Author: thelabdude
Date: Tue Jan 27 16:27:48 2015
New Revision: 1655083

URL: http://svn.apache.org/r1655083
Log:
SOLR-7016: Fix bin\solr.cmd to work in a directory with spaces in the name.

Modified:
    lucene/dev/branches/lucene_solr_5_0/   (props changed)
    lucene/dev/branches/lucene_solr_5_0/solr/   (props changed)
    lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_5_0/solr/bin/   (props changed)
    lucene/dev/branches/lucene_solr_5_0/solr/bin/solr.cmd
    lucene/dev/branches/lucene_solr_5_0/solr/build.xml   (contents, props changed)

Modified: lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt?rev=1655083&r1=1655082&r2=1655083&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt Tue Jan 27 16:27:48 2015
@@ -468,6 +468,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
 ----------------------
 

Modified: lucene/dev/branches/lucene_solr_5_0/solr/bin/solr.cmd
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_0/solr/bin/solr.cmd?rev=1655083&r1=1655082&r2=1655083&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_0/solr/bin/solr.cmd (original)
+++ lucene/dev/branches/lucene_solr_5_0/solr/bin/solr.cmd Tue Jan 27 16:27:48 2015
@@ -303,6 +303,9 @@ goto done
 
 REM Really basic command-line arg parsing
 :parse_args
+
+set "arg=%~1"
+set "firstTwo=%arg:~0,2%"
 IF "%SCRIPT_CMD%"=="" set SCRIPT_CMD=start
 IF [%1]==[] goto process_script_cmd
 IF "%1"=="-help" goto usage
@@ -334,6 +337,7 @@ IF "%1"=="-noprompt" goto set_noprompt
 IF "%1"=="-k" goto set_stop_key
 IF "%1"=="-key" goto set_stop_key
 IF "%1"=="-all" goto set_stop_all
+IF "%firstTwo%"=="-D" goto set_passthru
 IF NOT "%1"=="" goto invalid_cmd_line
 
 :set_script_cmd
@@ -519,6 +523,17 @@ SHIFT
 SHIFT
 goto parse_args
 
+:set_passthru
+set "PASSTHRU=%~1=%~2"
+IF NOT "%SOLR_OPTS%"=="" (
+  set "SOLR_OPTS=%SOLR_OPTS% %PASSTHRU%"
+) ELSE (
+  set "SOLR_OPTS=%PASSTHRU%"
+)
+SHIFT
+SHIFT
+goto parse_args
+
 :set_noprompt
 set NO_USER_PROMPT=1
 SHIFT
@@ -613,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
+                  )
+                )
+              )
+            )
+          )
         )
       )
     )
@@ -662,10 +705,14 @@ IF "%STOP_PORT%"=="" set /A STOP_PORT=%S
 
 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
+        )
+      )
     )
   )
 )
@@ -791,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%"
 
@@ -799,19 +847,23 @@ IF NOT EXIST "!SOLR_LOGS_DIR!" (
   mkdir "!SOLR_LOGS_DIR!"
 )
 
+IF NOT EXIST "%SOLR_SERVER_DIR%\tmp" (
+  mkdir "%SOLR_SERVER_DIR%\tmp"
+)
+
 @echo.
 @echo Starting Solr on port %SOLR_PORT% from %SOLR_SERVER_DIR%
 @echo.
 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% ^
-    -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" -jar start.jar
+  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% ^
-    -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" -jar start.jar > "!SOLR_LOGS_DIR!\solr-%SOLR_PORT%-console.log"
-  echo %SOLR_PORT%>%SOLR_TIP%\bin\solr-%SOLR_PORT%.port
+  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
 )
 
 
@@ -843,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.
@@ -942,19 +994,19 @@ for /l %%x in (1, 1, !CLOUD_NUM_NODES!)
       set "DASHZ="
     )
     @echo Starting node1 on port !NODE_PORT! using command:
-    @echo solr -cloud -p !NODE_PORT! !DASHZ! !DASHM! -s %CLOUD_EXAMPLE_DIR%\node1\solr
-    START "Solr-!NODE_PORT!" "%SDIR%\solr" -f -cloud -p !NODE_PORT! !DASHZ! !DASHM! -s %CLOUD_EXAMPLE_DIR%\node1\solr
+    @echo solr -cloud -p !NODE_PORT! -s example\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
       set "ZK_HOST=localhost:!ZK_PORT!"
     )
     @echo Starting node%%x on port !NODE_PORT! using command:
-    @echo solr -cloud -p !NODE_PORT! -z !ZK_HOST! !DASHM! -s %CLOUD_EXAMPLE_DIR%\node%%x\solr
-    START "Solr-!NODE_PORT!" "%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
+    @echo solr -cloud -p !NODE_PORT! -s example\node%%x\solr -z !ZK_HOST! !DASHM!
+    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
@@ -1015,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.
+          )
         )
       )
     )
@@ -1137,9 +1191,9 @@ IF "!CREATE_CONFNAME!"=="" set CREATE_CO
 
 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!
@@ -1205,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!

Modified: lucene/dev/branches/lucene_solr_5_0/solr/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_0/solr/build.xml?rev=1655083&r1=1655082&r2=1655083&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_0/solr/build.xml (original)
+++ lucene/dev/branches/lucene_solr_5_0/solr/build.xml Tue Jan 27 16:27:48 2015
@@ -53,10 +53,10 @@
     </delete>
     <echo>See ${common-solr.dir}/README.txt for how to run the Solr server.</echo>
   </target>
-  
+
   <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="example/solr"/>
+    <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">
@@ -68,6 +68,7 @@
       <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>