SOLR-6982: bin/solr and SolrCLI should support SSL-related Java System Properties

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1652208 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy Potter 2015-01-15 18:24:48 +00:00
parent 4a17f23182
commit 7401236745
6 changed files with 104 additions and 30 deletions

View File

@ -713,6 +713,9 @@ Other Changes
* SOLR-6926: "ant example" makes no sense anymore - should be "ant server"
(Ramkumar Aiyengar, Timothy Potter)
* SOLR-6982: bin/solr and SolrCLI should support SSL-related Java System Properties
(Timothy Potter)
================== 4.10.3 ==================
Bug Fixes

View File

@ -112,6 +112,12 @@ fi
# test that Java exists and is executable on this server
$JAVA -version >/dev/null 2>&1 || { echo >&2 "Java is required to run Solr! Please install Java 7 or 8 before running this script."; exit 1; }
# URL scheme for contacting Solr
SOLR_URL_SCHEME=http
if [ -n "$SOLR_SSL_OPTS" ]; then
SOLR_URL_SCHEME=https
fi
function print_usage() {
CMD="$1"
ERROR_MSG="$2"
@ -336,7 +342,7 @@ function run_tool() {
(mkdir -p $DEFAULT_SERVER_DIR/solr-webapp/webapp && cd $DEFAULT_SERVER_DIR/solr-webapp/webapp && jar xf $DEFAULT_SERVER_DIR/webapps/solr.war)
fi
"$JAVA" -Dlog4j.configuration=file:$DEFAULT_SERVER_DIR/scripts/cloud-scripts/log4j.properties \
"$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 $*
@ -355,7 +361,7 @@ function get_info() {
port=`jetty_port "$ID"`
if [ "$port" != "" ]; then
echo -e "\nSolr process $ID running on port $port"
run_tool status -solr http://localhost:$port/solr
run_tool status -solr $SOLR_URL_SCHEME://localhost:$port/solr
echo ""
else
echo -e "\nSolr process $ID from $PIDF not found."
@ -372,7 +378,7 @@ function get_info() {
if [ "$port" != "" ]; then
echo ""
echo "Solr process $ID running on port $port"
run_tool status -solr http://localhost:$port/solr
run_tool status -solr $SOLR_URL_SCHEME://localhost:$port/solr
echo ""
fi
done
@ -395,7 +401,7 @@ function stop_solr() {
if [ "$SOLR_PID" != "" ]; then
echo -e "Sending stop command to Solr running on port $SOLR_PORT ... waiting 5 seconds to allow Jetty process $SOLR_PID to stop gracefully."
$JAVA -jar $DIR/start.jar STOP.PORT=$STOP_PORT STOP.KEY=$STOP_KEY --stop || true
$JAVA $SOLR_SSL_OPTS -jar $DIR/start.jar STOP.PORT=$STOP_PORT STOP.KEY=$STOP_KEY --stop || true
(sleep 5) &
spinner $!
rm -f $SOLR_PID_DIR/solr-$SOLR_PORT.pid
@ -627,14 +633,14 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CM
fi
if [ "$SCRIPT_CMD" == "create_core" ]; then
run_tool create_core -name $CREATE_NAME -solrUrl http://localhost:$CREATE_PORT/solr \
run_tool create_core -name $CREATE_NAME -solrUrl $SOLR_URL_SCHEME://localhost:$CREATE_PORT/solr \
-confdir $CREATE_CONFDIR -configsetsDir $SOLR_TIP/server/solr/configsets
exit $?
else
run_tool $SCRIPT_CMD -name $CREATE_NAME -shards $CREATE_NUM_SHARDS -replicationFactor $CREATE_REPFACT \
-confname $CREATE_CONFNAME -confdir $CREATE_CONFDIR \
-configsetsDir $SOLR_TIP/server/solr/configsets \
-solrUrl http://localhost:$CREATE_PORT/solr
-solrUrl $SOLR_URL_SCHEME://localhost:$CREATE_PORT/solr
exit $?
fi
fi
@ -1141,6 +1147,16 @@ function launch_solr() {
fi
fi
# If SSL-related system props are set, add them to SOLR_OPTS
if [ -n "$SOLR_SSL_OPTS" ]; then
# If using SSL and jetty.ssl.port not set explicitly, use the jetty.port
SSL_PORT_PROP="-Djetty.ssl.port=$SOLR_PORT"
if [ -n "$SOLR_SSL_PORT" ]; then
SSL_PORT_PROP="-Djetty.ssl.port=$SOLR_SSL_PORT"
fi
SOLR_OPTS="$SOLR_OPTS $SOLR_SSL_OPTS $SSL_PORT_PROP"
fi
if $verbose ; then
echo -e "\nStarting Solr using the following settings:"
echo -e " JAVA = $JAVA"
@ -1251,17 +1267,17 @@ if [ "$EXAMPLE" != "cloud" ]; then
run_tool create -name $EXAMPLE_NAME -shards 1 -replicationFactor 1 \
-confname $EXAMPLE_NAME -confdir $EXAMPLE_CONFIGSET \
-configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl http://localhost:$SOLR_PORT/solr
-configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl $SOLR_URL_SCHEME://localhost:$SOLR_PORT/solr
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$EXAMPLE" == "techproducts" ]; then
echo "Indexing tech product example docs from $SOLR_TIP/example/exampledocs"
"$JAVA" -Durl=http://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
fi
echo -e "\nSolr $EXAMPLE example launched successfully. Direct your Web browser to http://localhost:$SOLR_PORT/solr to visit the Solr Admin UI\n"
echo -e "\nSolr $EXAMPLE example launched successfully. Direct your Web browser to $SOLR_URL_SCHEME://localhost:$SOLR_PORT/solr to visit the Solr Admin UI\n"
fi
else
#
@ -1374,9 +1390,9 @@ else
run_tool create_collection -name $CLOUD_COLLECTION -shards $CLOUD_NUM_SHARDS -replicationFactor $CLOUD_REPFACT \
-confname $CLOUD_COLLECTION -confdir $CLOUD_CONFIG \
-configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl http://localhost:$SOLR_PORT/solr
-configsetsDir $SOLR_TIP/server/solr/configsets -solrUrl $SOLR_URL_SCHEME://localhost:$SOLR_PORT/solr
echo -e "\n\nSolrCloud example running, please visit http://localhost:$SOLR_PORT/solr \n\n"
echo -e "\n\nSolrCloud example running, please visit $SOLR_URL_SCHEME://localhost:$SOLR_PORT/solr \n\n"
fi
exit $?

View File

@ -6,7 +6,7 @@
@REM (the "License"); you may not use this file except in compliance with
@REM the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM !SOLR_URL_SCHEME!://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing, software
@REM distributed under the License is distributed on an "AS IS" BASIS,
@ -36,6 +36,11 @@ REM command line args
IF "%SOLR_INCLUDE%"=="" set "SOLR_INCLUDE=%SOLR_TIP%\bin\solr.in.cmd"
IF EXIST "%SOLR_INCLUDE%" CALL "%SOLR_INCLUDE%"
REM URL scheme for contacting Solr
set SOLR_URL_SCHEME=http
IF DEFINED SOLR_SSL_OPTS set SOLR_URL_SCHEME=https
IF NOT DEFINED SOLR_SSL_OPTS set SOLR_SSL_OPTS=
REM Verify Java is available
IF DEFINED SOLR_JAVA_HOME set "JAVA_HOME=%SOLR_JAVA_HOME%"
REM Try to detect JAVA_HOME from the registry
@ -599,7 +604,7 @@ IF "%SCRIPT_CMD%"=="stop" (
for /f "tokens=2,5" %%j in ('netstat -aon ^| find /i "listening" ^| find ":!SOME_SOLR_PORT!"') do (
@echo Stopping Solr running on port !SOME_SOLR_PORT!
set /A STOP_PORT=!SOME_SOLR_PORT! - 1000
"%JAVA%" -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stop
"%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
@ -617,7 +622,7 @@ IF "%SCRIPT_CMD%"=="stop" (
set found_it=1
@echo Stopping Solr running on port %SOLR_PORT%
set /A STOP_PORT=%SOLR_PORT% - 1000
"%JAVA%" -Djetty.home="%SOLR_SERVER_DIR%" -jar "%SOLR_SERVER_DIR%\start.jar" STOP.PORT=!STOP_PORT! STOP.KEY=%STOP_KEY% --stop
"%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
@ -755,6 +760,11 @@ IF NOT "%REMOTE_JMX_OPTS%"=="" set "START_OPTS=%START_OPTS% %REMOTE_JMX_OPTS%"
IF NOT "%SOLR_ADDL_ARGS%"=="" set "START_OPTS=%START_OPTS% %SOLR_ADDL_ARGS%"
IF NOT "%SOLR_HOST_ARG%"=="" set "START_OPTS=%START_OPTS% %SOLR_HOST_ARG%"
IF NOT "%SOLR_OPTS%"=="" set "START_OPTS=%START_OPTS% %SOLR_OPTS%"
IF NOT "%SOLR_SSL_OPTS%"=="" (
set "SSL_PORT_PROP=-Djetty.ssl.port=%SOLR_PORT%"
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%"
cd "%SOLR_SERVER_DIR%"
@ -796,14 +806,14 @@ IF "%EXAMPLE%"=="techproducts" (
IF NOT "!CREATE_EXAMPLE_CONFIG!"=="" (
timeout /T 10
IF "%SOLR_MODE%"=="solrcloud" (
"%JAVA%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
"%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 create_collection -name !EXAMPLE_NAME! -shards 1 -replicationFactor 1 ^
-confdir !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets" -solrUrl http://localhost:%SOLR_PORT%/solr
-confdir !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets" -solrUrl !SOLR_URL_SCHEME!://localhost:%SOLR_PORT%/solr
) ELSE (
"%JAVA%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
"%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 create_core -name !EXAMPLE_NAME! -solrUrl http://localhost:%SOLR_PORT%/solr ^
org.apache.solr.util.SolrCLI create_core -name !EXAMPLE_NAME! -solrUrl !SOLR_URL_SCHEME!://localhost:%SOLR_PORT%/solr ^
-confdir !CREATE_EXAMPLE_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets"
)
)
@ -811,14 +821,14 @@ IF NOT "!CREATE_EXAMPLE_CONFIG!"=="" (
IF "%EXAMPLE%"=="techproducts" (
@echo.
@echo Indexing tech product example docs from %SOLR_TIP%\example\exampledocs
"%JAVA%" -Durl=http://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.
IF NOT "%EXAMPLE%"=="" (
@echo Solr %EXAMPLE% example launched successfully.
)
@echo Direct your Web browser to http://localhost:%SOLR_PORT%/solr to visit the Solr Admin UI
@echo Direct your Web browser to !SOLR_URL_SCHEME!://localhost:%SOLR_PORT%/solr to visit the Solr Admin UI
@echo.
goto done
@ -967,13 +977,13 @@ echo !CLOUD_CONFIG!
goto create_collection
:create_collection
"%JAVA%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
"%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 create_collection -name !CLOUD_COLLECTION! -shards !CLOUD_NUM_SHARDS! -replicationFactor !CLOUD_REPFACT! ^
-confdir !CLOUD_CONFIG! -configsetsDir "%SOLR_SERVER_DIR%\solr\configsets" -zkHost %zk_host%
echo.
echo SolrCloud example is running, please visit http://localhost:%NODE1_PORT%/solr"
echo SolrCloud example is running, please visit !SOLR_URL_SCHEME!://localhost:%NODE1_PORT%/solr"
echo.
REM End of interactive cloud example
@ -992,9 +1002,9 @@ for /f "usebackq" %%i in (`dir /b %SOLR_TIP%\bin ^| findstr /i "^solr-.*\.port$"
@echo.
set has_info=1
echo Found Solr process %%k running on port !SOME_SOLR_PORT!
"%JAVA%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
"%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 http://localhost:!SOME_SOLR_PORT!/solr
org.apache.solr.util.SolrCLI status -solr !SOLR_URL_SCHEME!://localhost:!SOME_SOLR_PORT!/solr
@echo.
)
)
@ -1030,7 +1040,7 @@ goto parse_healthcheck_args
:run_healthcheck
IF NOT DEFINED HEALTHCHECK_COLLECTION goto healthcheck_usage
IF NOT DEFINED HEALTHCHECK_ZK_HOST set "HEALTHCHECK_ZK_HOST=localhost:9983"
"%JAVA%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
"%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 healthcheck -collection !HEALTHCHECK_COLLECTION! -zkHost !HEALTHCHECK_ZK_HOST!
goto done
@ -1119,15 +1129,15 @@ if "!CREATE_PORT!"=="" (
)
if "%SCRIPT_CMD%"=="create_core" (
"%JAVA%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
"%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 create_core -name !CREATE_NAME! -solrUrl http://localhost:!CREATE_PORT!/solr ^
org.apache.solr.util.SolrCLI create_core -name !CREATE_NAME! -solrUrl !SOLR_URL_SCHEME!://localhost:!CREATE_PORT!/solr ^
-confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets"
) else (
"%JAVA%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^
"%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 create -name !CREATE_NAME! -shards !CREATE_NUM_SHARDS! -replicationFactor !CREATE_REPFACT! ^
-confname !CREATE_CONFNAME! -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets" -solrUrl http://localhost:!CREATE_PORT!/solr
-confname !CREATE_CONFNAME! -confdir !CREATE_CONFDIR! -configsetsDir "%SOLR_TIP%\server\solr\configsets" -solrUrl !SOLR_URL_SCHEME!://localhost:!CREATE_PORT!/solr
)
goto done

View File

@ -79,3 +79,11 @@ REM set SOLR_HOME=
REM Sets the port Solr binds to, default is 8983
REM set SOLR_PORT=8983
REM Uncomment to set SSL-related system properties
REM Be sure to update the paths to the correct keystore for your environment
REM set SOLR_SSL_OPTS=-Djavax.net.ssl.keyStore=etc/solr-ssl.keystore.jks -Djavax.net.ssl.keyStorePassword=secret -Djavax.net.ssl.trustStore=etc/solr-ssl.keystore.jks -Djavax.net.ssl.trustStorePassword=secret
REM Uncomment to set a specific SSL port (-Djetty.ssl.port=N); if not set
REM and you are using SSL, then the start script will use SOLR_PORT for the SSL port
REM set SOLR_SSL_PORT=

View File

@ -91,3 +91,13 @@ ENABLE_REMOTE_JMX_OPTS="false"
# Sets the port Solr binds to, default is 8983
#SOLR_PORT=8983
# Uncomment to set SSL-related system properties
# Be sure to update the paths to the correct keystore for your environment
#SOLR_SSL_OPTS="-Djavax.net.ssl.keyStore=etc/solr-ssl.keystore.jks \
#-Djavax.net.ssl.keyStorePassword=secret \
#-Djavax.net.ssl.trustStore=etc/solr-ssl.keystore.jks \
#-Djavax.net.ssl.trustStorePassword=secret"
# Uncomment to set a specific SSL port (-Djetty.ssl.port=N); if not set
# and you are using SSL, then the start script will use SOLR_PORT for the SSL port
#SOLR_SSL_PORT=

View File

@ -192,9 +192,36 @@ public class SolrCLI {
CommandLine cli =
processCommandLineArgs(joinCommonAndToolOptions(tool.getOptions()), toolArgs);
// for SSL support, try to accommodate relative paths set for SSL store props
String solrInstallDir = System.getProperty("solr.install.dir");
if (solrInstallDir != null) {
checkSslStoreSysProp(solrInstallDir, "keyStore");
checkSslStoreSysProp(solrInstallDir, "trustStore");
}
// run the tool
System.exit(tool.runTool(cli));
}
protected static void checkSslStoreSysProp(String solrInstallDir, String key) {
String sysProp = "javax.net.ssl."+key;
String keyStore = System.getProperty(sysProp);
if (keyStore == null)
return;
File keyStoreFile = new File(keyStore);
if (keyStoreFile.isFile())
return; // configured setting is OK
keyStoreFile = new File(solrInstallDir, "server/"+keyStore);
if (keyStoreFile.isFile()) {
System.setProperty(sysProp, keyStoreFile.getAbsolutePath());
} else {
System.err.println("WARNING: "+sysProp+" file "+keyStore+
" not found! https requests to Solr will likely fail; please update your "+
sysProp+" setting to use an absolute path.");
}
}
/**
* Support options common to all tools.
@ -882,7 +909,7 @@ public class SolrCLI {
if (collection == null)
throw new IllegalArgumentException("Must provide a collection to run a healthcheck against!");
log.info("Running healthcheck for "+collection);
log.debug("Running healthcheck for "+collection);
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();