SOLR-6693: bin\solr.cmd doesn't support 32-bit JRE/JDK running on Windows due to parenthesis in JAVA_HOME

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1658423 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy Potter 2015-02-09 15:04:48 +00:00
parent ac5e4dd337
commit 0f78f64f43
2 changed files with 120 additions and 66 deletions

View File

@ -630,6 +630,9 @@ Bug Fixes
node attempts to become the leader for a shard.
(Mark Miller, Maxim Novikov)
* SOLR-6693: bin\solr.cmd doesn't support 32-bit JRE/JDK running on Windows due to
parenthesis in JAVA_HOME. (Timothy Potter, Christopher Hewitt, Jan Høydahl)
Optimizations
----------------------

View File

@ -47,16 +47,22 @@ REM Try to detect JAVA_HOME from the registry
IF NOT DEFINED JAVA_HOME (
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment" /v CurrentVersion') DO set CurVer=%%B
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment\!CurVer!" /v JavaHome') DO (
set JAVA_HOME=%%B
set "JAVA_HOME=%%B"
)
)
IF NOT DEFINED JAVA_HOME goto need_java_home
set JAVA_HOME=%JAVA_HOME:"=%
"%JAVA_HOME%"\bin\java -version:1.8 -version > nul 2>&1
IF ERRORLEVEL 1 "%JAVA_HOME%"\bin\java -version:1.7 -version > nul 2>&1
IF ERRORLEVEL 1 goto need_java_vers
IF %JAVA_HOME:~-1%==\ SET JAVA_HOME=%JAVA_HOME:~0,-1%
IF NOT EXIST "%JAVA_HOME%\bin\java.exe" (
set "SCRIPT_ERROR=java.exe not found in %JAVA_HOME%\bin. Please set JAVA_HOME to a valid JRE / JDK directory."
goto err
)
set "JAVA=%JAVA_HOME%\bin\java"
CALL :resolve_java_version
IF !JAVA_MAJOR_VERSION! LSS 8 (
set "SCRIPT_ERROR=Java 1.8 or later is required to run Solr. Current Java version is: !JAVA_VERSION_INFO!"
goto err
)
set "DEFAULT_SERVER_DIR=%SOLR_TIP%\server"
@ -543,9 +549,10 @@ REM Perform the requested command after processing args
:process_script_cmd
IF "%verbose%"=="1" (
@echo Using Solr root directory: %SOLR_TIP%
@echo Using Java: %JAVA%
CALL :safe_echo "Using Solr root directory: %SOLR_TIP%"
CALL :safe_echo "Using Java: %JAVA%"
"%JAVA%" -version
@echo.
)
IF NOT "%SOLR_HOST%"=="" (
@ -554,10 +561,10 @@ IF NOT "%SOLR_HOST%"=="" (
set SOLR_HOST_ARG=
)
IF "%SOLR_SERVER_DIR%"=="" set SOLR_SERVER_DIR=%DEFAULT_SERVER_DIR%
IF "%SOLR_SERVER_DIR%"=="" set "SOLR_SERVER_DIR=%DEFAULT_SERVER_DIR%"
IF NOT EXIST "%SOLR_SERVER_DIR%" (
set SCRIPT_ERROR=Solr server directory %SOLR_SERVER_DIR% not found!
set "SCRIPT_ERROR=Solr server directory %SOLR_SERVER_DIR% not found!"
goto err
)
@ -601,13 +608,13 @@ IF NOT EXIST "%SOLR_HOME%\" (
) ELSE IF EXIST "%cd%\%SOLR_HOME%" (
set "SOLR_HOME=%cd%\%SOLR_HOME%"
) ELSE (
set SCRIPT_ERROR=Solr home directory %SOLR_HOME% not found!
set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% not found!"
goto err
)
)
IF NOT EXIST "%SOLR_HOME%\solr.xml" (
set SCRIPT_ERROR=Solr home directory %SOLR_HOME% must contain solr.xml!
set "SCRIPT_ERROR=Solr home directory %SOLR_HOME% must contain solr.xml!"
goto err
)
@ -624,6 +631,16 @@ IF NOT "%TMP%"=="%SOLR_HOME%" (
set "LOG4J_CONFIG=file:%EXAMPLE_DIR%\resources\log4j.properties"
)
set IS_RESTART=0
IF "%SCRIPT_CMD%"=="restart" (
IF "%SOLR_PORT%"=="" (
set "SCRIPT_ERROR=Must specify the port when trying to restart Solr."
goto err
)
set SCRIPT_CMD=stop
set IS_RESTART=1
)
@REM stop logic here
IF "%SCRIPT_CMD%"=="stop" (
IF "%SOLR_PORT%"=="" (
@ -665,7 +682,7 @@ IF "%SCRIPT_CMD%"=="stop" (
)
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.
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 (
@ -697,9 +714,12 @@ IF "%SCRIPT_CMD%"=="stop" (
)
if "!found_it!"=="0" echo No Solr found running on port %SOLR_PORT%
)
goto done
IF "!IS_RESTART!"=="0" goto done
)
IF "!IS_RESTART!"=="1" set SCRIPT_CMD=start
IF "%SOLR_PORT%"=="" set SOLR_PORT=8983
IF "%STOP_PORT%"=="" set /A STOP_PORT=%SOLR_PORT% - 1000
@ -717,6 +737,26 @@ IF "%SCRIPT_CMD%"=="start" (
)
)
@REM determine if -server flag is supported by current JVM
"%JAVA%" -server -version > nul 2>&1
IF ERRORLEVEL 1 (
set IS_JDK=false
set "SERVEROPT="
@echo WARNING: You are using a JRE without support for -server option. Please upgrade to latest JDK for best performance
@echo.
) ELSE (
set IS_JDK=true
set "SERVEROPT=-server"
)
"%JAVA%" -d64 -version > nul 2>&1
IF ERRORLEVEL 1 (
set "IS_64BIT=false"
@echo WARNING: 32-bit Java detected. Not recommended for production. Point your JAVA_HOME to a 64-bit JDK
@echo.
) ELSE (
set IS_64bit=true
)
REM backup log files (use current timestamp for backup name)
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
@ -731,9 +771,6 @@ IF EXIST "!SOLR_LOGS_DIR!\solr_gc.log" (
move /Y "!SOLR_LOGS_DIR!\solr_gc.log" "!SOLR_LOGS_DIR!\solr_gc_log_!now_ts!"
)
REM if verbose gc logging enabled, setup the location of the log file
IF NOT "%GC_LOG_OPTS%"=="" set GC_LOG_OPTS=%GC_LOG_OPTS% -Xloggc:"!SOLR_LOGS_DIR!/solr_gc.log"
IF "%SOLR_MODE%"=="solrcloud" (
IF "%ZK_CLIENT_TIMEOUT%"=="" set "ZK_CLIENT_TIMEOUT=15000"
@ -760,7 +797,7 @@ IF "%ENABLE_REMOTE_JMX_OPTS%"=="true" (
-Dcom.sun.management.jmxremote.port=!RMI_PORT! ^
-Dcom.sun.management.jmxremote.rmi.port=!RMI_PORT!
IF NOT "%SOLR_HOST%"=="" set REMOTE_JMX_OPTS=%REMOTE_JMX_OPTS% -Djava.rmi.server.hostname=%SOLR_HOST%
IF NOT "%SOLR_HOST%"=="" set REMOTE_JMX_OPTS=%REMOTE_JMX_OPTS% -Djava.rmi.server.hostname=%SOLR_HOST%
) ELSE (
set REMOTE_JMX_OPTS=
)
@ -769,61 +806,47 @@ IF NOT "%SOLR_HEAP%"=="" set SOLR_JAVA_MEM=-Xms%SOLR_HEAP% -Xmx%SOLR_HEAP%
IF "%SOLR_JAVA_MEM%"=="" set SOLR_JAVA_MEM=-Xms512m -Xmx512m
IF "%SOLR_TIMEZONE%"=="" set SOLR_TIMEZONE=UTC
@REM Add Java version specific flags if needed
set JAVAVER=
set JAVA_MAJOR=
set JAVA_BUILD=0
"%JAVA%" -version 2>&1 | findstr /i "version" > javavers
set /p JAVAVEROUT=<javavers
del javavers
for /f "tokens=3" %%g in ("!JAVAVEROUT!") do (
set JAVAVER=%%g
set JAVAVER=!JAVAVER:"=!
for /f "delims=_ tokens=1-3" %%v in ("!JAVAVER!") do (
set JAVA_MAJOR=!JAVAVER:~0,3!
set /a JAVA_BUILD=%%w
)
)
IF "!JAVA_MAJOR!"=="1.7" (
IF "!JAVA_MAJOR_VERSION!"=="7" (
set "GC_TUNE=%GC_TUNE% -XX:CMSFullGCsBeforeCompaction=1 -XX:CMSTriggerPermRatio=80"
IF !JAVA_BUILD! GEQ 40 (
IF !JAVA_BUILD! LEQ 51 (
set "GC_TUNE=!GC_TUNE! -XX:-UseSuperWord"
@echo WARNING: Java version !JAVAVER! has known bugs with Lucene and requires the -XX:-UseSuperWord flag. Please consider upgrading your JVM.
@echo WARNING: Java version !JAVA_VERSION_INFO! has known bugs with Lucene and requires the -XX:-UseSuperWord flag. Please consider upgrading your JVM.
)
)
)
IF "%verbose%"=="1" (
@echo Starting Solr using the following settings:
@echo JAVA = %JAVA%
@echo SOLR_SERVER_DIR = %SOLR_SERVER_DIR%
@echo SOLR_HOME = %SOLR_HOME%
@echo SOLR_HOST = %SOLR_HOST%
@echo SOLR_PORT = %SOLR_PORT%
@echo STOP_PORT = %STOP_PORT%
@echo SOLR_JAVA_MEM = %SOLR_JAVA_MEM%
@echo GC_TUNE = !GC_TUNE!
@echo GC_LOG_OPTS = %GC_LOG_OPTS%
@echo SOLR_TIMEZONE = %SOLR_TIMEZONE%
@echo Starting Solr using the following settings:
CALL :safe_echo " JAVA = %JAVA%"
CALL :safe_echo " SOLR_SERVER_DIR = %SOLR_SERVER_DIR%"
CALL :safe_echo " SOLR_HOME = %SOLR_HOME%"
@echo SOLR_HOST = %SOLR_HOST%
@echo SOLR_PORT = %SOLR_PORT%
@echo STOP_PORT = %STOP_PORT%
@echo SOLR_JAVA_MEM = %SOLR_JAVA_MEM%
@echo GC_TUNE = !GC_TUNE!
@echo GC_LOG_OPTS = %GC_LOG_OPTS%
@echo SOLR_TIMEZONE = %SOLR_TIMEZONE%
IF "%SOLR_MODE%"=="solrcloud" (
@echo CLOUD_MODE_OPTS = %CLOUD_MODE_OPTS%
)
IF "%SOLR_MODE%"=="solrcloud" (
@echo CLOUD_MODE_OPTS = %CLOUD_MODE_OPTS%
)
IF NOT "%SOLR_OPTS%"=="" (
@echo SOLR_OPTS = %SOLR_OPTS%
)
IF NOT "%SOLR_OPTS%"=="" (
@echo SOLR_OPTS = %SOLR_OPTS%
)
IF NOT "%SOLR_ADDL_ARGS%"=="" (
@echo SOLR_ADDL_ARGS = %SOLR_ADDL_ARGS%
)
IF NOT "%SOLR_ADDL_ARGS%"=="" (
CALL :safe_echo " SOLR_ADDL_ARGS = %SOLR_ADDL_ARGS%"
)
IF "%ENABLE_REMOTE_JMX_OPTS%"=="true" (
@echo RMI_PORT = !RMI_PORT!
@echo REMOTE_JMX_OPTS = %REMOTE_JMX_OPTS%
)
IF "%ENABLE_REMOTE_JMX_OPTS%"=="true" (
@echo RMI_PORT = !RMI_PORT!
@echo REMOTE_JMX_OPTS = %REMOTE_JMX_OPTS%
)
@echo.
)
set START_OPTS=-Duser.timezone=%SOLR_TIMEZONE% -Djava.net.preferIPv4Stack=true
@ -852,21 +875,20 @@ IF NOT EXIST "%SOLR_SERVER_DIR%\tmp" (
)
@echo.
@echo Starting Solr on port %SOLR_PORT% from %SOLR_SERVER_DIR%
CALL :safe_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% -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
"%JAVA%" %SERVEROPT% -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -Xloggc:"!SOLR_LOGS_DIR!"/solr_gc.log -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%" /D "%SOLR_SERVER_DIR%" "%JAVA%" -server -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" "%JAVA%" %SERVEROPT% -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -Xloggc:"!SOLR_LOGS_DIR!"/solr_gc.log -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
)
set EXAMPLE_NAME=%EXAMPLE%
set CREATE_EXAMPLE_CONFIG=
IF "%EXAMPLE%"=="schemaless" (
@ -894,7 +916,7 @@ IF NOT "!CREATE_EXAMPLE_CONFIG!"=="" (
IF "%EXAMPLE%"=="techproducts" (
@echo.
@echo Indexing tech product example docs from %SOLR_TIP%\example\exampledocs
@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"
)
@ -942,14 +964,14 @@ IF NOT DEFINED CLOUD_NUM_NODES (
set "CLOUD_EXAMPLE_DIR=%SOLR_TIP%\example\cloud"
@echo Creating Solr home %CLOUD_EXAMPLE_DIR%\node1\solr
@echo Creating Solr home "%CLOUD_EXAMPLE_DIR%\node1\solr"
mkdir "%CLOUD_EXAMPLE_DIR%\node1\solr"
copy "%DEFAULT_SERVER_DIR%\solr\solr.xml" "%CLOUD_EXAMPLE_DIR%\node1\solr\solr.xml"
copy "%DEFAULT_SERVER_DIR%\solr\zoo.cfg" "%CLOUD_EXAMPLE_DIR%\node1\solr\zoo.cfg"
for /l %%x in (2, 1, !CLOUD_NUM_NODES!) do (
IF NOT EXIST "%SOLR_TIP%\node%%x" (
@echo Cloning %CLOUD_EXAMPLE_DIR%\node1 into %CLOUD_EXAMPLE_DIR%\node%%x
@echo Cloning "%CLOUD_EXAMPLE_DIR%\node1" into "%CLOUD_EXAMPLE_DIR%\node%%x"
xcopy /Q /E /I "%CLOUD_EXAMPLE_DIR%\node1" "%CLOUD_EXAMPLE_DIR%\node%%x"
)
)
@ -1331,3 +1353,32 @@ exit /b 1
:done
ENDLOCAL
GOTO :eof
REM Tests what Java we have and sets some global variables
:resolve_java_version
set JAVA_MAJOR_VERSION=0
set JAVA_VERSION_INFO=
set JAVA_BUILD=0
"%JAVA%" -version 2>&1 | findstr /i "version" > javavers
set /p JAVAVEROUT=<javavers
del javavers
for /f "tokens=3" %%g in ("!JAVAVEROUT!") do (
set JAVA_VERSION_INFO=%%g
set JAVA_VERSION_INFO=!JAVA_VERSION_INFO:"=!
for /f "delims=_ tokens=1-3" %%v in ("!JAVA_VERSION_INFO!") do (
set JAVA_MAJOR=!JAVA_VERSION_INFO:~0,3!
set /a JAVA_BUILD=%%w
set /a JAVA_MAJOR_VERSION=!JAVA_MAJOR:~2,1!*1
)
)
GOTO :eof
REM Safe echo which does not mess with () in strings
:safe_echo
set "eout=%1"
set eout=%eout:"=%
echo !eout!
GOTO :eof