"Fossies" - the Fresh Open Source Software Archive

Member "solr-8.4.1/solr/bin/solr" (10 Jan 2020, 83300 Bytes) of package /linux/www/solr-8.4.1-src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "solr": 8.4.0_vs_8.4.1.

    1 #!/usr/bin/env bash
    2 # Licensed to the Apache Software Foundation (ASF) under one or more
    3 # contributor license agreements.  See the NOTICE file distributed with
    4 # this work for additional information regarding copyright ownership.
    5 # The ASF licenses this file to You under the Apache License, Version 2.0
    6 # (the "License"); you may not use this file except in compliance with
    7 # the License.  You may obtain a copy of the License at
    8 #
    9 #     http://www.apache.org/licenses/LICENSE-2.0
   10 #
   11 # Unless required by applicable law or agreed to in writing, software
   12 # distributed under the License is distributed on an "AS IS" BASIS,
   13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14 # See the License for the specific language governing permissions and
   15 # limitations under the License.
   16 
   17 
   18 # CONTROLLING STARTUP:
   19 #
   20 # Use solr -help to see available command-line options. In addition
   21 # to passing command-line options, this script looks for an include
   22 # file named solr.in.sh to set environment variables. Specifically,
   23 # the following locations are searched in this order:
   24 #
   25 # ./
   26 # $HOME/.solr.in.sh
   27 # /usr/share/solr
   28 # /usr/local/share/solr
   29 # /var/solr/
   30 # /opt/solr
   31 #
   32 # Another option is to specify the full path to the include file in the
   33 # environment. For example:
   34 #
   35 #   $ SOLR_INCLUDE=/path/to/solr.in.sh solr start
   36 #
   37 # Note: This is particularly handy for running multiple instances on a
   38 # single installation, or for quick tests.
   39 #
   40 # Finally, developers and enthusiasts who frequently run from an SVN
   41 # checkout, and do not want to locally modify bin/solr.in.sh, can put
   42 # a customized include file at ~/.solr.in.sh.
   43 #
   44 # If you would rather configure startup entirely from the environment, you
   45 # can disable the include by exporting an empty SOLR_INCLUDE, or by
   46 # ensuring that no include files exist in the aforementioned search list.
   47 
   48 SOLR_SCRIPT="$0"
   49 verbose=false
   50 THIS_OS=`uname -s`
   51 
   52 # What version of Java is required to run this version of Solr.
   53 JAVA_VER_REQ="8"
   54 
   55 stop_all=false
   56 
   57 # for now, we don't support running this script from cygwin due to problems
   58 # like not having lsof, ps auxww, curl, and awkward directory handling
   59 if [ "${THIS_OS:0:6}" == "CYGWIN" ]; then
   60   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!"
   61   exit 1
   62 fi
   63 
   64 # Resolve symlinks to this script
   65 while [ -h "$SOLR_SCRIPT" ] ; do
   66   ls=`ls -ld "$SOLR_SCRIPT"`
   67   # Drop everything prior to ->
   68   link=`expr "$ls" : '.*-> \(.*\)$'`
   69   if expr "$link" : '/.*' > /dev/null; then
   70     SOLR_SCRIPT="$link"
   71   else
   72     SOLR_SCRIPT=`dirname "$SOLR_SCRIPT"`/"$link"
   73   fi
   74 done
   75 
   76 SOLR_TIP=`dirname "$SOLR_SCRIPT"`/..
   77 SOLR_TIP=`cd "$SOLR_TIP"; pwd`
   78 DEFAULT_SERVER_DIR="$SOLR_TIP/server"
   79 
   80 # If an include wasn't specified in the environment, then search for one...
   81 if [ -z "$SOLR_INCLUDE" ]; then
   82   # Locations (in order) to use when searching for an include file.
   83   for include in "`dirname "$0"`/solr.in.sh" \
   84                "$HOME/.solr.in.sh" \
   85                /usr/share/solr/solr.in.sh \
   86                /usr/local/share/solr/solr.in.sh \
   87                /etc/default/solr.in.sh \
   88                /opt/solr/solr.in.sh; do
   89     if [ -r "$include" ]; then
   90         SOLR_INCLUDE="$include"
   91         . "$include"
   92         break
   93     fi
   94   done
   95 elif [ -r "$SOLR_INCLUDE" ]; then
   96   . "$SOLR_INCLUDE"
   97 fi
   98 
   99 if [ -z "$SOLR_PID_DIR" ]; then
  100   SOLR_PID_DIR="$SOLR_TIP/bin"
  101 fi
  102 
  103 if [ -n "$SOLR_JAVA_HOME" ]; then
  104   JAVA="$SOLR_JAVA_HOME/bin/java"
  105 elif [ -n "$JAVA_HOME" ]; then
  106   for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
  107     if [ -x "$java" ]; then
  108       JAVA="$java"
  109       break
  110     fi
  111   done
  112   if [ -z "$JAVA" ]; then
  113     echo >&2 "The currently defined JAVA_HOME ($JAVA_HOME) refers"
  114     echo >&2 "to a location where Java could not be found.  Aborting."
  115     echo >&2 "Either fix the JAVA_HOME variable or remove it from the"
  116     echo >&2 "environment so that the system PATH will be searched."
  117     exit 1
  118   fi
  119 else
  120   JAVA=java
  121 fi
  122 
  123 if [ -z "$SOLR_STOP_WAIT" ]; then
  124   SOLR_STOP_WAIT=180
  125 fi
  126 # test that Java exists, is executable and correct version
  127 JAVA_VER=$("$JAVA" -version 2>&1)
  128 if [[ $? -ne 0 ]] ; then
  129   echo >&2 "Java not found, or an error was encountered when running java."
  130   echo >&2 "A working Java $JAVA_VER_REQ JRE is required to run Solr!"
  131   echo >&2 "Please install latest version of Java $JAVA_VER_REQ or set JAVA_HOME properly."
  132   echo >&2 "Command that we tried: '${JAVA} -version', with response:"
  133   echo >&2 "${JAVA_VER}"
  134   echo >&2
  135   echo >&2 "Debug information:"
  136   echo >&2 "JAVA_HOME: ${JAVA_HOME:-N/A}"
  137   echo >&2 "Active Path:"
  138   echo >&2 "${PATH}"
  139   exit 1
  140 else
  141   JAVA_VER_NUM=$(echo $JAVA_VER | head -1 | awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//')
  142   if [[ "$JAVA_VER_NUM" -lt "$JAVA_VER_REQ" ]] ; then
  143     echo >&2 "Your current version of Java is too old to run this version of Solr."
  144     echo >&2 "We found major version $JAVA_VER_NUM, using command '${JAVA} -version', with response:"
  145     echo >&2 "${JAVA_VER}"
  146     echo >&2
  147     echo >&2 "Please install latest version of Java $JAVA_VER_REQ or set JAVA_HOME properly."
  148     echo >&2
  149     echo >&2 "Debug information:"
  150     echo >&2 "JAVA_HOME: ${JAVA_HOME:-N/A}"
  151     echo >&2 "Active Path:"
  152     echo >&2 "${PATH}"
  153     exit 1
  154   fi
  155   JAVA_VENDOR="Oracle"
  156   if [ "`echo $JAVA_VER | grep -i "IBM J9"`" != "" ]; then
  157       JAVA_VENDOR="IBM J9"
  158   fi
  159 fi
  160 
  161 
  162 # Select HTTP OR HTTPS related configurations
  163 SOLR_URL_SCHEME=http
  164 SOLR_JETTY_CONFIG=()
  165 SOLR_SSL_OPTS=""
  166 
  167 if [ -n "$SOLR_HADOOP_CREDENTIAL_PROVIDER_PATH" ]; then
  168   SOLR_SSL_OPTS+=" -Dhadoop.security.credential.provider.path=$SOLR_HADOOP_CREDENTIAL_PROVIDER_PATH"
  169 fi
  170 
  171 if [ -z "$SOLR_SSL_ENABLED" ]; then
  172   if [ -n "$SOLR_SSL_KEY_STORE" ]; then
  173     SOLR_SSL_ENABLED="true" # implicitly from earlier behaviour
  174   else
  175     SOLR_SSL_ENABLED="false"
  176   fi
  177 fi
  178 if [ "$SOLR_SSL_ENABLED" == "true" ]; then
  179   if [[ "$JAVA_VER_NUM" -lt "9" ]] ; then
  180     echo >&2 "HTTP/2 + SSL is not support in Java 8. "
  181     echo >&2 "Configure Solr with HTTP/1.1 + SSL"
  182     SOLR_JETTY_CONFIG+=("--module=https8")
  183   else
  184     SOLR_JETTY_CONFIG+=("--module=https")
  185   fi
  186 
  187   SOLR_JETTY_CONFIG+=("--lib=$DEFAULT_SERVER_DIR/solr-webapp/webapp/WEB-INF/lib/*")
  188   SOLR_URL_SCHEME=https
  189   if [ -n "$SOLR_SSL_KEY_STORE" ]; then
  190     SOLR_SSL_OPTS+=" -Dsolr.jetty.keystore=$SOLR_SSL_KEY_STORE"
  191   fi
  192   if [ -n "$SOLR_SSL_KEY_STORE_PASSWORD" ]; then
  193     export SOLR_SSL_KEY_STORE_PASSWORD=$SOLR_SSL_KEY_STORE_PASSWORD
  194   fi
  195   if [ -n "$SOLR_SSL_KEY_STORE_TYPE" ]; then
  196     SOLR_SSL_OPTS+=" -Dsolr.jetty.keystore.type=$SOLR_SSL_KEY_STORE_TYPE"
  197   fi
  198 
  199   if [ -n "$SOLR_SSL_TRUST_STORE" ]; then
  200     SOLR_SSL_OPTS+=" -Dsolr.jetty.truststore=$SOLR_SSL_TRUST_STORE"
  201   fi
  202   if [ -n "$SOLR_SSL_TRUST_STORE_PASSWORD" ]; then
  203     export SOLR_SSL_TRUST_STORE_PASSWORD=$SOLR_SSL_TRUST_STORE_PASSWORD
  204   fi
  205   if [ -n "$SOLR_SSL_TRUST_STORE_TYPE" ]; then
  206     SOLR_SSL_OPTS+=" -Dsolr.jetty.truststore.type=$SOLR_SSL_TRUST_STORE_TYPE"
  207   fi
  208 
  209   if [ -z "$SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION" ] ; then
  210     SOLR_SSL_OPTS+=" -Dsolr.jetty.ssl.verifyClientHostName=HTTPS"
  211   fi
  212 
  213   if [ -n "$SOLR_SSL_NEED_CLIENT_AUTH" ]; then
  214     SOLR_SSL_OPTS+=" -Dsolr.jetty.ssl.needClientAuth=$SOLR_SSL_NEED_CLIENT_AUTH"
  215   fi
  216   if [ -n "$SOLR_SSL_WANT_CLIENT_AUTH" ]; then
  217     SOLR_SSL_OPTS+=" -Dsolr.jetty.ssl.wantClientAuth=$SOLR_SSL_WANT_CLIENT_AUTH"
  218   fi
  219 
  220   if [ -n "$SOLR_SSL_CLIENT_KEY_STORE" ]; then
  221     SOLR_SSL_OPTS+=" -Djavax.net.ssl.keyStore=$SOLR_SSL_CLIENT_KEY_STORE"
  222 
  223     if [ -n "$SOLR_SSL_CLIENT_KEY_STORE_PASSWORD" ]; then
  224       export SOLR_SSL_CLIENT_KEY_STORE_PASSWORD=$SOLR_SSL_CLIENT_KEY_STORE_PASSWORD
  225     fi
  226     if [ -n "$SOLR_SSL_CLIENT_KEY_STORE_TYPE" ]; then
  227       SOLR_SSL_OPTS+=" -Djavax.net.ssl.keyStoreType=$SOLR_SSL_CLIENT_KEY_STORE_TYPE"
  228     fi
  229   else
  230     if [ -n "$SOLR_SSL_KEY_STORE" ]; then
  231       SOLR_SSL_OPTS+=" -Djavax.net.ssl.keyStore=$SOLR_SSL_KEY_STORE"
  232     fi
  233     if [ -n "$SOLR_SSL_KEY_STORE_TYPE" ]; then
  234       SOLR_SSL_OPTS+=" -Djavax.net.ssl.keyStoreType=$SOLR_SSL_KEY_STORE_TYPE"
  235     fi
  236   fi
  237 
  238   if [ -n "$SOLR_SSL_CHECK_PEER_NAME" ]; then
  239     SOLR_SSL_OPTS+=" -Dsolr.ssl.checkPeerName=$SOLR_SSL_CHECK_PEER_NAME"
  240   fi
  241 
  242   if [ -n "$SOLR_SSL_CLIENT_TRUST_STORE" ]; then
  243     SOLR_SSL_OPTS+=" -Djavax.net.ssl.trustStore=$SOLR_SSL_CLIENT_TRUST_STORE"
  244 
  245     if [ -n "$SOLR_SSL_CLIENT_TRUST_STORE_PASSWORD" ]; then
  246       export SOLR_SSL_CLIENT_TRUST_STORE_PASSWORD=$SOLR_SSL_CLIENT_TRUST_STORE_PASSWORD
  247     fi
  248     if [ -n "$SOLR_SSL_CLIENT_TRUST_STORE_TYPE" ]; then
  249       SOLR_SSL_OPTS+=" -Djavax.net.ssl.trustStoreType=$SOLR_SSL_CLIENT_TRUST_STORE_TYPE"
  250     fi
  251   else
  252     if [ -n "$SOLR_SSL_TRUST_STORE" ]; then
  253       SOLR_SSL_OPTS+=" -Djavax.net.ssl.trustStore=$SOLR_SSL_TRUST_STORE"
  254     fi
  255 
  256     if [ -n "$SOLR_SSL_TRUST_STORE_TYPE" ]; then
  257       SOLR_SSL_OPTS+=" -Djavax.net.ssl.trustStoreType=$SOLR_SSL_TRUST_STORE_TYPE"
  258     fi
  259   fi
  260 else
  261   SOLR_JETTY_CONFIG+=("--module=http")
  262 fi
  263 
  264 # Authentication options
  265 if [ -z "$SOLR_AUTH_TYPE" ] && [ -n "$SOLR_AUTHENTICATION_OPTS" ]; then
  266   echo "WARNING: SOLR_AUTHENTICATION_OPTS environment variable configured without associated SOLR_AUTH_TYPE variable"
  267   echo "         Please configure SOLR_AUTH_TYPE environment variable with the authentication type to be used."
  268   echo "         Currently supported authentication types are [kerberos, basic]"
  269 fi
  270 
  271 if [ -n "$SOLR_AUTH_TYPE" ] && [ -n "$SOLR_AUTHENTICATION_CLIENT_BUILDER" ]; then
  272   echo "WARNING: SOLR_AUTHENTICATION_CLIENT_BUILDER and SOLR_AUTH_TYPE environment variables are configured together."
  273   echo "         Use SOLR_AUTH_TYPE environment variable to configure authentication type to be used. "
  274   echo "         Currently supported authentication types are [kerberos, basic]"
  275   echo "         The value of SOLR_AUTHENTICATION_CLIENT_BUILDER environment variable will be ignored"
  276 fi
  277 
  278 if [ -n "$SOLR_AUTH_TYPE" ]; then
  279   case "$(echo $SOLR_AUTH_TYPE | awk '{print tolower($0)}')" in
  280     basic)
  281       SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory"
  282       ;;
  283     kerberos)
  284       SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder"
  285       ;;
  286     *)
  287       echo "ERROR: Value specified for SOLR_AUTH_TYPE environment variable is invalid."
  288       exit 1
  289    esac
  290 fi
  291 
  292 if [ "$SOLR_AUTHENTICATION_CLIENT_CONFIGURER" != "" ]; then
  293   echo "WARNING: Found unsupported configuration variable SOLR_AUTHENTICATION_CLIENT_CONFIGURER"
  294   echo "         Please start using SOLR_AUTH_TYPE instead"
  295 fi
  296 if [ "$SOLR_AUTHENTICATION_CLIENT_BUILDER" != "" ]; then
  297   AUTHC_CLIENT_BUILDER_ARG="-Dsolr.httpclient.builder.factory=$SOLR_AUTHENTICATION_CLIENT_BUILDER"
  298 fi
  299 AUTHC_OPTS="$AUTHC_CLIENT_BUILDER_ARG $SOLR_AUTHENTICATION_OPTS"
  300 
  301 # Set the SOLR_TOOL_HOST variable for use when connecting to a running Solr instance
  302 if [ "$SOLR_HOST" != "" ]; then
  303   SOLR_TOOL_HOST="$SOLR_HOST"
  304 else
  305   SOLR_TOOL_HOST="localhost"
  306 fi
  307 
  308 function print_usage() {
  309   CMD="$1"
  310   ERROR_MSG="$2"
  311 
  312   if [ "$ERROR_MSG" != "" ]; then
  313     echo -e "\nERROR: $ERROR_MSG\n"
  314   fi
  315 
  316   if [ -z "$CMD" ]; then
  317     echo ""
  318     echo "Usage: solr COMMAND OPTIONS"
  319     echo "       where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config, autoscaling, export"
  320     echo ""
  321     echo "  Standalone server example (start Solr running in the background on port 8984):"
  322     echo ""
  323     echo "    ./solr start -p 8984"
  324     echo ""
  325     echo "  SolrCloud example (start Solr running in SolrCloud mode using localhost:2181 to connect to Zookeeper, with 1g max heap size and remote Java debug options enabled):"
  326     echo ""
  327     echo "    ./solr start -c -m 1g -z localhost:2181 -a \"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044\""
  328     echo ""
  329     echo "  Omit '-z localhost:2181' from the above command if you have defined ZK_HOST in solr.in.sh."
  330     echo ""
  331     echo "Pass -help after any COMMAND to see command-specific usage information,"
  332     echo "  such as:    ./solr start -help or ./solr stop -help"
  333     echo ""
  334   elif [[ "$CMD" == "start" || "$CMD" == "restart" ]]; then
  335     echo ""
  336     echo "Usage: solr $CMD [-f] [-c] [-h hostname] [-p port] [-d directory] [-z zkHost] [-m memory] [-e example] [-s solr.solr.home] [-t solr.data.home] [-a \"additional-options\"] [-V]"
  337     echo ""
  338     echo "  -f            Start Solr in foreground; default starts Solr in the background"
  339     echo "                  and sends stdout / stderr to solr-PORT-console.log"
  340     echo ""
  341     echo "  -c or -cloud  Start Solr in SolrCloud mode; if -z not supplied and ZK_HOST not defined in"
  342     echo "                  solr.in.sh, an embedded ZooKeeper instance is started on Solr port+1000,"
  343     echo "                  such as 9983 if Solr is bound to 8983"
  344     echo ""
  345     echo "  -h <host>     Specify the hostname for this Solr instance"
  346     echo ""
  347     echo "  -p <port>     Specify the port to start the Solr HTTP listener on; default is 8983"
  348     echo "                  The specified port (SOLR_PORT) will also be used to determine the stop port"
  349     echo "                  STOP_PORT=(\$SOLR_PORT-1000) and JMX RMI listen port RMI_PORT=(\$SOLR_PORT+10000). "
  350     echo "                  For instance, if you set -p 8985, then the STOP_PORT=7985 and RMI_PORT=18985"
  351     echo ""
  352     echo "  -d <dir>      Specify the Solr server directory; defaults to server"
  353     echo ""
  354     echo "  -z <zkHost>   Zookeeper connection string; only used when running in SolrCloud mode using -c"
  355     echo "                   If neither ZK_HOST is defined in solr.in.sh nor the -z parameter is specified,"
  356     echo "                   an embedded ZooKeeper instance will be launched."
  357     echo ""
  358     echo "  -m <memory>   Sets the min (-Xms) and max (-Xmx) heap size for the JVM, such as: -m 4g"
  359     echo "                  results in: -Xms4g -Xmx4g; by default, this script sets the heap size to 512m"
  360     echo ""
  361     echo "  -s <dir>      Sets the solr.solr.home system property; Solr will create core directories under"
  362     echo "                  this directory. This allows you to run multiple Solr instances on the same host"
  363     echo "                  while reusing the same server directory set using the -d parameter. If set, the"
  364     echo "                  specified directory should contain a solr.xml file, unless solr.xml exists in Zookeeper."
  365     echo "                  This parameter is ignored when running examples (-e), as the solr.solr.home depends"
  366     echo "                  on which example is run. The default value is server/solr. If passed relative dir,"
  367     echo "                  validation with current dir will be done, before trying default server/<dir>"
  368     echo ""
  369     echo "  -t <dir>      Sets the solr.data.home system property, where Solr will store index data in <instance_dir>/data subdirectories."
  370     echo "                  If not set, Solr uses solr.solr.home for config and data."
  371     echo ""
  372     echo "  -e <example>  Name of the example to run; available examples:"
  373     echo "      cloud:         SolrCloud example"
  374     echo "      techproducts:  Comprehensive example illustrating many of Solr's core capabilities"
  375     echo "      dih:           Data Import Handler"
  376     echo "      schemaless:    Schema-less example"
  377     echo ""
  378     echo "  -a            Additional parameters to pass to the JVM when starting Solr, such as to setup"
  379     echo "                  Java debug options. For example, to enable a Java debugger to attach to the Solr JVM"
  380     echo "                  you could pass: -a \"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=18983\""
  381     echo "                  In most cases, you should wrap the additional parameters in double quotes."
  382     echo ""
  383     echo "  -j            Additional parameters to pass to Jetty when starting Solr."
  384     echo "                  For example, to add configuration folder that jetty should read"
  385     echo "                  you could pass: -j \"--include-jetty-dir=/etc/jetty/custom/server/\""
  386     echo "                  In most cases, you should wrap the additional parameters in double quotes."
  387     echo ""
  388     echo "  -noprompt     Don't prompt for input; accept all defaults when running examples that accept user input"
  389     echo ""
  390     echo "  -v and -q     Verbose (-v) or quiet (-q) logging. Sets default log level to DEBUG or WARN instead of INFO"
  391     echo ""
  392     echo "  -V/-verbose   Verbose messages from this script"
  393     echo ""
  394   elif [ "$CMD" == "stop" ]; then
  395     echo ""
  396     echo "Usage: solr stop [-k key] [-p port] [-V]"
  397     echo ""
  398     echo "  -k <key>      Stop key; default is solrrocks"
  399     echo ""
  400     echo "  -p <port>     Specify the port the Solr HTTP listener is bound to"
  401     echo ""
  402     echo "  -all          Find and stop all running Solr servers on this host"
  403     echo ""
  404     echo "  -V/-verbose   Verbose messages from this script"
  405     echo ""
  406     echo "  NOTE: To see if any Solr servers are running, do: solr status"
  407     echo ""
  408   elif [ "$CMD" == "healthcheck" ]; then
  409     echo ""
  410     echo "Usage: solr healthcheck [-c collection] [-z zkHost] [-V]"
  411     echo ""
  412     echo "Can be run from remote (non-Solr) hosts, as long as a proper ZooKeeper connection is provided"
  413     echo ""
  414     echo "  -c <collection>  Collection to run healthcheck against."
  415     echo ""
  416     echo "  -z <zkHost>      Zookeeper connection string; unnecessary if ZK_HOST is defined in solr.in.sh;" 
  417     echo "                     otherwise, default is localhost:9983"
  418     echo ""
  419     echo "  -V               Enable more verbose output"
  420     echo ""
  421   elif [ "$CMD" == "status" ]; then
  422     echo ""
  423     echo "Usage: solr status"
  424     echo ""
  425     echo "  This command will show the status of all running Solr servers."
  426     echo "  It can only detect those Solr servers running on the current host."
  427     echo ""
  428   elif [ "$CMD" == "create" ]; then
  429     echo ""
  430     echo "Usage: solr create [-c name] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port] [-V]"
  431     echo ""
  432     echo "  Create a core or collection depending on whether Solr is running in standalone (core) or SolrCloud"
  433     echo "  mode (collection). In other words, this action detects which mode Solr is running in, and then takes"
  434     echo "  the appropriate action (either create_core or create_collection). For detailed usage instructions, do:"
  435     echo ""
  436     echo "    bin/solr create_core -help"
  437     echo ""
  438     echo "       or"
  439     echo ""
  440     echo "    bin/solr create_collection -help"
  441     echo ""
  442   elif [ "$CMD" == "delete" ]; then
  443     echo ""
  444     echo "Usage: solr delete [-c name] [-deleteConfig true|false] [-p port] [-V]"
  445     echo ""
  446     echo "  Deletes a core or collection depending on whether Solr is running in standalone (core) or SolrCloud"
  447     echo "  mode (collection). If you're deleting a collection in SolrCloud mode, the default behavior is to also"
  448     echo "  delete the configuration directory from Zookeeper so long as it is not being used by another collection."
  449     echo "  You can override this behavior by passing -deleteConfig false when running this command."
  450     echo ""
  451     echo "  Can be run on remote (non-Solr) hosts, as long as a valid SOLR_HOST is provided in solr.in.sh"
  452     echo ""
  453     echo "  -c <name>               Name of the core / collection to delete"
  454     echo ""
  455     echo "  -deleteConfig <boolean> Delete the configuration directory from Zookeeper; default is true"
  456     echo ""
  457     echo "  -p <port>               Port of a local Solr instance where you want to delete the core/collection"
  458     echo "                            If not specified, the script will search the local system for a running"
  459     echo "                            Solr instance and will use the port of the first server it finds."
  460     echo ""
  461     echo "  -V                      Enables more verbose output."
  462     echo ""
  463   elif [ "$CMD" == "create_core" ]; then
  464     echo ""
  465     echo "Usage: solr create_core [-c core] [-d confdir] [-p port] [-V]"
  466     echo ""
  467     echo "When a configSet is used, this can be run from remote (non-Solr) hosts.  If pointing at a non-configSet directory, this"
  468     echo "must be run from the host that you wish to create the core on"
  469     echo ""
  470     echo "  -c <core>     Name of core to create"
  471     echo ""
  472     echo "  -d <confdir>  Configuration directory to copy when creating the new core, built-in options are:"
  473     echo ""
  474     echo "      _default: Minimal configuration, which supports enabling/disabling field-guessing support"
  475     echo "      sample_techproducts_configs: Example configuration with many optional features enabled to"
  476     echo "         demonstrate the full power of Solr"
  477     echo ""
  478     echo "      If not specified, default is: _default"
  479     echo ""
  480     echo "      Alternatively, you can pass the path to your own configuration directory instead of using"
  481     echo "      one of the built-in configurations, such as: bin/solr create_core -c mycore -d /tmp/myconfig"
  482     echo ""
  483     echo "  -p <port>     Port of a local Solr instance where you want to create the new core"
  484     echo "                  If not specified, the script will search the local system for a running"
  485     echo "                  Solr instance and will use the port of the first server it finds."
  486     echo ""
  487     echo "  -V            Enable more verbose output."
  488     echo ""
  489   elif [ "$CMD" == "create_collection" ]; then
  490     echo ""
  491     echo "Usage: solr create_collection [-c collection] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port] [-V]"
  492     echo ""
  493     echo "Can be run from remote (non-Solr) hosts, as long as a valid SOLR_HOST is provided in solr.in.sh"
  494     echo "  -c <collection>         Name of collection to create"
  495     echo ""
  496     echo "  -d <confdir>            Configuration directory to copy when creating the new collection, built-in options are:"
  497     echo ""
  498     echo "      _default: Minimal configuration, which supports enabling/disabling field-guessing support"
  499     echo "      sample_techproducts_configs: Example configuration with many optional features enabled to"
  500     echo "         demonstrate the full power of Solr"
  501     echo ""
  502     echo "      If not specified, default is: _default"
  503     echo ""
  504     echo "      Alternatively, you can pass the path to your own configuration directory instead of using"
  505     echo "      one of the built-in configurations, such as: bin/solr create_collection -c mycoll -d /tmp/myconfig"
  506     echo ""
  507     echo "      By default the script will upload the specified confdir directory into Zookeeper using the same"
  508     echo "      name as the collection (-c) option. Alternatively, if you want to reuse an existing directory"
  509     echo "      or create a confdir in Zookeeper that can be shared by multiple collections, use the -n option"
  510     echo ""
  511     echo "  -n <configName>         Name the configuration directory in Zookeeper; by default, the configuration"
  512     echo "                            will be uploaded to Zookeeper using the collection name (-c), but if you want"
  513     echo "                            to use an existing directory or override the name of the configuration in"
  514     echo "                            Zookeeper, then use the -c option."
  515     echo ""
  516     echo "  -shards <#>             Number of shards to split the collection into; default is 1"
  517     echo ""
  518     echo "  -replicationFactor <#>  Number of copies of each document in the collection, default is 1 (no replication)"
  519     echo ""
  520     echo "  -p <port>               Port of a local Solr instance where you want to create the new collection"
  521     echo "                            If not specified, the script will search the local system for a running"
  522     echo "                            Solr instance and will use the port of the first server it finds."
  523     echo ""
  524     echo "  -V                      Enable more verbose output."
  525     echo ""
  526   elif [ "$CMD" == "zk" ]; then
  527     print_short_zk_usage ""
  528     echo "         Can be run on remote (non-Solr) hosts, as long as valid ZK_HOST information is provided"
  529     echo "         Be sure to check the Solr logs in case of errors."
  530     echo ""
  531     echo "             -z zkHost  Optional Zookeeper connection string for all commands. If specified it"
  532     echo "                        overrides the 'ZK_HOST=...'' defined in solr.in.sh."
  533     echo ""
  534     echo "             -V        Enable more verbose output."
  535     echo ""
  536     echo "         upconfig uploads a configset from the local machine to Zookeeper. (Backcompat: -upconfig)"
  537     echo ""
  538     echo "         downconfig downloads a configset from Zookeeper to the local machine. (Backcompat: -downconfig)"
  539     echo ""
  540     echo "             -n configName    Name of the configset in Zookeeper that will be the destination of"
  541     echo "                             'upconfig' and the source for 'downconfig'."
  542     echo ""
  543     echo "             -d confdir      The local directory the configuration will be uploaded from for"
  544     echo "                             'upconfig' or downloaded to for 'downconfig'. If 'confdir' is a child of"
  545     echo "                             ...solr/server/solr/configsets' then the configs will be copied from/to"
  546     echo "                             that directory. Otherwise it is interpreted as a simple local path."
  547     echo ""
  548     echo "         cp copies files or folders to/from Zookeeper or Zokeeper -> Zookeeper"
  549     echo "             -r    Recursively copy <src> to <dst>. Command will fail if <src> has children and "
  550     echo "                        -r is not specified. Optional"
  551     echo ""
  552     echo "             <src>, <dest> : [file:][/]path/to/local/file or zk:/path/to/zk/node"
  553     echo "                             NOTE: <src> and <dest> may both be Zookeeper resources prefixed by 'zk:'"
  554     echo "             When <src> is a zk resource, <dest> may be '.'"
  555     echo "             If <dest> ends with '/', then <dest> will be a local folder or parent znode and the last"
  556     echo "             element of the <src> path will be appended unless <src> also ends in a slash. "
  557     echo "             <dest> may be zk:, which may be useful when using the cp -r form to backup/restore "
  558     echo "             the entire zk state."
  559     echo "             You must enclose local paths that end in a wildcard in quotes or just"
  560     echo "             end the local path in a slash. That is,"
  561     echo "             'bin/solr zk cp -r /some/dir/ zk:/ -z localhost:2181' is equivalent to"
  562     echo "             'bin/solr zk cp -r \"/some/dir/*\" zk:/ -z localhost:2181'"
  563     echo "             but 'bin/solr zk cp -r /some/dir/* zk:/ -z localhost:2181' will throw an error"
  564     echo ""
  565     echo "             here's an example of backup/restore for a ZK configuration:"
  566     echo "             to copy to local: 'bin/solr zk cp -r zk:/ /some/dir -z localhost:2181'"
  567     echo "             to restore to ZK: 'bin/solr zk cp -r /some/dir/ zk:/ -z localhost:2181'"
  568     echo ""
  569     echo "             The 'file:' prefix is stripped, thus 'file:/wherever' specifies an absolute local path and"
  570     echo "             'file:somewhere' specifies a relative local path. All paths on Zookeeper are absolute."
  571     echo ""
  572     echo "             Zookeeper nodes CAN have data, so moving a single file to a parent znode"
  573     echo "             will overlay the data on the parent Znode so specifying the trailing slash"
  574     echo "             can be important."
  575     echo ""
  576     echo "             Wildcards are supported when copying from local, trailing only and must be quoted."
  577     echo ""
  578     echo "         rm deletes files or folders on Zookeeper"
  579     echo "             -r     Recursively delete if <path> is a directory. Command will fail if <path>"
  580     echo "                    has children and -r is not specified. Optional"
  581     echo "             <path> : [zk:]/path/to/zk/node. <path> may not be the root ('/')"
  582     echo ""
  583     echo "         mv moves (renames) znodes on Zookeeper"
  584     echo "             <src>, <dest> : Zookeeper nodes, the 'zk:' prefix is optional."
  585     echo "             If <dest> ends with '/', then <dest> will be a parent znode"
  586     echo "             and the last element of the <src> path will be appended."
  587     echo "             Zookeeper nodes CAN have data, so moving a single file to a parent znode"
  588     echo "             will overlay the data on the parent Znode so specifying the trailing slash"
  589     echo "             is important."
  590     echo ""
  591     echo "         ls lists the znodes on Zookeeper"
  592     echo "             -r recursively descends the path listing all znodes. Optional"
  593     echo "             <path>: The Zookeeper path to use as the root."
  594     echo ""
  595     echo "             Only the node names are listed, not data"
  596     echo ""
  597     echo "         mkroot makes a znode in Zookeeper with no data. Can be used to make a path of arbitrary"
  598     echo "             depth but primarily intended to create a 'chroot'."
  599     echo ""
  600     echo "             <path>: The Zookeeper path to create. Leading slash is assumed if not present."
  601     echo "                     Intermediate nodes are created as needed if not present."
  602     echo ""
  603   elif [ "$CMD" == "auth" ]; then
  604     echo ""
  605     echo "Usage: solr auth enable [-type basicAuth] -credentials user:pass [-blockUnknown <true|false>] [-updateIncludeFileOnly <true|false>] [-V]"
  606     echo "       solr auth enable [-type basicAuth] -prompt <true|false> [-blockUnknown <true|false>] [-updateIncludeFileOnly <true|false>] [-V]"
  607     echo "       solr auth enable -type kerberos -config \"<kerberos configs>\" [-updateIncludeFileOnly <true|false>] [-V]"
  608     echo "       solr auth disable [-updateIncludeFileOnly <true|false>] [-V]"
  609     echo ""
  610     echo "  Updates or enables/disables authentication.  Must be run on the machine hosting Solr."
  611     echo ""
  612     echo "  -type <type>                           The authentication mechanism (basicAuth or kerberos) to enable. Defaults to 'basicAuth'."
  613     echo ""
  614     echo "  -credentials <user:pass>               The username and password of the initial user. Applicable for basicAuth only."
  615     echo "                                         Note: only one of -prompt or -credentials must be provided"
  616     echo ""
  617     echo "  -config \"<configs>\"                    Configuration parameters (Solr startup parameters). Required and applicable only for Kerberos"
  618     echo ""
  619     echo "  -prompt <true|false>                   Prompts the user to provide the credentials. Applicable for basicAuth only."
  620     echo "                                         Note: only one of -prompt or -credentials must be provided"
  621     echo ""
  622     echo "  -blockUnknown <true|false>             When true, this blocks out access to unauthenticated users. When not provided,"
  623     echo "                                         this defaults to false (i.e. unauthenticated users can access all endpoints, except the"
  624     echo "                                         operations like collection-edit, security-edit, core-admin-edit etc.). Check the reference"
  625     echo "                                         guide for Basic Authentication for more details. Applicable for basicAuth only."
  626     echo ""
  627     echo "  -updateIncludeFileOnly <true|false>    Only update the solr.in.sh or solr.in.cmd file, and skip actual enabling/disabling"
  628     echo "                                         authentication (i.e. don't update security.json)"
  629     echo ""
  630     echo "  -z zkHost                              Zookeeper connection string. Unnecessary if ZK_HOST is defined in solr.in.sh."
  631     echo ""
  632     echo "  -d <dir>                               Specify the Solr server directory"
  633     echo ""
  634     echo "  -s <dir>                               Specify the Solr home directory. This is where any credentials or authentication"
  635     echo "                                         configuration files (e.g. basicAuth.conf) would be placed."
  636     echo ""
  637     echo "  -V                                     Enable more verbose output."
  638     echo ""
  639   fi
  640 } # end print_usage
  641 
  642 function print_short_zk_usage() {
  643 
  644   if [ "$1" != "" ]; then
  645     echo -e "\nERROR: $1\n"
  646   fi
  647 
  648   echo "  Usage: solr zk upconfig|downconfig -d <confdir> -n <configName> [-z zkHost]"
  649   echo "         solr zk cp [-r] <src> <dest> [-z zkHost]"
  650   echo "         solr zk rm [-r] <path> [-z zkHost]"
  651   echo "         solr zk mv <src> <dest> [-z zkHost]"
  652   echo "         solr zk ls [-r] <path> [-z zkHost]"
  653   echo "         solr zk mkroot <path> [-z zkHost]"
  654   echo ""
  655 
  656   if [ "$1" == "" ]; then
  657     echo "Type bin/solr zk -help for full usage help"
  658   else
  659     exit 1
  660   fi
  661 }
  662 
  663 # used to show the script is still alive when waiting on work to complete
  664 function spinner() {
  665   local pid=$1
  666   local delay=0.5
  667   local spinstr='|/-\'
  668   while [ "$(ps aux | awk '{print $2}' | grep -w $pid)" ]; do
  669       local temp=${spinstr#?}
  670       printf " [%c]  " "$spinstr"
  671       local spinstr=$temp${spinstr%"$temp"}
  672       sleep $delay
  673       printf "\b\b\b\b\b\b"
  674   done
  675   printf "    \b\b\b\b"
  676 }
  677 
  678 # given a port, find the pid for a Solr process
  679 function solr_pid_by_port() {
  680   THE_PORT="$1"
  681   if [ -e "$SOLR_PID_DIR/solr-$THE_PORT.pid" ]; then
  682     PID=`cat "$SOLR_PID_DIR/solr-$THE_PORT.pid"`
  683     CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $PID | sort -r | tr -d ' '`
  684     if [ "$CHECK_PID" != "" ]; then
  685       local solrPID=$PID
  686     fi
  687   fi
  688   echo "$solrPID"
  689 }
  690 
  691 # extract the value of the -Djetty.port parameter from a running Solr process
  692 function jetty_port() {
  693   SOLR_PID="$1"
  694   SOLR_PROC=`ps auxww | grep -w $SOLR_PID | grep start\.jar | grep jetty\.port`
  695   IFS=' ' read -a proc_args <<< "$SOLR_PROC"
  696   for arg in "${proc_args[@]}"
  697     do
  698       IFS='=' read -a pair <<< "$arg"
  699       if [ "${pair[0]}" == "-Djetty.port" ]; then
  700         local jetty_port="${pair[1]}"
  701         break
  702       fi
  703     done
  704   echo "$jetty_port"
  705 } # end jetty_port func
  706 
  707 # run a Solr command-line tool using the SolrCLI class;
  708 # useful for doing cross-platform work from the command-line using Java
  709 function run_tool() {
  710 
  711   "$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS $SOLR_ZK_CREDS_AND_ACLS -Dsolr.install.dir="$SOLR_TIP" \
  712     -Dlog4j.configurationFile="file:$DEFAULT_SERVER_DIR/resources/log4j2-console.xml" \
  713     -classpath "$DEFAULT_SERVER_DIR/solr-webapp/webapp/WEB-INF/lib/*:$DEFAULT_SERVER_DIR/lib/ext/*:$DEFAULT_SERVER_DIR/lib/*" \
  714     org.apache.solr.util.SolrCLI "$@"
  715 
  716   return $?
  717 } # end run_tool function
  718 
  719 # get information about any Solr nodes running on this host
  720 function get_info() {
  721   CODE=4
  722   # first, see if Solr is running
  723   numSolrs=`find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' '`
  724   if [ "$numSolrs" != "0" ]; then
  725     echo -e "\nFound $numSolrs Solr nodes: "
  726     while read PIDF
  727       do
  728         ID=`cat "$PIDF"`
  729         port=`jetty_port "$ID"`
  730         if [ "$port" != "" ]; then
  731           echo -e "\nSolr process $ID running on port $port"
  732           run_tool status -solr "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr"
  733           CODE=$?
  734           echo ""
  735         else
  736           echo -e "\nSolr process $ID from $PIDF not found."
  737           CODE=1
  738         fi
  739     done < <(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)
  740   else
  741     # no pid files but check using ps just to be sure
  742     numSolrs=`ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//'`
  743     if [ "$numSolrs" != "0" ]; then
  744       echo -e "\nFound $numSolrs Solr nodes: "
  745       PROCESSES=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | awk '{print $2}' | sort -r)
  746       for ID in $PROCESSES
  747         do
  748           port=`jetty_port "$ID"`
  749           if [ "$port" != "" ]; then
  750             echo ""
  751             echo "Solr process $ID running on port $port"
  752             run_tool status -solr "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr"
  753             CODE=$?
  754             echo ""
  755           fi
  756       done
  757     else
  758       echo -e "\nNo Solr nodes are running.\n"
  759       CODE=3
  760     fi
  761   fi
  762 
  763   return $CODE
  764 } # end get_info
  765 
  766 function run_package() {
  767   runningSolrUrl=""
  768 
  769   numSolrs=`find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' '`
  770   if [ "$numSolrs" != "0" ]; then
  771     #echo -e "\nFound $numSolrs Solr nodes: "
  772     while read PIDF
  773       do
  774         ID=`cat "$PIDF"`
  775         port=`jetty_port "$ID"`
  776         if [ "$port" != "" ]; then
  777           #echo -e "\nSolr process $ID running on port $port"
  778           runningSolrUrl="$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr"
  779           break
  780           CODE=$?
  781           echo ""
  782         else
  783           echo -e "\nSolr process $ID from $PIDF not found."
  784           CODE=1
  785         fi
  786     done < <(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)
  787   else
  788     # no pid files but check using ps just to be sure
  789     numSolrs=`ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//'`
  790     if [ "$numSolrs" != "0" ]; then
  791       echo -e "\nFound $numSolrs Solr nodes: "
  792       PROCESSES=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | awk '{print $2}' | sort -r)
  793       for ID in $PROCESSES
  794         do
  795           port=`jetty_port "$ID"`
  796           if [ "$port" != "" ]; then
  797             echo ""
  798             echo "Solr process $ID running on port $port"
  799             runningSolrUrl="$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr"
  800             break
  801             CODE=$?
  802             echo ""
  803           fi
  804       done
  805     else
  806       echo -e "\nNo Solr nodes are running.\n"
  807       exit 1
  808       CODE=3
  809     fi
  810   fi
  811 
  812   run_tool package -solrUrl "$runningSolrUrl" $@
  813   #exit $?
  814 }
  815 
  816 # tries to gracefully stop Solr using the Jetty
  817 # stop command and if that fails, then uses kill -9
  818 function stop_solr() {
  819 
  820   DIR="$1"
  821   SOLR_PORT="$2"
  822   THIS_STOP_PORT="${STOP_PORT:-$(expr $SOLR_PORT - 1000)}"
  823   STOP_KEY="$3"
  824   SOLR_PID="$4"
  825 
  826   if [ "$SOLR_PID" != "" ]; then
  827     echo -e "Sending stop command to Solr running on port $SOLR_PORT ... waiting up to $SOLR_STOP_WAIT seconds to allow Jetty process $SOLR_PID to stop gracefully."
  828     "$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS -jar "$DIR/start.jar" "STOP.PORT=$THIS_STOP_PORT" "STOP.KEY=$STOP_KEY" --stop || true
  829       (loops=0
  830       while true
  831       do
  832         CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
  833         if [ "$CHECK_PID" != "" ]; then
  834           slept=$((loops * 2))
  835           if [ $slept -lt $SOLR_STOP_WAIT ]; then
  836             sleep 2
  837             loops=$[$loops+1]
  838           else
  839             exit # subshell!
  840           fi
  841         else
  842           exit # subshell!
  843         fi
  844       done) &
  845     spinner $!
  846     rm -f "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
  847   else
  848     echo -e "No Solr nodes found to stop."
  849     exit 0
  850   fi
  851 
  852   CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
  853   if [ "$CHECK_PID" != "" ]; then
  854     echo -e "Solr process $SOLR_PID is still running; forcefully killing it now."
  855     kill -9 $SOLR_PID
  856     echo "Killed process $SOLR_PID"
  857     rm -f "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
  858     sleep 1
  859   fi
  860 
  861   CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
  862   if [ "$CHECK_PID" != "" ]; then
  863     echo "ERROR: Failed to kill previous Solr Java process $SOLR_PID ... script fails."
  864     exit 1
  865   fi
  866 } # end stop_solr
  867 
  868 if [ $# -eq 1 ]; then
  869   case $1 in
  870     -help|-usage|-h|--help)
  871         print_usage ""
  872         exit
  873     ;;
  874     -info|-i|status)
  875         get_info
  876         exit $?
  877     ;;
  878     -version|-v|version)
  879         run_tool version
  880         exit
  881     ;;
  882   esac
  883 fi
  884 
  885 if [ $# -gt 0 ]; then
  886   # if first arg starts with a dash (and it's not -help or -info),
  887   # then assume they are starting Solr, such as: solr -f
  888   if [[ $1 == -* ]]; then
  889     SCRIPT_CMD="start"
  890   else
  891     SCRIPT_CMD="$1"
  892     shift
  893   fi
  894 else
  895   # no args - just show usage and exit
  896   print_usage ""
  897   exit
  898 fi
  899 
  900 if [ "$SCRIPT_CMD" == "status" ]; then
  901   # hacky - the script hits this if the user passes additional args with the status command,
  902   # which is not supported but also not worth complaining about either
  903   get_info
  904   exit
  905 fi
  906 
  907 # assert tool
  908 if [ "$SCRIPT_CMD" == "assert" ]; then
  909   run_tool assert $*
  910   exit $?
  911 fi
  912 
  913 # run a healthcheck and exit if requested
  914 if [ "$SCRIPT_CMD" == "healthcheck" ]; then
  915 
  916   VERBOSE=""
  917 
  918   if [ $# -gt 0 ]; then
  919     while true; do
  920       case "$1" in
  921           -c|-collection)
  922               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
  923                 print_usage "$SCRIPT_CMD" "Collection name is required when using the $1 option!"
  924                 exit 1
  925               fi
  926               HEALTHCHECK_COLLECTION="$2"
  927               shift 2
  928           ;;
  929           -z|-zkhost)
  930               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
  931                 print_usage "$SCRIPT_CMD" "ZooKeeper connection string is required when using the $1 option!"
  932                 exit 1
  933               fi
  934               ZK_HOST="$2"
  935               shift 2
  936           ;;
  937           -help|-usage)
  938               print_usage "$SCRIPT_CMD"
  939               exit 0
  940           ;;
  941           -V|--verbose)
  942               VERBOSE="-verbose"
  943               shift
  944           ;;
  945           --)
  946               shift
  947               break
  948           ;;
  949           *)
  950               if [ "$1" != "" ]; then
  951                 print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
  952                 exit 1
  953               else
  954                 break # out-of-args, stop looping
  955               fi
  956           ;;
  957       esac
  958     done
  959   fi
  960 
  961   if [ -z "$ZK_HOST" ]; then
  962     ZK_HOST=localhost:9983
  963   fi
  964 
  965   if [ -z "$HEALTHCHECK_COLLECTION" ]; then
  966     echo "collection parameter is required!"
  967     print_usage "healthcheck"
  968     exit 1
  969   fi
  970 
  971   run_tool healthcheck -zkHost "$ZK_HOST" -collection "$HEALTHCHECK_COLLECTION" $VERBOSE
  972 
  973   exit $?
  974 fi
  975 
  976 if [[ "$SCRIPT_CMD" == "config" ]]; then
  977   CONFIG_PARAMS=()
  978 
  979   if [ $# -gt 0 ]; then
  980     while true; do
  981       case "$1" in
  982           -z|-zkhost|-zkHost)
  983               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
  984                 print_usage "$SCRIPT_CMD" "ZooKeeper connection string is required when using the $1 option!"
  985                 exit 1
  986               fi
  987               ZK_HOST="$2"
  988               shift 2
  989           ;;
  990           -s|-scheme)
  991               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
  992                 print_usage "$SCRIPT_CMD" "URL scheme is required when using the $1 option!"
  993                 exit 1
  994               fi
  995               SOLR_URL_SCHEME="$2"
  996               shift 2
  997           ;;
  998           *)  # Pass through all other params
  999               if [ "$1" != "" ]; then
 1000                 CONFIG_PARAMS+=($1)
 1001                 shift
 1002               else
 1003                 break
 1004               fi
 1005           ;;
 1006       esac
 1007     done
 1008   fi
 1009   if [[ -n "$ZK_HOST" ]]; then
 1010     CONFIG_PARAMS+=("-z" "$ZK_HOST")
 1011   fi
 1012   if [[ -n "$SOLR_URL_SCHEME" ]]; then
 1013     CONFIG_PARAMS+=("-scheme" "$SOLR_URL_SCHEME")
 1014   fi
 1015   run_tool config "${CONFIG_PARAMS[@]}"
 1016   exit $?
 1017 fi
 1018 
 1019 # create a core or collection
 1020 if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CMD" == "create_collection" ]]; then
 1021 
 1022   CREATE_NUM_SHARDS=1
 1023   CREATE_REPFACT=1
 1024   FORCE=false
 1025   VERBOSE=""
 1026 
 1027   if [ $# -gt 0 ]; then
 1028     while true; do
 1029       case "$1" in
 1030           -c|-core|-collection)
 1031               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1032                 print_usage "$SCRIPT_CMD" "name is required when using the $1 option!"
 1033                 exit 1
 1034               fi
 1035               CREATE_NAME="$2"
 1036               shift 2
 1037           ;;
 1038           -n|-confname)
 1039               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1040                 print_usage "$SCRIPT_CMD" "Configuration name is required when using the $1 option!"
 1041                 exit 1
 1042               fi
 1043               CREATE_CONFNAME="$2"
 1044               shift 2
 1045           ;;
 1046           -d|-confdir)
 1047               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1048                 print_usage "$SCRIPT_CMD" "Configuration directory is required when using the $1 option!"
 1049                 exit 1
 1050               fi
 1051               CREATE_CONFDIR="$2"
 1052               shift 2
 1053           ;;
 1054           -s|-shards)
 1055               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1056                 print_usage "$SCRIPT_CMD" "Shard count is required when using the $1 option!"
 1057                 exit 1
 1058               fi
 1059               CREATE_NUM_SHARDS="$2"
 1060               shift 2
 1061           ;;
 1062           -rf|-replicationFactor)
 1063               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1064                 print_usage "$SCRIPT_CMD" "Replication factor is required when using the $1 option!"
 1065                 exit 1
 1066               fi
 1067               CREATE_REPFACT="$2"
 1068               shift 2
 1069           ;;
 1070           -p|-port)
 1071               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1072                 print_usage "$SCRIPT_CMD" "Solr port is required when using the $1 option!"
 1073                 exit 1
 1074               fi
 1075               CREATE_PORT="$2"
 1076               shift 2
 1077           ;;
 1078           -V|--verbose)
 1079               VERBOSE="-verbose"
 1080               shift
 1081           ;;
 1082           -force)
 1083               FORCE=true
 1084               shift
 1085           ;;
 1086           -help|-usage)
 1087               print_usage "$SCRIPT_CMD"
 1088               exit 0
 1089           ;;
 1090           --)
 1091               shift
 1092               break
 1093           ;;
 1094           *)
 1095               if [ "$1" != "" ]; then
 1096                 print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
 1097                 exit 1
 1098               else
 1099                 break # out-of-args, stop looping
 1100               fi
 1101           ;;
 1102       esac
 1103     done
 1104   fi
 1105 
 1106   if [ -z "$CREATE_CONFDIR" ]; then
 1107     CREATE_CONFDIR='_default'
 1108   fi
 1109 
 1110   # validate the confdir arg (if provided)
 1111   if [[ ! -d "$SOLR_TIP/server/solr/configsets/$CREATE_CONFDIR" && ! -d "$CREATE_CONFDIR" ]]; then
 1112     echo -e "\nSpecified configuration directory $CREATE_CONFDIR not found!\n"
 1113     exit 1
 1114   fi
 1115 
 1116   if [ -z "$CREATE_NAME" ]; then
 1117     echo "Name (-c) argument is required!"
 1118     print_usage "$SCRIPT_CMD"
 1119     exit 1
 1120   fi
 1121 
 1122   if [ -z "$CREATE_PORT" ]; then
 1123     for ID in `ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r`
 1124       do
 1125         port=`jetty_port "$ID"`
 1126         if [ "$port" != "" ]; then
 1127           CREATE_PORT=$port
 1128           break
 1129         fi
 1130     done
 1131   fi
 1132 
 1133   if [ -z "$CREATE_PORT" ]; then
 1134     echo "Failed to determine the port of a local Solr instance, cannot create $CREATE_NAME!"
 1135     exit 1
 1136   fi
 1137 
 1138   if [[ "$CREATE_CONFDIR" == "_default" ]] && ([[ "$CREATE_CONFNAME" == "" ]] || [[ "$CREATE_CONFNAME" == "_default" ]]); then
 1139     echo "WARNING: Using _default configset with data driven schema functionality. NOT RECOMMENDED for production use."
 1140     echo "         To turn off: bin/solr config -c $CREATE_NAME -p $CREATE_PORT -action set-user-property -property update.autoCreateFields -value false"
 1141   fi
 1142 
 1143   if [[ $EUID -eq 0 ]] && [[ "$FORCE" == "false" ]] ; then
 1144     echo "WARNING: Creating cores as the root user can cause Solr to fail and is not advisable. Exiting."
 1145     echo "         If you started Solr as root (not advisable either), force core creation by adding argument -force"
 1146     exit 1
 1147   fi
 1148   if [ "$SCRIPT_CMD" == "create_core" ]; then
 1149     run_tool create_core -name "$CREATE_NAME" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$CREATE_PORT/solr" \
 1150       -confdir "$CREATE_CONFDIR" -configsetsDir "$SOLR_TIP/server/solr/configsets" \
 1151       $VERBOSE
 1152     exit $?
 1153   else
 1154     run_tool "$SCRIPT_CMD" -name "$CREATE_NAME" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$CREATE_PORT/solr" \
 1155       -shards "$CREATE_NUM_SHARDS" -replicationFactor "$CREATE_REPFACT" \
 1156       -confname "$CREATE_CONFNAME" -confdir "$CREATE_CONFDIR" \
 1157       -configsetsDir "$SOLR_TIP/server/solr/configsets" \
 1158       $VERBOSE
 1159     exit $?
 1160   fi
 1161 fi
 1162 
 1163 # delete a core or collection
 1164 if [[ "$SCRIPT_CMD" == "delete" ]]; then
 1165 
 1166   VERBOSE=""
 1167 
 1168   if [ $# -gt 0 ]; then
 1169     while true; do
 1170       case "$1" in
 1171           -c|-core|-collection)
 1172               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1173                 print_usage "$SCRIPT_CMD" "name is required when using the $1 option!"
 1174                 exit 1
 1175               fi
 1176               DELETE_NAME="$2"
 1177               shift 2
 1178           ;;
 1179           -p|-port)
 1180               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1181                 print_usage "$SCRIPT_CMD" "Solr port is required when using the $1 option!"
 1182                 exit 1
 1183               fi
 1184               DELETE_PORT="$2"
 1185               shift 2
 1186           ;;
 1187           -deleteConfig)
 1188               if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1189                 print_usage "$SCRIPT_CMD" "true|false is required when using the $1 option!"
 1190                 exit 1
 1191               fi
 1192               DELETE_CONFIG="$2"
 1193               shift 2
 1194           ;;
 1195           -V|--verbose)
 1196               VERBOSE="-verbose"
 1197               shift
 1198           ;;
 1199           -help|-usage)
 1200               print_usage "$SCRIPT_CMD"
 1201               exit 0
 1202           ;;
 1203           --)
 1204               shift
 1205               break
 1206           ;;
 1207           *)
 1208               if [ "$1" != "" ]; then
 1209                 print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
 1210                 exit 1
 1211               else
 1212                 break # out-of-args, stop looping
 1213               fi
 1214           ;;
 1215       esac
 1216     done
 1217   fi
 1218 
 1219   if [ -z "$DELETE_NAME" ]; then
 1220     echo "Name (-c) argument is required!"
 1221     print_usage "$SCRIPT_CMD"
 1222     exit 1
 1223   fi
 1224 
 1225   # If not defined, use the collection name for the name of the configuration in Zookeeper
 1226   if [ -z "$DELETE_CONFIG" ]; then
 1227     DELETE_CONFIG=true
 1228   fi
 1229 
 1230   if [ -z "$DELETE_PORT" ]; then
 1231     for ID in `ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r`
 1232       do
 1233         port=`jetty_port "$ID"`
 1234         if [ "$port" != "" ]; then
 1235           DELETE_PORT=$port
 1236           break
 1237         fi
 1238     done
 1239   fi
 1240 
 1241   if [ -z "$DELETE_PORT" ]; then
 1242     echo "Failed to determine the port of a local Solr instance, cannot delete $DELETE_NAME!"
 1243     exit 1
 1244   fi
 1245 
 1246   run_tool delete -name "$DELETE_NAME" -deleteConfig "$DELETE_CONFIG" \
 1247     -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$DELETE_PORT/solr" \
 1248     $VERBOSE
 1249   exit $?
 1250 fi
 1251 
 1252 ZK_RECURSE=false
 1253 # Zookeeper file maintenance (upconfig, downconfig, files up/down etc.)
 1254 # It's a little clumsy to have the parsing go round and round for upconfig and downconfig, but that's
 1255 # necessary for back-compat
 1256 if [[ "$SCRIPT_CMD" == "zk" ]]; then
 1257 
 1258   VERBOSE=""
 1259 
 1260   if [ $# -gt 0 ]; then
 1261     while true; do
 1262       case "$1" in
 1263         -upconfig|upconfig|-downconfig|downconfig|cp|rm|mv|ls|mkroot)
 1264             if [ "${1:0:1}" == "-" ]; then
 1265               ZK_OP=${1:1}
 1266             else
 1267               ZK_OP=$1
 1268             fi
 1269             shift 1
 1270         ;;
 1271         -z|-zkhost)
 1272             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1273               print_short_zk_usage "$SCRIPT_CMD" "ZooKeeper connection string is required when using the $1 option!"
 1274             fi
 1275             ZK_HOST="$2"
 1276             shift 2
 1277         ;;
 1278         -n|-confname)
 1279             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1280               print_short_zk_usage "$SCRIPT_CMD" "Configuration name is required when using the $1 option!"
 1281             fi
 1282             CONFIGSET_CONFNAME="$2"
 1283             shift 2
 1284         ;;
 1285         -d|-confdir)
 1286             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1287               print_short_zk_usage "$SCRIPT_CMD" "Configuration directory is required when using the $1 option!"
 1288             fi
 1289             CONFIGSET_CONFDIR="$2"
 1290             shift 2
 1291         ;;
 1292         -r)
 1293             ZK_RECURSE="true"
 1294             shift
 1295         ;;
 1296         -V|--verbose)
 1297             VERBOSE="-verbose"
 1298             shift
 1299         ;;
 1300         -help|-usage|-h)
 1301             print_usage "$SCRIPT_CMD"
 1302             exit 0
 1303         ;;
 1304         --)
 1305             shift
 1306             break
 1307         ;;
 1308         *)  # Pick up <src> <dst> or <path> params for rm, ls, cp, mv, mkroot.
 1309             if [ "$1" == "" ]; then
 1310               break # out-of-args, stop looping
 1311             fi
 1312             if [ -z "$ZK_SRC" ]; then
 1313               ZK_SRC=$1
 1314             else
 1315               if [ -z "$ZK_DST" ]; then
 1316                 ZK_DST=$1
 1317               else
 1318                 print_short_zk_usage "Unrecognized or misplaced command $1. 'cp' with trailing asterisk requires quoting, see help text."
 1319               fi
 1320             fi
 1321             shift
 1322         ;;
 1323       esac
 1324     done
 1325   fi
 1326 
 1327   if [ -z "$ZK_OP" ]; then
 1328     print_short_zk_usage "Zookeeper operation (one of 'upconfig', 'downconfig', 'rm', 'mv', 'cp', 'ls', 'mkroot') is required!"
 1329   fi
 1330 
 1331   if [ -z "$ZK_HOST" ]; then
 1332     print_short_zk_usage "Zookeeper address (-z) argument is required or ZK_HOST must be specified in the solr.in.sh file."
 1333   fi
 1334 
 1335   if [[ "$ZK_OP" == "upconfig" ||  "$ZK_OP" == "downconfig" ]]; then
 1336     if [ -z "$CONFIGSET_CONFDIR" ]; then
 1337       print_short_zk_usage "Local directory of the configset (-d) argument is required!"
 1338     fi
 1339 
 1340     if [ -z "$CONFIGSET_CONFNAME" ]; then
 1341       print_short_zk_usage "Configset name on Zookeeper (-n) argument is required!"
 1342     fi
 1343   fi
 1344 
 1345   if [[ "$ZK_OP" == "cp" || "$ZK_OP" == "mv" ]]; then
 1346     if [[ -z "$ZK_SRC" || -z "$ZK_DST" ]]; then
 1347       print_short_zk_usage "<source> and <destination> must be specified when using either the 'mv' or 'cp' commands."
 1348     fi
 1349     if [[ "$ZK_OP" == "cp" && "${ZK_SRC:0:3}" != "zk:" && "${ZK_DST:0:3}" != "zk:" ]]; then
 1350       print_short_zk_usage "One of the source or desintation paths must be prefixed by 'zk:' for the 'cp' command."
 1351     fi
 1352   fi
 1353 
 1354   if [[ "$ZK_OP" == "mkroot" ]]; then
 1355     if [[ -z "$ZK_SRC" ]]; then
 1356       print_short_zk_usage "<path> must be specified when using the 'mkroot' command."
 1357     fi
 1358   fi
 1359 
 1360 
 1361   case "$ZK_OP" in
 1362     upconfig)
 1363       run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST" -configsetsDir "$SOLR_TIP/server/solr/configsets" $VERBOSE
 1364     ;;
 1365     downconfig)
 1366       run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST" $VERBOSE
 1367     ;;
 1368     rm)
 1369       if [ -z "$ZK_SRC" ]; then
 1370         print_short_zk_usage "Zookeeper path to remove must be specified when using the 'rm' command"
 1371       fi
 1372       run_tool "$ZK_OP" -path "$ZK_SRC" -zkHost "$ZK_HOST" -recurse "$ZK_RECURSE" $VERBOSE
 1373     ;;
 1374     mv)
 1375       run_tool "$ZK_OP" -src "$ZK_SRC" -dst "$ZK_DST" -zkHost "$ZK_HOST" $VERBOSE
 1376     ;;
 1377     cp)
 1378       run_tool "$ZK_OP" -src "$ZK_SRC" -dst "$ZK_DST" -zkHost "$ZK_HOST" -recurse "$ZK_RECURSE" $VERBOSE
 1379     ;;
 1380     ls)
 1381       if [ -z "$ZK_SRC" ]; then
 1382         print_short_zk_usage "Zookeeper path to list must be specified when using the 'ls' command"
 1383       fi
 1384       run_tool "$ZK_OP" -path "$ZK_SRC" -recurse "$ZK_RECURSE" -zkHost "$ZK_HOST" $VERBOSE
 1385     ;;
 1386     mkroot)
 1387       if [ -z "$ZK_SRC" ]; then
 1388         print_short_zk_usage "Zookeeper path to list must be specified when using the 'mkroot' command"
 1389       fi
 1390       run_tool "$ZK_OP" -path "$ZK_SRC" -zkHost "$ZK_HOST" $VERBOSE
 1391     ;;
 1392     *)
 1393       print_short_zk_usage "Unrecognized Zookeeper operation $ZK_OP"
 1394     ;;
 1395   esac
 1396 
 1397   exit $?
 1398 fi
 1399 
 1400 
 1401 if [[ "$SCRIPT_CMD" == "autoscaling" ]]; then
 1402   run_tool autoscaling $@
 1403   exit $?
 1404 fi
 1405 
 1406 if [[ "$SCRIPT_CMD" == "export" ]]; then
 1407   run_tool export $@
 1408   exit $?
 1409 fi
 1410 
 1411 if [[ "$SCRIPT_CMD" == "package" ]]; then
 1412   run_package $@
 1413   exit $?
 1414 fi
 1415 
 1416 if [[ "$SCRIPT_CMD" == "auth" ]]; then
 1417 
 1418   VERBOSE=""
 1419 
 1420   declare -a AUTH_PARAMS
 1421   if [ $# -gt 0 ]; then
 1422     while true; do
 1423       case "$1" in
 1424         enable|disable)
 1425             AUTH_OP=$1
 1426             AUTH_PARAMS=("${AUTH_PARAMS[@]}" "$AUTH_OP")
 1427             shift
 1428         ;;
 1429         -z|-zkhost|zkHost)
 1430             ZK_HOST="$2"
 1431             AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-zkHost" "$ZK_HOST")
 1432             shift 2
 1433         ;;
 1434         -t|-type)
 1435             AUTH_TYPE="$2"
 1436             AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-type" "$AUTH_TYPE")
 1437             shift 2
 1438         ;;
 1439         -credentials)
 1440             AUTH_CREDENTIALS="$2"
 1441             AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-credentials" "$AUTH_CREDENTIALS")
 1442             shift 2
 1443         ;;
 1444         -config)
 1445             AUTH_CONFIG="`echo $2| base64`"
 1446             AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-config" "$AUTH_CONFIG")
 1447             shift 2
 1448         ;;
 1449         -solrIncludeFile)
 1450             SOLR_INCLUDE="$2"
 1451             shift 2
 1452         ;;
 1453         -prompt)
 1454             AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-prompt" "$2")
 1455             shift
 1456         ;;
 1457         -blockUnknown)
 1458             AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-blockUnknown" "$2")
 1459             shift
 1460             break
 1461         ;;
 1462         -updateIncludeFileOnly)
 1463             AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-updateIncludeFileOnly" "$2")
 1464             shift
 1465             break
 1466         ;;
 1467         -V|--verbose)
 1468             VERBOSE="-verbose"
 1469             shift
 1470         ;;
 1471         -d|-dir)
 1472             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1473               print_usage "$SCRIPT_CMD" "Server directory is required when using the $1 option!"
 1474               exit 1
 1475             fi
 1476 
 1477             if [[ "$2" == "." || "$2" == "./" || "$2" == ".." || "$2" == "../" ]]; then
 1478               SOLR_SERVER_DIR="$(pwd)/$2"
 1479             else
 1480               # see if the arg value is relative to the tip vs full path
 1481               if [[ "$2" != /* ]] && [[ -d "$SOLR_TIP/$2" ]]; then
 1482                 SOLR_SERVER_DIR="$SOLR_TIP/$2"
 1483               else
 1484                 SOLR_SERVER_DIR="$2"
 1485               fi
 1486             fi
 1487             # resolve it to an absolute path
 1488             SOLR_SERVER_DIR="$(cd "$SOLR_SERVER_DIR"; pwd)"
 1489             shift 2
 1490         ;;
 1491         -s|-solr.home)
 1492             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1493               print_usage "$SCRIPT_CMD" "Solr home directory is required when using the $1 option!"
 1494               exit 1
 1495             fi
 1496 
 1497             SOLR_HOME="$2"
 1498             shift 2
 1499         ;;
 1500         -help|-usage|-h)
 1501             print_usage "$SCRIPT_CMD"
 1502             exit 0
 1503         ;;
 1504         --)
 1505             shift
 1506             break
 1507         ;;
 1508         *)
 1509             shift
 1510             break
 1511         ;;
 1512       esac
 1513     done
 1514   fi
 1515 
 1516   if [ -z "$SOLR_SERVER_DIR" ]; then
 1517     SOLR_SERVER_DIR="$DEFAULT_SERVER_DIR"
 1518   fi
 1519   if [ ! -e "$SOLR_SERVER_DIR" ]; then
 1520     echo -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n"
 1521     exit 1
 1522   fi
 1523 
 1524   if [ -z "$SOLR_HOME" ]; then
 1525     SOLR_HOME="$SOLR_SERVER_DIR/solr"
 1526   elif [[ $SOLR_HOME != /* ]]; then
 1527     if [[ -d "`pwd`/$SOLR_HOME" ]]; then
 1528       SOLR_HOME="$(pwd)/$SOLR_HOME"
 1529     elif [[ -d "$SOLR_SERVER_DIR/$SOLR_HOME" ]]; then
 1530       SOLR_HOME="$SOLR_SERVER_DIR/$SOLR_HOME"
 1531       SOLR_PID_DIR="$SOLR_HOME"
 1532     fi
 1533   fi
 1534 
 1535   if [ -z "$AUTH_OP" ]; then
 1536     print_usage "$SCRIPT_CMD"
 1537     exit 0
 1538   fi
 1539 
 1540   AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-solrIncludeFile" "$SOLR_INCLUDE")
 1541 
 1542   if [ -z "$AUTH_PORT" ]; then
 1543     for ID in `ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r`
 1544       do
 1545         port=`jetty_port "$ID"`
 1546         if [ "$port" != "" ]; then
 1547           AUTH_PORT=$port
 1548           break
 1549         fi
 1550       done
 1551   fi
 1552   run_tool auth ${AUTH_PARAMS[@]} -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$AUTH_PORT/solr" -authConfDir "$SOLR_HOME" $VERBOSE
 1553   exit $?
 1554 fi
 1555 
 1556 
 1557 # verify the command given is supported
 1558 if [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD" != "restart" ] && [ "$SCRIPT_CMD" != "status" ] && [ "$SCRIPT_CMD" != "assert" ]; then
 1559   print_usage "" "$SCRIPT_CMD is not a valid command!"
 1560   exit 1
 1561 fi
 1562 
 1563 #Check current Ulimits for Open Files and Max Processes.  Warn if they are below the recommended values.
 1564 
 1565 if [ -z "$SOLR_RECOMMENDED_MAX_PROCESSES" ]; then
 1566   SOLR_RECOMMENDED_MAX_PROCESSES=65000
 1567 fi
 1568 
 1569 if [ -z "$SOLR_RECOMMENDED_OPEN_FILES" ]; then
 1570   SOLR_RECOMMENDED_OPEN_FILES=65000
 1571 fi
 1572 
 1573 if [ -z "$SOLR_ULIMIT_CHECKS" ] || [ "$SOLR_ULIMIT_CHECKS" != "false" ]; then
 1574   if [ "$SCRIPT_CMD" == "start" ] || [ "$SCRIPT_CMD" == "restart" ] || [ "$SCRIPT_CMD" == "status" ]; then
 1575     if hash ulimit 2>/dev/null; then
 1576        openFiles=$(ulimit -n)
 1577        maxProcs=$(ulimit -u)
 1578        virtualMemory=$(ulimit -v)
 1579        maxMemory=$(ulimit -m)
 1580        if [ $openFiles != "unlimited" ] && [ $openFiles -lt "$SOLR_RECOMMENDED_OPEN_FILES" ]; then
 1581            echo "*** [WARN] *** Your open file limit is currently $openFiles.  "
 1582            echo " It should be set to $SOLR_RECOMMENDED_OPEN_FILES to avoid operational disruption. "
 1583            echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"
 1584        fi
 1585 
 1586        if [ $maxProcs != "unlimited" ] && [ $maxProcs -lt "$SOLR_RECOMMENDED_MAX_PROCESSES" ]; then
 1587            echo "*** [WARN] ***  Your Max Processes Limit is currently $maxProcs. "
 1588            echo " It should be set to $SOLR_RECOMMENDED_MAX_PROCESSES to avoid operational disruption. "
 1589            echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"
 1590        fi
 1591        if [ $virtualMemory != "unlimited" ]; then
 1592            echo "*** [WARN] ***  Your Virtual Memory limit is $virtualMemory. "
 1593            echo " It should be set to 'unlimited' to avoid operational disruption. "
 1594            echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"
 1595        fi
 1596        if [ $maxMemory != "unlimited" ]; then
 1597            echo "*** [WARN] ***  Your Max Memory Size limit is $maxMemory. "
 1598            echo " It should be set to 'unlimited' to avoid operational disruption. "
 1599            echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"
 1600        fi
 1601 
 1602     else
 1603       echo "Could not check ulimits for processes and open files, recommended values are"
 1604       echo "     max processes:   $SOLR_RECOMMENDED_MAX_PROCESSES "
 1605       echo "     open files:      $SOLR_RECOMMENDED_OPEN_FILES"
 1606       echo "     virtual memory:  unlimited"
 1607       echo "     max memorh size: unlimited"
 1608     fi
 1609   fi
 1610 fi
 1611 
 1612 # Run in foreground (default is to run in the background)
 1613 FG="false"
 1614 FORCE=false
 1615 noprompt=false
 1616 SOLR_OPTS=($SOLR_OPTS)
 1617 PASS_TO_RUN_EXAMPLE=
 1618 
 1619 if [ $# -gt 0 ]; then
 1620   while true; do
 1621     case "$1" in
 1622         -c|-cloud)
 1623             SOLR_MODE="solrcloud"
 1624             PASS_TO_RUN_EXAMPLE+=" -c"
 1625             shift
 1626         ;;
 1627         -d|-dir)
 1628             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1629               print_usage "$SCRIPT_CMD" "Server directory is required when using the $1 option!"
 1630               exit 1
 1631             fi
 1632 
 1633             if [[ "$2" == "." || "$2" == "./" || "$2" == ".." || "$2" == "../" ]]; then
 1634               SOLR_SERVER_DIR="$(pwd)/$2"
 1635             else
 1636               # see if the arg value is relative to the tip vs full path
 1637               if [[ "$2" != /* ]] && [[ -d "$SOLR_TIP/$2" ]]; then
 1638                 SOLR_SERVER_DIR="$SOLR_TIP/$2"
 1639               else
 1640                 SOLR_SERVER_DIR="$2"
 1641               fi
 1642             fi
 1643             # resolve it to an absolute path
 1644             SOLR_SERVER_DIR="$(cd "$SOLR_SERVER_DIR"; pwd)"
 1645             shift 2
 1646         ;;
 1647         -s|-solr.home)
 1648             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1649               print_usage "$SCRIPT_CMD" "Solr home directory is required when using the $1 option!"
 1650               exit 1
 1651             fi
 1652 
 1653             SOLR_HOME="$2"
 1654             shift 2
 1655         ;;
 1656         -t|-data.home)
 1657             SOLR_DATA_HOME="$2"
 1658             shift 2
 1659         ;;
 1660         -e|-example)
 1661             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1662               print_usage "$SCRIPT_CMD" "Example name is required when using the $1 option!"
 1663               exit 1
 1664             fi
 1665             EXAMPLE="$2"
 1666             shift 2
 1667         ;;
 1668         -f|-foreground)
 1669             FG="true"
 1670             shift
 1671         ;;
 1672         -h|-host)
 1673             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1674               print_usage "$SCRIPT_CMD" "Hostname is required when using the $1 option!"
 1675               exit 1
 1676             fi
 1677             SOLR_HOST="$2"
 1678             PASS_TO_RUN_EXAMPLE+=" -h $SOLR_HOST"
 1679             shift 2
 1680         ;;
 1681         -m|-memory)
 1682             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1683               print_usage "$SCRIPT_CMD" "Memory setting is required when using the $1 option!"
 1684               exit 1
 1685             fi
 1686             SOLR_HEAP="$2"
 1687             PASS_TO_RUN_EXAMPLE+=" -m $SOLR_HEAP"
 1688             shift 2
 1689         ;;
 1690         -p|-port)
 1691             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1692               print_usage "$SCRIPT_CMD" "Port number is required when using the $1 option!"
 1693               exit 1
 1694             fi
 1695             SOLR_PORT="$2"
 1696             PASS_TO_RUN_EXAMPLE+=" -p $SOLR_PORT"
 1697             shift 2
 1698         ;;
 1699         -z|-zkhost)
 1700             if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
 1701               print_usage "$SCRIPT_CMD" "Zookeeper connection string is required when using the $1 option!"
 1702               exit 1
 1703             fi
 1704             ZK_HOST="$2"
 1705             SOLR_MODE="solrcloud"
 1706             PASS_TO_RUN_EXAMPLE+=" -z $ZK_HOST"
 1707             shift 2
 1708         ;;
 1709         -a|-addlopts)
 1710             ADDITIONAL_CMD_OPTS="$2"
 1711             PASS_TO_RUN_EXAMPLE+=" -a \"$ADDITIONAL_CMD_OPTS\""
 1712             shift 2
 1713         ;;
 1714         -j|-jettyconfig)
 1715             ADDITIONAL_JETTY_CONFIG="$2"
 1716             PASS_TO_RUN_EXAMPLE+=" -j \"$ADDITIONAL_JETTY_CONFIG\""
 1717             shift 2
 1718         ;;
 1719         -k|-key)
 1720             STOP_KEY="$2"
 1721             shift 2
 1722         ;;
 1723         -help|-usage)
 1724             print_usage "$SCRIPT_CMD"
 1725             exit 0
 1726         ;;
 1727         -noprompt)
 1728             noprompt=true
 1729             PASS_TO_RUN_EXAMPLE+=" -noprompt"
 1730             shift
 1731         ;;
 1732         -V|-verbose)
 1733             verbose=true
 1734             PASS_TO_RUN_EXAMPLE+=" --verbose"
 1735             shift
 1736         ;;
 1737         -v)
 1738             SOLR_LOG_LEVEL=DEBUG
 1739             shift
 1740         ;;
 1741         -q)
 1742             SOLR_LOG_LEVEL=WARN
 1743             shift
 1744         ;;
 1745         -all)
 1746             stop_all=true
 1747             shift
 1748         ;;
 1749         -force)
 1750             FORCE=true
 1751             PASS_TO_RUN_EXAMPLE+=" -force"
 1752             shift
 1753         ;;
 1754         --)
 1755             shift
 1756             break
 1757         ;;
 1758         *)
 1759             if [ "${1:0:2}" == "-D" ]; then
 1760               # pass thru any opts that begin with -D (java system props)
 1761               SOLR_OPTS+=("$1")
 1762               PASS_TO_RUN_EXAMPLE+=" $1"
 1763               shift
 1764             else
 1765               if [ "$1" != "" ]; then
 1766                 print_usage "$SCRIPT_CMD" "$1 is not supported by this script"
 1767                 exit 1
 1768               else
 1769                 break # out-of-args, stop looping
 1770               fi
 1771             fi
 1772         ;;
 1773     esac
 1774   done
 1775 fi
 1776 
 1777 if [[ $SOLR_LOG_LEVEL ]] ; then
 1778   SOLR_LOG_LEVEL_OPT="-Dsolr.log.level=$SOLR_LOG_LEVEL"
 1779 fi
 1780 
 1781 if [ -z "$SOLR_SERVER_DIR" ]; then
 1782   SOLR_SERVER_DIR="$DEFAULT_SERVER_DIR"
 1783 fi
 1784 
 1785 if [ ! -e "$SOLR_SERVER_DIR" ]; then
 1786   echo -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n"
 1787   exit 1
 1788 fi
 1789 
 1790 if [[ "$FG" == 'true' && "$EXAMPLE" != "" ]]; then
 1791   FG='false'
 1792   echo -e "\nWARNING: Foreground mode (-f) not supported when running examples.\n"
 1793 fi
 1794 
 1795 #
 1796 # If the user specified an example to run, invoke the run_example tool (Java app) and exit
 1797 # otherwise let this script proceed to process the user request
 1798 #
 1799 if [ -n "$EXAMPLE" ] && [ "$SCRIPT_CMD" == "start" ]; then
 1800   run_tool run_example -e $EXAMPLE -d "$SOLR_SERVER_DIR" -urlScheme $SOLR_URL_SCHEME $PASS_TO_RUN_EXAMPLE
 1801   exit $?
 1802 fi
 1803 
 1804 ############# start/stop logic below here ################
 1805 
 1806 if $verbose ; then
 1807   echo "Using Solr root directory: $SOLR_TIP"
 1808   echo "Using Java: $JAVA"
 1809   "$JAVA" -version
 1810 fi
 1811 
 1812 if [ "$SOLR_HOST" != "" ]; then
 1813   SOLR_HOST_ARG=("-Dhost=$SOLR_HOST")
 1814 else
 1815   SOLR_HOST_ARG=()
 1816 fi
 1817 
 1818 if [ -z "$STOP_KEY" ]; then
 1819   STOP_KEY='solrrocks'
 1820 fi
 1821 
 1822 # stop all if no port specified
 1823 if [[ "$SCRIPT_CMD" == "stop" && -z "$SOLR_PORT" ]]; then
 1824   if $stop_all; then
 1825     none_stopped=true
 1826     find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | while read PIDF
 1827       do
 1828         NEXT_PID=`cat "$PIDF"`
 1829         port=`jetty_port "$NEXT_PID"`
 1830         if [ "$port" != "" ]; then
 1831           stop_solr "$SOLR_SERVER_DIR" "$port" "$STOP_KEY" "$NEXT_PID"
 1832           none_stopped=false
 1833         fi
 1834         rm -f "$PIDF"
 1835     done
 1836     # TODO: none_stopped doesn't get reflected across the subshell
 1837     # This can be uncommented once we find a clean way out of it
 1838     # if $none_stopped; then
 1839     #   echo -e "\nNo Solr nodes found to stop.\n"
 1840     # fi
 1841   else
 1842     # not stopping all and don't have a port, but if we can find the pid file for the default port 8983, then use that
 1843     none_stopped=true
 1844     numSolrs=`find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' '`
 1845     if [ $numSolrs -eq 1 ]; then
 1846       # only do this if there is only 1 node running, otherwise they must provide the -p or -all
 1847       PID="$(cat "$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)")"
 1848       CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $PID | sort -r | tr -d ' '`
 1849       if [ "$CHECK_PID" != "" ]; then
 1850         port=`jetty_port "$CHECK_PID"`
 1851         if [ "$port" != "" ]; then
 1852           stop_solr "$SOLR_SERVER_DIR" "$port" "$STOP_KEY" "$CHECK_PID"
 1853           none_stopped=false
 1854         fi
 1855       fi
 1856     fi
 1857 
 1858     if $none_stopped; then
 1859       if [ $numSolrs -gt 0 ]; then
 1860         echo -e "\nFound $numSolrs Solr nodes running! Must either specify a port using -p or -all to stop all Solr nodes on this host.\n"
 1861       else
 1862         echo -e "\nNo Solr nodes found to stop.\n"
 1863       fi
 1864       exit 1
 1865     fi
 1866   fi
 1867   exit
 1868 fi
 1869 
 1870 if [ -z "$SOLR_PORT" ]; then
 1871   SOLR_PORT=8983
 1872 fi
 1873 
 1874 if [ -z "$STOP_PORT" ]; then
 1875   STOP_PORT=`expr $SOLR_PORT - 1000`
 1876 fi
 1877 
 1878 if [ "$SCRIPT_CMD" == "start" ] || [ "$SCRIPT_CMD" == "restart" ] ; then
 1879   if [[ $EUID -eq 0 ]] && [[ "$FORCE" == "false" ]] ; then
 1880     echo "WARNING: Starting Solr as the root user is a security risk and not considered best practice. Exiting."
 1881     echo "         Please consult the Reference Guide. To override this check, start with argument '-force'"
 1882     exit 1
 1883   fi
 1884 fi
 1885 
 1886 if [[ "$SCRIPT_CMD" == "start" ]]; then
 1887   # see if Solr is already running
 1888   SOLR_PID=`solr_pid_by_port "$SOLR_PORT"`
 1889 
 1890   if [ -z "$SOLR_PID" ]; then
 1891     # not found using the pid file ... but use ps to ensure not found
 1892     SOLR_PID=`ps auxww | grep start\.jar | grep -w "\-Djetty\.port=$SOLR_PORT" | grep -v grep | awk '{print $2}' | sort -r`
 1893   fi
 1894 
 1895   if [ "$SOLR_PID" != "" ]; then
 1896     echo -e "\nPort $SOLR_PORT is already being used by another process (pid: $SOLR_PID)\nPlease choose a different port using the -p option.\n"
 1897     exit 1
 1898   fi
 1899 else
 1900   # either stop or restart
 1901   # see if Solr is already running
 1902   SOLR_PID=`solr_pid_by_port "$SOLR_PORT"`
 1903   if [ -z "$SOLR_PID" ]; then
 1904     # not found using the pid file ... but use ps to ensure not found
 1905     SOLR_PID=`ps auxww | grep start\.jar | grep -w "\-Djetty\.port=$SOLR_PORT" | grep -v grep | awk '{print $2}' | sort -r`
 1906   fi
 1907   if [ "$SOLR_PID" != "" ]; then
 1908     stop_solr "$SOLR_SERVER_DIR" "$SOLR_PORT" "$STOP_KEY" "$SOLR_PID"
 1909   else
 1910     if [ "$SCRIPT_CMD" == "stop" ]; then
 1911       echo -e "No process found for Solr node running on port $SOLR_PORT"
 1912       exit 1
 1913     fi
 1914   fi
 1915 fi
 1916 
 1917 if [ -z "$SOLR_HOME" ]; then
 1918   SOLR_HOME="$SOLR_SERVER_DIR/solr"
 1919 elif [[ $SOLR_HOME != /* ]]; then
 1920   if [[ -d "`pwd`/$SOLR_HOME" ]]; then
 1921     SOLR_HOME="$(pwd)/$SOLR_HOME"
 1922   elif [[ -d "$SOLR_SERVER_DIR/$SOLR_HOME" ]]; then
 1923     SOLR_HOME="$SOLR_SERVER_DIR/$SOLR_HOME"
 1924     SOLR_PID_DIR="$SOLR_HOME"
 1925   fi
 1926 fi
 1927 
 1928 # Set the default configset dir to be bootstrapped as _default
 1929 if [ -z "$DEFAULT_CONFDIR" ]; then
 1930   DEFAULT_CONFDIR="$SOLR_SERVER_DIR/solr/configsets/_default/conf"
 1931 fi
 1932 
 1933 # This is quite hacky, but examples rely on a different log4j2.xml
 1934 # so that we can write logs for examples to $SOLR_HOME/../logs
 1935 if [ -z "$SOLR_LOGS_DIR" ]; then
 1936   SOLR_LOGS_DIR="$SOLR_SERVER_DIR/logs"
 1937 fi
 1938 EXAMPLE_DIR="$SOLR_TIP/example"
 1939 if [ "${SOLR_HOME:0:${#EXAMPLE_DIR}}" = "$EXAMPLE_DIR" ]; then
 1940   LOG4J_PROPS="$DEFAULT_SERVER_DIR/resources/log4j2.xml"
 1941   SOLR_LOGS_DIR="$SOLR_HOME/../logs"
 1942 fi
 1943 
 1944 LOG4J_CONFIG=()
 1945 if [ -n "$LOG4J_PROPS" ]; then
 1946   LOG4J_CONFIG+=("-Dlog4j.configurationFile=file:$LOG4J_PROPS")
 1947 fi
 1948 
 1949 if [ "$SCRIPT_CMD" == "stop" ]; then
 1950   # already stopped, script is done.
 1951   exit 0
 1952 fi
 1953 
 1954 # NOTE: If the script gets to here, then it is starting up a Solr node.
 1955 
 1956 if [ ! -e "$SOLR_HOME" ]; then
 1957   echo -e "\nSolr home directory $SOLR_HOME not found!\n"
 1958   exit 1
 1959 fi
 1960 if [[ $SOLR_DATA_HOME ]] && [ ! -e "$SOLR_DATA_HOME" ]; then
 1961   echo -e "\nSolr data home directory $SOLR_DATA_HOME not found!\n"
 1962   exit 1
 1963 fi
 1964 if $verbose ; then
 1965   q=""
 1966 else
 1967   q="-q"
 1968 fi
 1969 # Rotate and clean on startup. Default to false since 7.4 as log4j2 handles startup rotation
 1970 if [ "${SOLR_LOG_PRESTART_ROTATION:=false}" == "true" ]; then
 1971   # Enable any of these if you require old remove/archive behavior
 1972   #run_tool utils -s "$DEFAULT_SERVER_DIR" -l "$SOLR_LOGS_DIR" $q -remove_old_solr_logs 7 || echo "Failed removing old solr logs"
 1973   #run_tool utils -s "$DEFAULT_SERVER_DIR" -l "$SOLR_LOGS_DIR" $q -archive_gc_logs $q     || echo "Failed archiving old GC logs"
 1974   #run_tool utils -s "$DEFAULT_SERVER_DIR" -l "$SOLR_LOGS_DIR" $q -archive_console_logs   || echo "Failed archiving old console logs"
 1975   run_tool utils -s "$DEFAULT_SERVER_DIR" -l "$SOLR_LOGS_DIR" $q -rotate_solr_logs 10    || echo "Failed rotating old solr logs"
 1976 fi
 1977 
 1978 # Establish default GC logging opts if no env var set (otherwise init to sensible default)
 1979 if [ -z ${GC_LOG_OPTS+x} ]; then
 1980   if [[ "$JAVA_VER_NUM" -lt "9" ]] ; then
 1981     GC_LOG_OPTS=('-verbose:gc' '-XX:+PrintHeapAtGC' '-XX:+PrintGCDetails' \
 1982                  '-XX:+PrintGCDateStamps' '-XX:+PrintGCTimeStamps' '-XX:+PrintTenuringDistribution' \
 1983                  '-XX:+PrintGCApplicationStoppedTime')
 1984   else
 1985     GC_LOG_OPTS=('-Xlog:gc*')
 1986   fi
 1987 else
 1988   GC_LOG_OPTS=($GC_LOG_OPTS)
 1989 fi
 1990 
 1991 # if verbose gc logging enabled, setup the location of the log file and rotation
 1992 if [ "$GC_LOG_OPTS" != "" ]; then
 1993   if [[ "$JAVA_VER_NUM" -lt "9" ]] ; then
 1994     gc_log_flag="-Xloggc"
 1995     if [ "$JAVA_VENDOR" == "IBM J9" ]; then
 1996       gc_log_flag="-Xverbosegclog"
 1997     fi
 1998     GC_LOG_OPTS+=("$gc_log_flag:$SOLR_LOGS_DIR/solr_gc.log" '-XX:+UseGCLogFileRotation' '-XX:NumberOfGCLogFiles=9' '-XX:GCLogFileSize=20M')
 1999   else
 2000     # http://openjdk.java.net/jeps/158
 2001     for i in "${!GC_LOG_OPTS[@]}";
 2002     do
 2003       # for simplicity, we only look at the prefix '-Xlog:gc'
 2004       # (if 'all' or multiple tags are used starting with anything other then 'gc' the user is on their own)
 2005       # if a single additional ':' exists in param, then there is already an explicit output specifier
 2006       GC_LOG_OPTS[$i]=$(echo ${GC_LOG_OPTS[$i]} | sed "s|^\(-Xlog:gc[^:]*$\)|\1:file=$SOLR_LOGS_DIR/solr_gc.log:time,uptime:filecount=9,filesize=20M|")
 2007     done
 2008   fi
 2009 fi
 2010 
 2011 # If ZK_HOST is defined, the assume SolrCloud mode
 2012 if [[ -n "$ZK_HOST" ]]; then
 2013   SOLR_MODE="solrcloud"
 2014 fi
 2015 
 2016 if [ "$SOLR_MODE" == 'solrcloud' ]; then
 2017   if [ -z "$ZK_CLIENT_TIMEOUT" ]; then
 2018     ZK_CLIENT_TIMEOUT="15000"
 2019   fi
 2020 
 2021   CLOUD_MODE_OPTS=("-DzkClientTimeout=$ZK_CLIENT_TIMEOUT")
 2022 
 2023   if [ "$ZK_HOST" != "" ]; then
 2024     CLOUD_MODE_OPTS+=("-DzkHost=$ZK_HOST")
 2025   else
 2026     if $verbose ; then
 2027       echo "Configuring SolrCloud to launch an embedded Zookeeper using -DzkRun"
 2028     fi
 2029 
 2030     CLOUD_MODE_OPTS+=('-DzkRun')
 2031   fi
 2032 
 2033   # and if collection1 needs to be bootstrapped
 2034   if [ -e "$SOLR_HOME/collection1/core.properties" ]; then
 2035     CLOUD_MODE_OPTS+=('-Dbootstrap_confdir=./solr/collection1/conf' '-Dcollection.configName=myconf' '-DnumShards=1')
 2036   fi
 2037 
 2038 else
 2039   if [ ! -e "$SOLR_HOME/solr.xml" ]; then
 2040     echo -e "\nSolr home directory $SOLR_HOME must contain a solr.xml file!\n"
 2041     exit 1
 2042   fi
 2043 fi
 2044 
 2045 # These are useful for attaching remote profilers like VisualVM/JConsole
 2046 if [ "$ENABLE_REMOTE_JMX_OPTS" == "true" ]; then
 2047 
 2048   if [ -z "$RMI_PORT" ]; then
 2049     RMI_PORT=`expr $SOLR_PORT + 10000`
 2050     if [ $RMI_PORT -gt 65535 ]; then
 2051       echo -e "\nRMI_PORT is $RMI_PORT, which is invalid!\n"
 2052       exit 1
 2053     fi
 2054   fi
 2055 
 2056   REMOTE_JMX_OPTS=('-Dcom.sun.management.jmxremote' \
 2057     '-Dcom.sun.management.jmxremote.local.only=false' \
 2058     '-Dcom.sun.management.jmxremote.ssl=false' \
 2059     '-Dcom.sun.management.jmxremote.authenticate=false' \
 2060     "-Dcom.sun.management.jmxremote.port=$RMI_PORT" \
 2061     "-Dcom.sun.management.jmxremote.rmi.port=$RMI_PORT")
 2062 
 2063   # if the host is set, then set that as the rmi server hostname
 2064   if [ "$SOLR_HOST" != "" ]; then
 2065     REMOTE_JMX_OPTS+=("-Djava.rmi.server.hostname=$SOLR_HOST")
 2066   fi
 2067 else
 2068   REMOTE_JMX_OPTS=()
 2069 fi
 2070 
 2071 JAVA_MEM_OPTS=()
 2072 if [ -z "$SOLR_HEAP" ] && [ -n "$SOLR_JAVA_MEM" ]; then
 2073   JAVA_MEM_OPTS=($SOLR_JAVA_MEM)
 2074 else
 2075   SOLR_HEAP="${SOLR_HEAP:-512m}"
 2076   JAVA_MEM_OPTS=("-Xms$SOLR_HEAP" "-Xmx$SOLR_HEAP")
 2077 fi
 2078 
 2079 # Pick default for Java thread stack size, and then add to SOLR_OPTS
 2080 if [ -z ${SOLR_JAVA_STACK_SIZE+x} ]; then
 2081   SOLR_JAVA_STACK_SIZE='-Xss256k'
 2082 fi
 2083 SOLR_OPTS+=($SOLR_JAVA_STACK_SIZE)
 2084 
 2085 if [ -z "$SOLR_TIMEZONE" ]; then
 2086   SOLR_TIMEZONE='UTC'
 2087 fi
 2088 
 2089 # Launches Solr in foreground/background depending on parameters
 2090 function start_solr() {
 2091 
 2092   run_in_foreground="$1"
 2093   stop_port="$STOP_PORT"
 2094 
 2095   SOLR_ADDL_ARGS="$2"
 2096   SOLR_JETTY_ADDL_CONFIG="$3"
 2097 
 2098   # define default GC_TUNE
 2099   if [ -z ${GC_TUNE+x} ]; then
 2100       GC_TUNE=('-XX:+UseG1GC' \
 2101         '-XX:+PerfDisableSharedMem' \
 2102         '-XX:+ParallelRefProcEnabled' \
 2103         '-XX:MaxGCPauseMillis=250' \
 2104         '-XX:+UseLargePages' \
 2105         '-XX:+AlwaysPreTouch')
 2106   else
 2107     GC_TUNE=($GC_TUNE)
 2108   fi
 2109 
 2110   if [ -n "$SOLR_WAIT_FOR_ZK" ]; then
 2111     WAIT_FOR_ZK_PROP="-DwaitForZk=$SOLR_WAIT_FOR_ZK"
 2112     SOLR_OPTS+=($WAIT_FOR_ZK_PROP)
 2113   fi
 2114 
 2115   # If SSL-related system props are set, add them to SOLR_OPTS
 2116   if [ "$SOLR_SSL_ENABLED" ]; then
 2117     # If using SSL and solr.jetty.https.port not set explicitly, use the jetty.port
 2118     SSL_PORT_PROP="-Dsolr.jetty.https.port=$SOLR_PORT"
 2119     SOLR_OPTS+=($SOLR_SSL_OPTS "$SSL_PORT_PROP")
 2120   fi
 2121 
 2122   # If authentication system props are set, add them to SOLR_OPTS
 2123   if [ -n "$AUTHC_OPTS" ]; then
 2124     SOLR_OPTS+=($AUTHC_OPTS)
 2125   fi
 2126 
 2127   if $verbose ; then
 2128     echo -e "\nStarting Solr using the following settings:"
 2129     echo -e "    JAVA            = $JAVA"
 2130     echo -e "    SOLR_SERVER_DIR = $SOLR_SERVER_DIR"
 2131     echo -e "    SOLR_HOME       = $SOLR_HOME"
 2132     echo -e "    SOLR_HOST       = $SOLR_HOST"
 2133     echo -e "    SOLR_PORT       = $SOLR_PORT"
 2134     echo -e "    STOP_PORT       = $STOP_PORT"
 2135     echo -e "    JAVA_MEM_OPTS   = ${JAVA_MEM_OPTS[@]}"
 2136     echo -e "    GC_TUNE         = ${GC_TUNE[@]}"
 2137     echo -e "    GC_LOG_OPTS     = ${GC_LOG_OPTS[@]}"
 2138     echo -e "    SOLR_TIMEZONE   = $SOLR_TIMEZONE"
 2139 
 2140     if [ "$SOLR_MODE" == "solrcloud" ]; then
 2141       echo -e "    CLOUD_MODE_OPTS = ${CLOUD_MODE_OPTS[@]}"
 2142     fi
 2143 
 2144     if [ "$SOLR_OPTS" != "" ]; then
 2145       echo -e "    SOLR_OPTS       = ${SOLR_OPTS[@]}"
 2146     fi
 2147 
 2148     if [ "$SOLR_ADDL_ARGS" != "" ]; then
 2149       echo -e "    SOLR_ADDL_ARGS  = $SOLR_ADDL_ARGS"
 2150     fi
 2151 
 2152     if [ "$ENABLE_REMOTE_JMX_OPTS" == "true" ]; then
 2153       echo -e "    RMI_PORT        = $RMI_PORT"
 2154       echo -e "    REMOTE_JMX_OPTS = ${REMOTE_JMX_OPTS[@]}"
 2155     fi
 2156 
 2157     if [ "$SOLR_LOG_LEVEL" != "" ]; then
 2158       echo -e "    SOLR_LOG_LEVEL  = $SOLR_LOG_LEVEL"
 2159     fi
 2160 
 2161     if [ "$SOLR_DATA_HOME" != "" ]; then
 2162       echo -e "    SOLR_DATA_HOME  = $SOLR_DATA_HOME"
 2163     fi
 2164     echo -e "\n"
 2165   fi
 2166 
 2167   # need to launch solr from the server dir
 2168   cd "$SOLR_SERVER_DIR"
 2169 
 2170   if [ ! -e "$SOLR_SERVER_DIR/start.jar" ]; then
 2171     echo -e "\nERROR: start.jar file not found in $SOLR_SERVER_DIR!\nPlease check your -d parameter to set the correct Solr server directory.\n"
 2172     exit 1
 2173   fi
 2174 
 2175   SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE[@]}" "${GC_LOG_OPTS[@]}" \
 2176     "${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" $SOLR_LOG_LEVEL_OPT -Dsolr.log.dir="$SOLR_LOGS_DIR" \
 2177     "-Djetty.port=$SOLR_PORT" "-DSTOP.PORT=$stop_port" "-DSTOP.KEY=$STOP_KEY" \
 2178     "${SOLR_HOST_ARG[@]}" "-Duser.timezone=$SOLR_TIMEZONE" \
 2179     "-Djetty.home=$SOLR_SERVER_DIR" "-Dsolr.solr.home=$SOLR_HOME" "-Dsolr.data.home=$SOLR_DATA_HOME" "-Dsolr.install.dir=$SOLR_TIP" \
 2180     "-Dsolr.default.confdir=$DEFAULT_CONFDIR" "${LOG4J_CONFIG[@]}" "${SOLR_OPTS[@]}")
 2181 
 2182   if [ "$SOLR_MODE" == "solrcloud" ]; then
 2183     IN_CLOUD_MODE=" in SolrCloud mode"
 2184   fi
 2185 
 2186   mkdir -p "$SOLR_LOGS_DIR" 2>/dev/null
 2187   if [ $? -ne 0 ]; then
 2188     echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR could not be created. Exiting"
 2189     exit 1
 2190   fi
 2191   if [ ! -w "$SOLR_LOGS_DIR" ]; then
 2192     echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR is not writable. Exiting"
 2193     exit 1
 2194   fi
 2195   case "$SOLR_LOGS_DIR" in
 2196     contexts|etc|lib|modules|resources|scripts|solr|solr-webapp)
 2197       echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR is invalid. Reserved for the system. Exiting"
 2198       exit 1
 2199       ;;
 2200   esac
 2201 
 2202   if [ "$run_in_foreground" == "true" ]; then
 2203     exec "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -jar start.jar "${SOLR_JETTY_CONFIG[@]}" $SOLR_JETTY_ADDL_CONFIG
 2204   else
 2205     # run Solr in the background
 2206     nohup "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -Dsolr.log.muteconsole \
 2207     "-XX:OnOutOfMemoryError=$SOLR_TIP/bin/oom_solr.sh $SOLR_PORT $SOLR_LOGS_DIR" \
 2208         -jar start.jar "${SOLR_JETTY_CONFIG[@]}" $SOLR_JETTY_ADDL_CONFIG \
 2209     1>"$SOLR_LOGS_DIR/solr-$SOLR_PORT-console.log" 2>&1 & echo $! > "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
 2210 
 2211     # check if /proc/sys/kernel/random/entropy_avail exists then check output of cat /proc/sys/kernel/random/entropy_avail to see if less than 300
 2212     if [[ -f /proc/sys/kernel/random/entropy_avail ]] && (( `cat /proc/sys/kernel/random/entropy_avail` < 300)); then
 2213     echo "Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require"
 2214     echo "RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'."
 2215     echo ""
 2216     fi
 2217     # no lsof on cygwin though
 2218     if hash lsof 2>/dev/null ; then  # hash returns true if lsof is on the path
 2219       echo -n "Waiting up to $SOLR_STOP_WAIT seconds to see Solr running on port $SOLR_PORT"
 2220       # Launch in a subshell to show the spinner
 2221       (loops=0
 2222       while true
 2223       do
 2224         running=`lsof -PniTCP:$SOLR_PORT -sTCP:LISTEN`
 2225         if [ -z "$running" ]; then
 2226       slept=$((loops * 2))
 2227           if [ $slept -lt $SOLR_STOP_WAIT ]; then
 2228             sleep 2
 2229             loops=$[$loops+1]
 2230           else
 2231             echo -e "Still not seeing Solr listening on $SOLR_PORT after $SOLR_STOP_WAIT seconds!"
 2232             tail -30 "$SOLR_LOGS_DIR/solr.log"
 2233             exit # subshell!
 2234           fi
 2235         else
 2236           SOLR_PID=`ps auxww | grep start\.jar | grep -w "\-Djetty\.port=$SOLR_PORT" | grep -v grep | awk '{print $2}' | sort -r`
 2237           echo -e "\nStarted Solr server on port $SOLR_PORT (pid=$SOLR_PID). Happy searching!\n"
 2238           exit # subshell!
 2239         fi
 2240       done) &
 2241       spinner $!
 2242     else
 2243       echo -e "NOTE: Please install lsof as this script needs it to determine if Solr is listening on port $SOLR_PORT."
 2244       sleep 10
 2245       SOLR_PID=`ps auxww | grep start\.jar | grep -w "\-Djetty\.port=$SOLR_PORT" | grep -v grep | awk '{print $2}' | sort -r`
 2246       echo -e "\nStarted Solr server on port $SOLR_PORT (pid=$SOLR_PID). Happy searching!\n"
 2247       return;
 2248     fi
 2249   fi
 2250 }
 2251 
 2252 start_solr "$FG" "$ADDITIONAL_CMD_OPTS" "$ADDITIONAL_JETTY_CONFIG"
 2253 
 2254 exit $?