SOLR-3617: hardening command-line parsing and a few minor bug fixes found by QA testing.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1619025 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy Potter 2014-08-20 02:56:18 +00:00
parent dd1e04cc0f
commit 7223a40b6d
3 changed files with 188 additions and 57 deletions

View File

@ -46,7 +46,13 @@
SOLR_SCRIPT="$0" SOLR_SCRIPT="$0"
verbose=false verbose=false
isLegacyExampleDir=false THIS_OS=`uname -s`
# for now, we don't support running this script from cygwin due to problems
# like not having lsof, ps waux, curl, and awkward directory handling
if [ "${THIS_OS:0:6}" == "CYGWIN" ]; then
echo -e "This script does not support cygwin due to severe limitations and lack of adherence\nto BASH standards, such as lack of lsof, curl, and ps options.\n\nPlease use the native solr.cmd script on Windows!"
exit 1
fi
# Resolve symlinks to this script # Resolve symlinks to this script
while [ -h "$SOLR_SCRIPT" ] ; do while [ -h "$SOLR_SCRIPT" ] ; do
@ -69,7 +75,6 @@ if [ -e "$SOLR_TIP/server/start.jar" ]; then
DEFAULT_SERVER_DIR=$SOLR_TIP/server DEFAULT_SERVER_DIR=$SOLR_TIP/server
else else
DEFAULT_SERVER_DIR=$SOLR_TIP/example DEFAULT_SERVER_DIR=$SOLR_TIP/example
isLegacyExampleDir=true
fi fi
if [ "$SOLR_JAVA_HOME" != "" ]; then if [ "$SOLR_JAVA_HOME" != "" ]; then
@ -93,7 +98,7 @@ function print_usage() {
ERROR_MSG="$2" ERROR_MSG="$2"
if [ "$ERROR_MSG" != "" ]; then if [ "$ERROR_MSG" != "" ]; then
echo "$ERROR_MSG" echo -e "\nERROR: $ERROR_MSG\n"
fi fi
if [ "$CMD" == "" ]; then if [ "$CMD" == "" ]; then
@ -147,7 +152,7 @@ function print_usage() {
echo "" echo ""
echo " -k <key> Stop key; default is solrrocks" echo " -k <key> Stop key; default is solrrocks"
echo "" echo ""
echo " -p <port> Specify the port to start the Solr HTTP listener on; default is 8983" echo " -p <port> Specify the port the Solr HTTP listener is bound to; default is 8983"
echo "" echo ""
echo " -V Verbose messages from this script" echo " -V Verbose messages from this script"
echo "" echo ""
@ -301,15 +306,23 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; then
while true; do while true; do
case $1 in case $1 in
-c|-collection) -c|-collection)
if [ "${2:0:1}" == "-" ]; then
print_usage "$SCRIPT_CMD" "$2 is not a valid collection!"
exit 1
fi
HEALTHCHECK_COLLECTION=$2 HEALTHCHECK_COLLECTION=$2
shift 2 shift 2
;; ;;
-z|-zkhost) -z|-zkhost)
if [ "${2:0:1}" == "-" ]; then
print_usage "$SCRIPT_CMD" "$2 is not a valid ZooKeeper connnection string!"
exit 1
fi
ZK_HOST="$2" ZK_HOST="$2"
shift 2 shift 2
;; ;;
-help|-usage) -help|-usage)
print_usage "$SCRIPT_CMD" "" print_usage "$SCRIPT_CMD"
exit 0 exit 0
;; ;;
--) --)
@ -318,8 +331,7 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; then
;; ;;
*) *)
if [ "$1" != "" ]; then if [ "$1" != "" ]; then
echo "Error parsing argument $1!" >&2 print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
print_usage "$SCRIPT_CMD"
exit 1 exit 1
else else
break # out-of-args, stop looping break # out-of-args, stop looping
@ -332,6 +344,12 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; then
if [ "$ZK_HOST" == "" ]; then if [ "$ZK_HOST" == "" ]; then
ZK_HOST=localhost:9983 ZK_HOST=localhost:9983
fi fi
if [ "$HEALTHCHECK_COLLECTION" == "" ]; then
echo "collection parameter is required!"
print_usage "healthcheck"
exit 1
fi
run_tool healthcheck -zkHost $ZK_HOST -collection $HEALTHCHECK_COLLECTION run_tool healthcheck -zkHost $ZK_HOST -collection $HEALTHCHECK_COLLECTION
@ -373,6 +391,11 @@ if [ $# -gt 0 ]; then
shift shift
;; ;;
-d|-dir) -d|-dir)
if [ "${2:0:1}" == "-" ]; then
print_usage "$SCRIPT_CMD" "$2 is not a valid directory!"
exit 1
fi
# see if the arg value is relative to the tip vs full path # see if the arg value is relative to the tip vs full path
if [ -d "$SOLR_TIP/$2" ]; then if [ -d "$SOLR_TIP/$2" ]; then
SOLR_SERVER_DIR="$SOLR_TIP/$2" SOLR_SERVER_DIR="$SOLR_TIP/$2"
@ -382,6 +405,10 @@ if [ $# -gt 0 ]; then
shift 2 shift 2
;; ;;
-e|-example) -e|-example)
if [ "${2:0:1}" == "-" ]; then
print_usage "$SCRIPT_CMD" "$2 is not a valid example!"
exit 1
fi
EXAMPLE="$2" EXAMPLE="$2"
shift 2 shift 2
;; ;;
@ -390,23 +417,40 @@ if [ $# -gt 0 ]; then
shift shift
;; ;;
-h|-host) -h|-host)
if [ "${2:0:1}" == "-" ]; then
print_usage "$SCRIPT_CMD" "$2 is not a valid hostname!"
exit 1
fi
SOLR_HOST="$2" SOLR_HOST="$2"
shift 2 shift 2
;; ;;
-m|-memory) -m|-memory)
if [ "${2:0:1}" == "-" ]; then
print_usage "$SCRIPT_CMD" "$2 is not a valid memory setting!"
exit 1
fi
SOLR_HEAP="$2" SOLR_HEAP="$2"
shift 2 shift 2
;; ;;
-p|-port) -p|-port)
if [ "${2:0:1}" == "-" ]; then
print_usage "$SCRIPT_CMD" "$2 is not a valid port!"
exit 1
fi
SOLR_PORT="$2" SOLR_PORT="$2"
shift 2 shift 2
;; ;;
-z|-zkhost) -z|-zkhost)
if [ "${2:0:1}" == "-" ]; then
print_usage "$SCRIPT_CMD" "$2 is not a valid ZooKeeper connection string!"
exit 1
fi
ZK_HOST="$2" ZK_HOST="$2"
shift 2 shift 2
;; ;;
-help|-usage) -help|-usage)
print_usage "$SCRIPT_CMD" "" print_usage "$SCRIPT_CMD"
exit 0 exit 0
;; ;;
-noprompt) -noprompt)
@ -423,8 +467,7 @@ if [ $# -gt 0 ]; then
;; ;;
*) *)
if [ "$1" != "" ]; then if [ "$1" != "" ]; then
echo "Error parsing argument $1!" >&2 print_usage "$SCRIPT_CMD" "Error parsing argument $1!"
print_usage "$SCRIPT_CMD"
exit 1 exit 1
else else
break # out-of-args, stop looping break # out-of-args, stop looping
@ -636,7 +679,13 @@ if [ "$SOLR_MODE" == "solrcloud" ]; then
fi fi
CLOUD_MODE_OPTS="$CLOUD_MODE_OPTS -DzkRun" CLOUD_MODE_OPTS="$CLOUD_MODE_OPTS -DzkRun"
# and if collection1 needs to be bootstrapped
if [ -e "$SOLR_HOME/collection1/core.properties" ]; then
CLOUD_MODE_OPTS="$CLOUD_MODE_OPTS -Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf"
fi
fi fi
fi fi
# These are useful for attaching remove profilers like VisualVM/JConsole # These are useful for attaching remove profilers like VisualVM/JConsole
@ -723,6 +772,7 @@ $SOLR_HOST_ARG -Djetty.port=$SOLR_PORT \
# run Solr in the background # run Solr in the background
nohup $JAVA $SOLR_START_OPTS $SOLR_ADDL_ARGS -XX:OnOutOfMemoryError="$SOLR_TIP/bin/oom_solr.sh $SOLR_PORT" -jar start.jar 1>$SOLR_TIP/bin/solr-$SOLR_PORT-console.log 2>&1 & nohup $JAVA $SOLR_START_OPTS $SOLR_ADDL_ARGS -XX:OnOutOfMemoryError="$SOLR_TIP/bin/oom_solr.sh $SOLR_PORT" -jar start.jar 1>$SOLR_TIP/bin/solr-$SOLR_PORT-console.log 2>&1 &
# no lsof on cygwin though
echo -n "Waiting to see Solr listening on port $SOLR_PORT" echo -n "Waiting to see Solr listening on port $SOLR_PORT"
# Launch in a subshell to show the spinner # Launch in a subshell to show the spinner
(loops=0 (loops=0
@ -745,7 +795,6 @@ $SOLR_HOST_ARG -Djetty.port=$SOLR_PORT \
fi fi
done) & done) &
spinner $! spinner $!
fi fi
} }
@ -760,14 +809,9 @@ else
SOLR_PORT=${CLOUD_PORTS[0]} SOLR_PORT=${CLOUD_PORTS[0]}
echo -e "\nStarting up SolrCloud node1 on port ${CLOUD_PORTS[0]} using command:\n" echo -e "\nStarting up SolrCloud node1 on port ${CLOUD_PORTS[0]} using command:\n"
echo -e "solr start -cloud -d node1 -p $SOLR_PORT \n\n" echo -e "solr start -cloud -d node1 -p $SOLR_PORT \n\n"
if $isLegacyExampleDir ; then
# have to pass these when working with the legacy example directory
BOOTSTRAP_ARGS="-Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf"
fi
# can't launch this node in the foreground else we can't run anymore commands # can't launch this node in the foreground else we can't run anymore commands
launch_solr "false" "$BOOTSTRAP_ARGS" launch_solr "false" ""
zk_port=$[$SOLR_PORT+1000] zk_port=$[$SOLR_PORT+1000]
zk_host=localhost:$zk_port zk_host=localhost:$zk_port
@ -784,20 +828,20 @@ else
# TODO: better (shorter) name?? # TODO: better (shorter) name??
CLOUD_COLLECTION=gettingstarted CLOUD_COLLECTION=gettingstarted
# if the new default config directory is available, then use it,
# otherwise, use the schema-less example
if [ -d "$SOLR_TIP/server/solr/default_conf" ]; then
CLOUD_CONFIG_DIR=$SOLR_TIP/server/solr/default_conf
else
CLOUD_CONFIG_DIR=$SOLR_TIP/example/example-schemaless/solr/collection1/conf
fi
CLOUD_CONFIG=schemaless
if $noprompt ; then if $noprompt ; then
CLOUD_NUM_SHARDS=2 CLOUD_NUM_SHARDS=2
CLOUD_REPFACT=2 CLOUD_REPFACT=2
# if the new default config directory is available, then use it,
# otherwise, use the legacy collection1 example
# TODO: this will need to change when SOLR-3619 is resolved
if [ -d "$SOLR_TIP/server/solr/configsets/schemaless" ]; then
CLOUD_CONFIG_DIR=$SOLR_TIP/server/solr/configsets/schemaless
CLOUD_CONFIG=schemaless
else
CLOUD_CONFIG_DIR=$SOLR_TIP/example/solr/collection1/conf
CLOUD_CONFIG=default
fi
else else
echo -e "\nNow let's create a new collection for indexing documents in your $CLOUD_NUM_NODES-node cluster.\n" echo -e "\nNow let's create a new collection for indexing documents in your $CLOUD_NUM_NODES-node cluster.\n"
read -e -p "Please provide a name for your new collection: [gettingstarted] " USER_INPUT read -e -p "Please provide a name for your new collection: [gettingstarted] " USER_INPUT
@ -810,6 +854,7 @@ else
fi fi
echo $CLOUD_COLLECTION echo $CLOUD_COLLECTION
USER_INPUT=
read -e -p "How many shards would you like to split $CLOUD_COLLECTION into? [2] " USER_INPUT read -e -p "How many shards would you like to split $CLOUD_COLLECTION into? [2] " USER_INPUT
# trim whitespace out of the user input # trim whitespace out of the user input
CLOUD_NUM_SHARDS=`echo $USER_INPUT | tr -d ' '` CLOUD_NUM_SHARDS=`echo $USER_INPUT | tr -d ' '`
@ -820,6 +865,7 @@ else
fi fi
echo $CLOUD_NUM_SHARDS echo $CLOUD_NUM_SHARDS
USER_INPUT=
read -e -p "How many replicas per shard would you like to create? [2] " USER_INPUT read -e -p "How many replicas per shard would you like to create? [2] " USER_INPUT
# trim whitespace out of the user input # trim whitespace out of the user input
CLOUD_REPFACT=`echo $USER_INPUT | tr -d ' '` CLOUD_REPFACT=`echo $USER_INPUT | tr -d ' '`
@ -830,8 +876,28 @@ else
fi fi
echo $CLOUD_REPFACT echo $CLOUD_REPFACT
USER_INPUT=
read -e -p "Please choose a configuration for the $CLOUD_COLLECTION collection, available options are: default or schemaless [default] " USER_INPUT
# trim whitespace out of the user input
CLOUD_CONFIG=`echo $USER_INPUT | tr -d ' '`
# handle the default selection or empty input
if [ "$CLOUD_CONFIG" == "" ]; then
CLOUD_CONFIG=default
fi
echo $CLOUD_CONFIG
if [ "$CLOUD_CONFIG" == "schemaless" ]; then
if [ -d "$SOLR_TIP/server/solr/configsets/schemaless" ]; then
CLOUD_CONFIG_DIR=$SOLR_TIP/server/solr/configsets/schemaless
else
CLOUD_CONFIG_DIR=$SOLR_TIP/example/example-schemaless/solr/collection1/conf
fi
else
CLOUD_CONFIG_DIR=$SOLR_TIP/example/solr/collection1/conf
fi
fi fi
echo -e "\nDeploying default Solr configuration files to embedded ZooKeeper using command:\n" echo -e "\nDeploying default Solr configuration files to embedded ZooKeeper using command:\n"
echo -e "$DEFAULT_SERVER_DIR/scripts/cloud-scripts/zkcli.sh -zkhost $zk_host -cmd upconfig -confdir $CLOUD_CONFIG_DIR -confname $CLOUD_CONFIG\n" echo -e "$DEFAULT_SERVER_DIR/scripts/cloud-scripts/zkcli.sh -zkhost $zk_host -cmd upconfig -confdir $CLOUD_CONFIG_DIR -confname $CLOUD_CONFIG\n"
# upload the config directory to ZooKeeper # upload the config directory to ZooKeeper
@ -842,7 +908,7 @@ else
$JAVA -Dlog4j.configuration=file:$DEFAULT_SERVER_DIR/scripts/cloud-scripts/log4j.properties \ $JAVA -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/*" \ -classpath "$DEFAULT_SERVER_DIR/solr-webapp/webapp/WEB-INF/lib/*:$DEFAULT_SERVER_DIR/lib/ext/*" \
org.apache.solr.cloud.ZkCLI -zkhost $zk_host -cmd upconfig -confdir $CLOUD_CONFIG_DIR -confname $CLOUD_CONFIG > /dev/null 2>&1 org.apache.solr.cloud.ZkCLI -zkhost $zk_host -cmd upconfig -confdir $CLOUD_CONFIG_DIR -confname $CLOUD_CONFIG > /dev/null 2>&1
echo -e "Successfully deployed $CLOUD_CONFIG to ZooKeeper\n" echo -e "Successfully deployed the $CLOUD_CONFIG_DIR configuration directory to ZooKeeper as $CLOUD_CONFIG\n"
# note use of ceiling logic in case of remainder # note use of ceiling logic in case of remainder
MAX_SHARDS_PER_NODE=$((($CLOUD_NUM_SHARDS*$CLOUD_REPFACT+$CLOUD_NUM_NODES-1)/$CLOUD_NUM_NODES)) MAX_SHARDS_PER_NODE=$((($CLOUD_NUM_SHARDS*$CLOUD_REPFACT+$CLOUD_NUM_NODES-1)/$CLOUD_NUM_NODES))
@ -850,9 +916,8 @@ else
COLLECTIONS_API=http://localhost:$SOLR_PORT/solr/admin/collections COLLECTIONS_API=http://localhost:$SOLR_PORT/solr/admin/collections
CLOUD_CREATE_COLLECTION_CMD="$COLLECTIONS_API?action=CREATE&name=$CLOUD_COLLECTION&replicationFactor=$CLOUD_REPFACT&numShards=$CLOUD_NUM_SHARDS&collection.configName=$CLOUD_CONFIG&maxShardsPerNode=$MAX_SHARDS_PER_NODE&wt=json&indent=2" CLOUD_CREATE_COLLECTION_CMD="$COLLECTIONS_API?action=CREATE&name=$CLOUD_COLLECTION&replicationFactor=$CLOUD_REPFACT&numShards=$CLOUD_NUM_SHARDS&collection.configName=$CLOUD_CONFIG&maxShardsPerNode=$MAX_SHARDS_PER_NODE&wt=json&indent=2"
echo -e "\n\nCreating new collection $CLOUD_COLLECTION with $CLOUD_NUM_SHARDS shards and replication factor $CLOUD_REPFACT using Collections API command:\n\n$CLOUD_CREATE_COLLECTION_CMD\n\nFor more information about the Collections API, please see: https://cwiki.apache.org/confluence/display/solr/Collections+API\n" echo -e "\n\nCreating new collection $CLOUD_COLLECTION with $CLOUD_NUM_SHARDS shards and replication factor $CLOUD_REPFACT using Collections API command:\n\n$CLOUD_CREATE_COLLECTION_CMD\n\nFor more information about the Collections API, please see: https://cwiki.apache.org/confluence/display/solr/Collections+API\n"
curl "$CLOUD_CREATE_COLLECTION_CMD" curl "$CLOUD_CREATE_COLLECTION_CMD"
echo -e "\n\nSolrCloud example running, please visit http://localhost:$SOLR_PORT/solr \n\n" echo -e "\n\nSolrCloud example running, please visit http://localhost:$SOLR_PORT/solr \n\n"
fi fi

View File

@ -207,6 +207,14 @@ SHIFT
goto parse_args goto parse_args
:set_server_dir :set_server_dir
set "arg=%2"
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=%2 is not a valid directory!
goto invalid_cmd_line
)
REM See if they are using a short-hand name relative from the Solr tip directory REM See if they are using a short-hand name relative from the Solr tip directory
IF EXIST "%SOLR_TIP%\%2" ( IF EXIST "%SOLR_TIP%\%2" (
set "SOLR_SERVER_DIR=%SOLR_TIP%\%2" set "SOLR_SERVER_DIR=%SOLR_TIP%\%2"
@ -218,12 +226,28 @@ SHIFT
goto parse_args goto parse_args
:set_example :set_example
set "arg=%2"
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=%2 is not a valid example!
goto invalid_cmd_line
)
set EXAMPLE=%2 set EXAMPLE=%2
SHIFT SHIFT
SHIFT SHIFT
goto parse_args goto parse_args
:set_memory :set_memory
set "arg=%2"
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=%2 is not a valid memory setting!
goto invalid_cmd_line
)
set SOLR_HEAP=%2 set SOLR_HEAP=%2
@echo SOLR_HEAP=%SOLR_HEAP% @echo SOLR_HEAP=%SOLR_HEAP%
SHIFT SHIFT
@ -231,18 +255,40 @@ SHIFT
goto parse_args goto parse_args
:set_host :set_host
set "arg=%2"
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=%2 is not a valid hostname!
goto invalid_cmd_line
)
set SOLR_HOST=%2 set SOLR_HOST=%2
SHIFT SHIFT
SHIFT SHIFT
goto parse_args goto parse_args
:set_port :set_port
set "arg=%2"
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=%2 is not a valid port!
goto invalid_cmd_line
)
set SOLR_PORT=%2 set SOLR_PORT=%2
SHIFT SHIFT
SHIFT SHIFT
goto parse_args goto parse_args
:set_zookeeper :set_zookeeper
set "arg=%2"
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=%2 is not a valid ZooKeeper connection string!
goto invalid_cmd_line
)
set "ZK_HOST=%2" set "ZK_HOST=%2"
SHIFT SHIFT
SHIFT SHIFT
@ -272,7 +318,7 @@ REM TODO: Change this to "server" when we resolve SOLR-3619
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%" ( 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 goto err
) )
@ -348,16 +394,17 @@ 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_SERVER_DIR%/logs/solr_gc.log" IF NOT "%GC_LOG_OPTS%"=="" set GC_LOG_OPTS=%GC_LOG_OPTS% -Xloggc:"%SOLR_SERVER_DIR%/logs/solr_gc.log"
IF "%SOLR_MODE%"=="solrcloud" ( IF "%SOLR_MODE%"=="solrcloud" (
IF "%ZK_CLIENT_TIMEOUT%"=="" set ZK_CLIENT_TIMEOUT=15000 IF "%ZK_CLIENT_TIMEOUT%"=="" set "ZK_CLIENT_TIMEOUT=15000"
set CLOUD_MODE_OPTS=-DzkClientTimeout=%ZK_CLIENT_TIMEOUT% set "CLOUD_MODE_OPTS=-DzkClientTimeout=!ZK_CLIENT_TIMEOUT!"
IF NOT "%ZK_HOST%"=="" ( IF NOT "%ZK_HOST%"=="" (
set "CLOUD_MODE_OPTS=%CLOUD_MODE_OPTS% -DzkHost=%ZK_HOST%" set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -DzkHost=%ZK_HOST%"
) ELSE ( ) ELSE (
IF "%verbose%"=="1" echo 'Configuring SolrCloud to launch an embedded ZooKeeper using -DzkRun' IF "%verbose%"=="1" echo Configuring SolrCloud to launch an embedded ZooKeeper using -DzkRun
set "CLOUD_MODE_OPTS=%CLOUD_MODE_OPTS% -DzkRun" set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -DzkRun"
) IF EXIST "%SOLR_HOME%\collection1\core.properties" set "CLOUD_MODE_OPTS=!CLOUD_MODE_OPTS! -Dbootstrap_confdir=./solr/collection1/conf -Dcollection.configName=myconf"
)
) ELSE ( ) ELSE (
set CLOUD_MODE_OPTS= set CLOUD_MODE_OPTS=
) )
@ -397,12 +444,12 @@ IF "%verbose%"=="1" (
set START_OPTS=-Duser.timezone=%SOLR_TIMEZONE% -Djava.net.preferIPv4Stack=true -Dsolr.autoSoftCommit.maxTime=3000 set START_OPTS=-Duser.timezone=%SOLR_TIMEZONE% -Djava.net.preferIPv4Stack=true -Dsolr.autoSoftCommit.maxTime=3000
set START_OPTS=%START_OPTS% %GC_TUNE% %GC_LOG_OPTS% set START_OPTS=%START_OPTS% %GC_TUNE% %GC_LOG_OPTS%
IF NOT "%CLOUD_MODE_OPTS%"=="" set START_OPTS=%START_OPTS% %CLOUD_MODE_OPTS% IF NOT "!CLOUD_MODE_OPTS!"=="" set START_OPTS=%START_OPTS% !CLOUD_MODE_OPTS!
IF NOT "%REMOTE_JMX_OPTS%"=="" set START_OPTS=%START_OPTS% %REMOTE_JMX_OPTS% 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_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_HOST_ARG%"=="" set START_OPTS=%START_OPTS% %SOLR_HOST_ARG%
cd %SOLR_SERVER_DIR% cd "%SOLR_SERVER_DIR%"
@echo. @echo.
@echo Starting Solr on port %SOLR_PORT% from %SOLR_SERVER_DIR% @echo Starting Solr on port %SOLR_PORT% from %SOLR_SERVER_DIR%
@echo. @echo.
@ -411,7 +458,7 @@ IF "%FG%"=="1" (
"%JAVA%" -server -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -DSTOP.PORT=%STOP_PORT% -DSTOP.KEY=%STOP_KEY% ^ "%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%" -jar start.jar -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -jar start.jar
) ELSE ( ) ELSE (
START %JAVA% -server -Xss256k %SOLR_JAVA_MEM% %START_OPTS% -DSTOP.PORT=%STOP_PORT% -DSTOP.KEY=%STOP_KEY% ^ START "" "%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%" -jar start.jar > "%SOLR_TIP%\bin\solr-%SOLR_PORT%-console.log" -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -jar start.jar > "%SOLR_TIP%\bin\solr-%SOLR_PORT%-console.log"
) )
@ -482,12 +529,12 @@ for /l %%x in (1, 1, !CLOUD_NUM_NODES!) do (
IF %%x EQU 1 ( IF %%x EQU 1 (
set EXAMPLE= set EXAMPLE=
START %SDIR%\solr -f -c -p !NODE_PORT! -d node1 START "" "%SDIR%\solr" -f -c -p !NODE_PORT! -d node1
set NODE1_PORT=!NODE_PORT! set NODE1_PORT=!NODE_PORT!
) ELSE ( ) ELSE (
set /A ZK_PORT=!NODE1_PORT!+1000 set /A ZK_PORT=!NODE1_PORT!+1000
set "ZK_HOST=localhost:!ZK_PORT!" set "ZK_HOST=localhost:!ZK_PORT!"
START %SDIR%\solr -f -c -p !NODE_PORT! -d node%%x -z !ZK_HOST! START "" "%SDIR%\solr" -f -c -p !NODE_PORT! -d node%%x -z !ZK_HOST!
) )
timeout /T 10 timeout /T 10
@ -500,6 +547,8 @@ IF "%NO_USER_PROMPT%"=="1" (
set CLOUD_COLLECTION=gettingstarted set CLOUD_COLLECTION=gettingstarted
set CLOUD_NUM_SHARDS=2 set CLOUD_NUM_SHARDS=2
set CLOUD_REPFACT=2 set CLOUD_REPFACT=2
set CLOUD_CONFIG=default
set "CLOUD_CONFIG_DIR=%SOLR_TIP%\example\solr\collection1\conf"
goto create_collection goto create_collection
) ELSE ( ) ELSE (
goto get_create_collection_params goto get_create_collection_params
@ -522,25 +571,35 @@ set /P "USER_INPUT=How many replicas per shard would you like to create? [2] "
IF "!USER_INPUT!"=="" set USER_INPUT=2 IF "!USER_INPUT!"=="" set USER_INPUT=2
set CLOUD_REPFACT=!USER_INPUT! set CLOUD_REPFACT=!USER_INPUT!
echo !CLOUD_REPFACT! echo !CLOUD_REPFACT!
set USER_INPUT=
echo.
set /P "USER_INPUT=Please choose a configuration for the !CLOUD_COLLECTION! collection, available options are: default or schemaless [default] "
IF "!USER_INPUT!"=="" set USER_INPUT=default
set CLOUD_CONFIG=!USER_INPUT!
echo !CLOUD_CONFIG!
IF "!CLOUD_CONFIG!"=="schemaless" (
IF EXIST "%SOLR_TIP%\server\solr\configsets\schemaless" set "CLOUD_CONFIG_DIR=%SOLR_TIP%\server\solr\configsets\schemaless"
IF NOT EXIST "%SOLR_TIP%\server\solr\configsets\schemaless" set "CLOUD_CONFIG_DIR=%SOLR_TIP%\example\example-schemaless\solr\collection1\conf"
) ELSE (
set "CLOUD_CONFIG_DIR=%SOLR_TIP%\example\solr\collection1\conf"
)
goto create_collection goto create_collection
:create_collection :create_collection
set /A MAX_SHARDS_PER_NODE=((!CLOUD_NUM_SHARDS!*!CLOUD_REPFACT!)/!CLOUD_NUM_NODES!)+1 set /A MAX_SHARDS_PER_NODE=((!CLOUD_NUM_SHARDS!*!CLOUD_REPFACT!)/!CLOUD_NUM_NODES!)+1
IF EXIST "%SOLR_TIP%\server\solr\default_conf" set "CLOUD_CONFIG_DIR=%SOLR_TIP%\server\solr\default_conf"
IF NOT EXIST "%SOLR_TIP%\server\solr\default_conf" set "CLOUD_CONFIG_DIR=%SOLR_TIP%\example\example-schemaless\solr\collection1\conf"
set CLOUD_CONFIG=schemaless
echo. echo.
echo Deploying default Solr configuration files to embedded ZooKeeper echo Deploying default Solr configuration files to embedded ZooKeeper
echo. echo.
"%JAVA%" -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-scripts\log4j.properties" ^ "%JAVA%" -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\*" ^ -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
org.apache.solr.cloud.ZkCLI -zkhost %zk_host% -cmd upconfig -confdir "%CLOUD_CONFIG_DIR%" -confname %CLOUD_CONFIG% org.apache.solr.cloud.ZkCLI -zkhost %zk_host% -cmd upconfig -confdir "!CLOUD_CONFIG_DIR!" -confname !CLOUD_CONFIG!
set COLLECTIONS_API=http://localhost:!NODE1_PORT!/solr/admin/collections set COLLECTIONS_API=http://localhost:!NODE1_PORT!/solr/admin/collections
set "CLOUD_CREATE_COLLECTION_CMD=%COLLECTIONS_API%?action=CREATE&name=%CLOUD_COLLECTION%&replicationFactor=%CLOUD_REPFACT%&numShards=%CLOUD_NUM_SHARDS%&collection.configName=%CLOUD_CONFIG%&maxShardsPerNode=%MAX_SHARDS_PER_NODE%&wt=json&indent=2" set "CLOUD_CREATE_COLLECTION_CMD=%COLLECTIONS_API%?action=CREATE&name=%CLOUD_COLLECTION%&replicationFactor=%CLOUD_REPFACT%&numShards=%CLOUD_NUM_SHARDS%&collection.configName=!CLOUD_CONFIG!&maxShardsPerNode=%MAX_SHARDS_PER_NODE%&wt=json&indent=2"
echo Creating new collection %CLOUD_COLLECTION% with %CLOUD_NUM_SHARDS% shards and replication factor %CLOUD_REPFACT% using Collections API command: echo Creating new collection %CLOUD_COLLECTION% with %CLOUD_NUM_SHARDS% shards and replication factor %CLOUD_REPFACT% using Collections API command:
echo. echo.
@echo "%CLOUD_CREATE_COLLECTION_CMD%" @echo "%CLOUD_CREATE_COLLECTION_CMD%"
@ -618,7 +677,11 @@ goto done
:invalid_cmd_line :invalid_cmd_line
@echo. @echo.
@echo Invalid command-line option: %1 IF "!SCRIPT_ERROR!"=="" (
@echo Invalid command-line option: %1
) ELSE (
@echo ERROR: !SCRIPT_ERROR!
)
@echo. @echo.
IF "%FIRST_ARG%"=="start" ( IF "%FIRST_ARG%"=="start" (
goto start_usage goto start_usage
@ -644,7 +707,7 @@ goto done
:err :err
@echo. @echo.
@echo %SCRIPT_ERROR% @echo ERROR: !SCRIPT_ERROR!
@echo. @echo.
exit /b 1 exit /b 1

View File

@ -43,8 +43,11 @@ GC_TUNE="-XX:-UseSuperWord \
-XX:+ParallelRefProcEnabled \ -XX:+ParallelRefProcEnabled \
-XX:+AggressiveOpts" -XX:+AggressiveOpts"
# Mac OSX and Cygwin don't seem to like the UseLargePages flag
thisOs=`uname -s` thisOs=`uname -s`
if [ "$thisOs" != "Darwin" ]; then # for now, we don't support running this script from cygwin due to problems
# like not having lsof, ps waux, curl, and awkward directory handling
if [[ "$thisOs" != "Darwin" && "${thisOs:0:6}" != "CYGWIN" ]]; then
# UseLargePages flag causes JVM crash on Mac OSX # UseLargePages flag causes JVM crash on Mac OSX
GC_TUNE="$GC_TUNE -XX:+UseLargePages" GC_TUNE="$GC_TUNE -XX:+UseLargePages"
fi fi