2014-08-06 12:30:01 -04:00
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# CONTROLLING STARTUP:
#
# Use solr -help to see available command-line options. In addition
# to passing command-line options, this script looks for an include
# file named solr.in.sh to set environment variables. Specifically,
2014-12-23 18:20:42 -05:00
# the following locations are searched in this order:
2014-08-06 12:30:01 -04:00
#
# ./
# $HOME/.solr.in.sh
# /usr/share/solr
# /usr/local/share/solr
2014-12-23 18:20:42 -05:00
# /var/solr/
2014-08-06 12:30:01 -04:00
# /opt/solr
#
# Another option is to specify the full path to the include file in the
# environment. For example:
#
# $ SOLR_INCLUDE=/path/to/solr.in.sh solr start
#
# Note: This is particularly handy for running multiple instances on a
# single installation, or for quick tests.
#
# Finally, developers and enthusiasts who frequently run from an SVN
# checkout, and do not want to locally modify bin/solr.in.sh, can put
# a customized include file at ~/.solr.in.sh.
#
# If you would rather configure startup entirely from the environment, you
# can disable the include by exporting an empty SOLR_INCLUDE, or by
# ensuring that no include files exist in the aforementioned search list.
SOLR_SCRIPT="$0"
verbose=false
2014-08-19 22:56:18 -04:00
THIS_OS=`uname -s`
2015-01-22 12:13:20 -05:00
2014-10-09 18:28:05 -04:00
stop_all=false
2014-09-05 12:30:23 -04:00
2014-08-19 22:56:18 -04:00
# for now, we don't support running this script from cygwin due to problems
2014-11-26 11:45:01 -05:00
# like not having lsof, ps auxww, curl, and awkward directory handling
2014-08-19 22:56:18 -04:00
if [ "${THIS_OS:0:6}" == "CYGWIN" ]; then
echo -e "This script does not support cygwin due to severe limitations and lack of adherence\nto BASH standards, such as lack of lsof, curl, and ps options.\n\nPlease use the native solr.cmd script on Windows!"
exit 1
fi
2014-08-06 12:30:01 -04:00
# Resolve symlinks to this script
while [ -h "$SOLR_SCRIPT" ] ; do
ls=`ls -ld "$SOLR_SCRIPT"`
# Drop everything prior to ->
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SOLR_SCRIPT="$link"
else
SOLR_SCRIPT=`dirname "$SOLR_SCRIPT"`/"$link"
fi
done
SOLR_TIP=`dirname "$SOLR_SCRIPT"`/..
SOLR_TIP=`cd "$SOLR_TIP"; pwd`
2015-03-27 13:25:05 -04:00
DEFAULT_SERVER_DIR="$SOLR_TIP/server"
2014-08-06 12:30:01 -04:00
2014-10-09 14:42:21 -04:00
# If an include wasn't specified in the environment, then search for one...
2014-12-23 18:20:42 -05:00
if [ -z "$SOLR_INCLUDE" ]; then
# Locations (in order) to use when searching for an include file.
for include in "`dirname "$0"`/solr.in.sh" \
"$HOME/.solr.in.sh" \
/usr/share/solr/solr.in.sh \
/usr/local/share/solr/solr.in.sh \
2015-11-25 13:40:03 -05:00
/etc/default/solr.in.sh \
2014-12-23 18:20:42 -05:00
/opt/solr/solr.in.sh; do
if [ -r "$include" ]; then
. "$include"
break
fi
done
2014-10-09 14:42:21 -04:00
elif [ -r "$SOLR_INCLUDE" ]; then
2014-12-23 18:20:42 -05:00
. "$SOLR_INCLUDE"
fi
if [ -z "$SOLR_PID_DIR" ]; then
2015-03-27 13:25:05 -04:00
SOLR_PID_DIR="$SOLR_TIP/bin"
2014-10-09 14:42:21 -04:00
fi
2014-12-23 18:20:42 -05:00
if [ -n "$SOLR_JAVA_HOME" ]; then
2015-03-27 13:25:05 -04:00
JAVA="$SOLR_JAVA_HOME/bin/java"
2014-08-06 12:30:01 -04:00
elif [ -n "$JAVA_HOME" ]; then
for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
if [ -x "$java" ]; then
JAVA="$java"
break
fi
done
2015-01-23 19:02:25 -05:00
if [ -z "$JAVA" ]; then
echo >&2 "The currently defined JAVA_HOME ($JAVA_HOME) refers"
echo >&2 "to a location where Java could not be found. Aborting."
echo >&2 "Either fix the JAVA_HOME variable or remove it from the"
echo >&2 "environment so that the system PATH will be searched."
exit 1
fi
2014-08-06 12:30:01 -04:00
else
JAVA=java
fi
# test that Java exists and is executable on this server
2015-03-27 13:25:05 -04:00
"$JAVA" -version >/dev/null 2>&1 || {
2015-01-23 19:02:25 -05:00
echo >&2 "Java not found, or an error was encountered when running java."
echo >&2 "A working Java 8 is required to run Solr!"
echo >&2 "Please install Java 8 or fix JAVA_HOME before running this script."
echo >&2 "Command that we tried: '${JAVA} -version'"
echo >&2 "Active Path:"
echo >&2 "${PATH}"
exit 1
}
2014-08-06 12:30:01 -04:00
2015-04-26 08:44:20 -04:00
# Select HTTP OR HTTPS related configurations
2015-01-15 13:24:48 -05:00
SOLR_URL_SCHEME=http
2015-04-23 10:17:35 -04:00
SOLR_JETTY_CONFIG=()
2015-04-26 08:44:20 -04:00
SOLR_SSL_OPTS=""
if [ -n "$SOLR_SSL_KEY_STORE" ]; then
2015-04-23 10:17:35 -04:00
SOLR_JETTY_CONFIG+=("--module=https")
2015-04-26 08:44:20 -04:00
SOLR_URL_SCHEME=https
SOLR_SSL_OPTS=" -Dsolr.jetty.keystore=$SOLR_SSL_KEY_STORE \
-Dsolr.jetty.keystore.password=$SOLR_SSL_KEY_STORE_PASSWORD \
-Dsolr.jetty.truststore=$SOLR_SSL_TRUST_STORE \
-Dsolr.jetty.truststore.password=$SOLR_SSL_TRUST_STORE_PASSWORD \
-Dsolr.jetty.ssl.needClientAuth=$SOLR_SSL_NEED_CLIENT_AUTH \
-Dsolr.jetty.ssl.wantClientAuth=$SOLR_SSL_WANT_CLIENT_AUTH"
if [ -n "$SOLR_SSL_CLIENT_KEY_STORE" ]; then
SOLR_SSL_OPTS+=" -Djavax.net.ssl.keyStore=$SOLR_SSL_CLIENT_KEY_STORE \
-Djavax.net.ssl.keyStorePassword=$SOLR_SSL_CLIENT_KEY_STORE_PASSWORD \
-Djavax.net.ssl.trustStore=$SOLR_SSL_CLIENT_TRUST_STORE \
-Djavax.net.ssl.trustStorePassword=$SOLR_SSL_CLIENT_TRUST_STORE_PASSWORD"
else
SOLR_SSL_OPTS+=" -Djavax.net.ssl.keyStore=$SOLR_SSL_KEY_STORE \
-Djavax.net.ssl.keyStorePassword=$SOLR_SSL_KEY_STORE_PASSWORD \
-Djavax.net.ssl.trustStore=$SOLR_SSL_TRUST_STORE \
-Djavax.net.ssl.trustStorePassword=$SOLR_SSL_TRUST_STORE_PASSWORD"
fi
2015-04-23 10:17:35 -04:00
else
SOLR_JETTY_CONFIG+=("--module=http")
fi
2015-05-19 17:10:16 -04:00
# Authentication options
if [ "$SOLR_AUTHENTICATION_CLIENT_CONFIGURER" != "" ]; then
AUTHC_CLIENT_CONFIGURER_ARG="-Dsolr.authentication.httpclient.configurer=$SOLR_AUTHENTICATION_CLIENT_CONFIGURER"
fi
AUTHC_OPTS="$AUTHC_CLIENT_CONFIGURER_ARG $SOLR_AUTHENTICATION_OPTS"
2015-05-17 17:07:52 -04:00
# Set the SOLR_TOOL_HOST variable for use when connecting to a running Solr instance
if [ "$SOLR_HOST" != "" ]; then
SOLR_TOOL_HOST="$SOLR_HOST"
else
SOLR_TOOL_HOST="localhost"
fi
2014-08-06 12:30:01 -04:00
function print_usage() {
CMD="$1"
ERROR_MSG="$2"
if [ "$ERROR_MSG" != "" ]; then
2014-08-19 22:56:18 -04:00
echo -e "\nERROR: $ERROR_MSG\n"
2014-08-06 12:30:01 -04:00
fi
2014-12-23 18:20:42 -05:00
if [ -z "$CMD" ]; then
2014-08-06 12:30:01 -04:00
echo ""
echo "Usage: solr COMMAND OPTIONS"
2015-12-10 10:32:33 -05:00
echo " where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk"
2014-08-06 12:30:01 -04:00
echo ""
2014-10-09 14:42:21 -04:00
echo " Standalone server example (start Solr running in the background on port 8984):"
2014-08-06 12:30:01 -04:00
echo ""
echo " ./solr start -p 8984"
echo ""
2015-12-10 10:32:33 -05:00
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):"
2014-10-09 14:42:21 -04:00
echo ""
echo " ./solr start -c -m 1g -z localhost:2181 -a \"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044\""
echo ""
2014-08-06 12:30:01 -04:00
echo "Pass -help after any COMMAND to see command-specific usage information,"
2014-10-09 14:42:21 -04:00
echo " such as: ./solr start -help or ./solr stop -help"
2014-08-06 12:30:01 -04:00
echo ""
elif [[ "$CMD" == "start" || "$CMD" == "restart" ]]; then
echo ""
2014-10-09 14:42:21 -04:00
echo "Usage: solr $CMD [-f] [-c] [-h hostname] [-p port] [-d directory] [-z zkHost] [-m memory] [-e example] [-s solr.solr.home] [-a \"additional-options\"] [-V]"
2014-08-06 12:30:01 -04:00
echo ""
echo " -f Start Solr in foreground; default starts Solr in the background"
echo " and sends stdout / stderr to solr-PORT-console.log"
echo ""
2015-12-10 10:32:33 -05:00
echo " -c or -cloud Start Solr in SolrCloud mode; if -z not supplied, an embedded Zookeeper"
2014-08-06 12:30:01 -04:00
echo " instance is started on Solr port+1000, such as 9983 if Solr is bound to 8983"
echo ""
echo " -h <host> Specify the hostname for this Solr instance"
echo ""
echo " -p <port> Specify the port to start the Solr HTTP listener on; default is 8983"
2014-12-01 14:50:30 -05:00
echo " The specified port (SOLR_PORT) will also be used to determine the stop port"
echo " STOP_PORT=(\$SOLR_PORT-1000) and JMX RMI listen port RMI_PORT=(1\$SOLR_PORT). "
echo " For instance, if you set -p 8985, then the STOP_PORT=7985 and RMI_PORT=18985"
2014-08-06 12:30:01 -04:00
echo ""
echo " -d <dir> Specify the Solr server directory; defaults to server"
echo ""
2015-12-10 10:32:33 -05:00
echo " -z <zkHost> Zookeeper connection string; only used when running in SolrCloud mode using -c"
echo " To launch an embedded Zookeeper instance, don't pass this parameter."
2014-08-06 12:30:01 -04:00
echo ""
echo " -m <memory> Sets the min (-Xms) and max (-Xmx) heap size for the JVM, such as: -m 4g"
echo " results in: -Xms4g -Xmx4g; by default, this script sets the heap size to 512m"
echo ""
2014-10-09 14:42:21 -04:00
echo " -s <dir> Sets the solr.solr.home system property; Solr will create core directories under"
echo " this directory. This allows you to run multiple Solr instances on the same host"
echo " while reusing the same server directory set using the -d parameter. If set, the"
2015-12-10 10:32:33 -05:00
echo " specified directory should contain a solr.xml file, unless solr.xml exists in Zookeeper."
2014-10-09 14:42:21 -04:00
echo " This parameter is ignored when running examples (-e), as the solr.solr.home depends"
2015-07-25 20:15:27 -04:00
echo " on which example is run. The default value is server/solr."
2014-10-09 14:42:21 -04:00
echo ""
2014-08-06 12:30:01 -04:00
echo " -e <example> Name of the example to run; available examples:"
echo " cloud: SolrCloud example"
2014-10-31 00:30:52 -04:00
echo " techproducts: Comprehensive example illustrating many of Solr's core capabilities"
2014-08-06 12:30:01 -04:00
echo " dih: Data Import Handler"
echo " schemaless: Schema-less example"
echo ""
2014-09-22 12:48:32 -04:00
echo " -a Additional parameters to pass to the JVM when starting Solr, such as to setup"
2014-12-01 14:50:30 -05:00
echo " Java debug options. For example, to enable a Java debugger to attach to the Solr JVM"
echo " you could pass: -a \"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=18983\""
echo " In most cases, you should wrap the additional parameters in double quotes."
2014-09-22 12:48:32 -04:00
echo ""
2014-08-06 12:30:01 -04:00
echo " -noprompt Don't prompt for input; accept all defaults when running examples that accept user input"
echo ""
echo " -V Verbose messages from this script"
echo ""
elif [ "$CMD" == "stop" ]; then
echo ""
2014-09-22 12:48:32 -04:00
echo "Usage: solr stop [-k key] [-p port] [-V]"
2014-08-06 12:30:01 -04:00
echo ""
echo " -k <key> Stop key; default is solrrocks"
echo ""
2014-12-02 11:57:06 -05:00
echo " -p <port> Specify the port the Solr HTTP listener is bound to"
2014-08-06 12:30:01 -04:00
echo ""
2014-10-09 18:28:05 -04:00
echo " -all Find and stop all running Solr servers on this host"
echo ""
2014-12-23 18:20:42 -05:00
echo " NOTE: To see if any Solr servers are running, do: solr status"
2014-12-02 11:57:06 -05:00
echo ""
2014-08-06 12:30:01 -04:00
elif [ "$CMD" == "healthcheck" ]; then
echo ""
echo "Usage: solr healthcheck [-c collection] [-z zkHost]"
echo ""
echo " -c <collection> Collection to run healthcheck against."
echo ""
2015-12-10 10:32:33 -05:00
echo " -z <zkHost> Zookeeper connection string; default is localhost:9983"
2014-08-06 12:30:01 -04:00
echo ""
2014-12-23 18:20:42 -05:00
elif [ "$CMD" == "status" ]; then
echo ""
echo "Usage: solr status"
echo ""
echo " NOTE: This command will show the status of all running Solr servers"
echo ""
2015-01-12 18:33:34 -05:00
elif [ "$CMD" == "create" ]; then
echo ""
echo "Usage: solr create [-c name] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]"
echo ""
echo " Create a core or collection depending on whether Solr is running in standalone (core) or SolrCloud"
echo " mode (collection). In other words, this action detects which mode Solr is running in, and then takes"
echo " the appropriate action (either create_core or create_collection). For detailed usage instructions, do:"
echo ""
echo " bin/solr create_core -help"
echo ""
echo " or"
echo ""
echo " bin/solr create_collection -help"
echo ""
2015-01-16 01:36:15 -05:00
elif [ "$CMD" == "delete" ]; then
echo ""
echo "Usage: solr delete [-c name] [-deleteConfig true|false] [-p port]"
echo ""
echo " Deletes a core or collection depending on whether Solr is running in standalone (core) or SolrCloud"
echo " mode (collection). If you're deleting a collection in SolrCloud mode, the default behavior is to also"
2015-12-10 10:32:33 -05:00
echo " delete the configuration directory from Zookeeper so long as it is not being used by another collection."
2015-01-16 01:36:15 -05:00
echo " You can override this behavior by passing -deleteConfig false when running this command."
echo ""
echo " -c <name> Name of the core / collection to delete"
echo ""
2015-12-10 10:32:33 -05:00
echo " -deleteConfig <boolean> Delete the configuration directory from Zookeeper; default is true"
2015-01-16 01:36:15 -05:00
echo ""
echo " -p <port> Port of a local Solr instance where you want to delete the core/collection"
echo " If not specified, the script will search the local system for a running"
echo " Solr instance and will use the port of the first server it finds."
echo ""
2014-10-31 00:30:52 -04:00
elif [ "$CMD" == "create_core" ]; then
echo ""
2015-01-12 18:33:34 -05:00
echo "Usage: solr create_core [-c core] [-d confdir] [-p port]"
2014-10-31 00:30:52 -04:00
echo ""
2015-01-12 18:33:34 -05:00
echo " -c <core> Name of core to create"
echo ""
echo " -d <confdir> Configuration directory to copy when creating the new core, built-in options are:"
2014-10-31 00:30:52 -04:00
echo ""
echo " basic_configs: Minimal Solr configuration"
echo " data_driven_schema_configs: Managed schema with field-guessing support enabled"
echo " sample_techproducts_configs: Example configuration with many optional features enabled to"
echo " demonstrate the full power of Solr"
2015-01-12 18:33:34 -05:00
echo ""
2014-10-31 00:30:52 -04:00
echo " If not specified, default is: data_driven_schema_configs"
echo ""
2014-12-23 23:00:49 -05:00
echo " Alternatively, you can pass the path to your own configuration directory instead of using"
2015-01-12 18:33:34 -05:00
echo " one of the built-in configurations, such as: bin/solr create_core -c mycore -d /tmp/myconfig"
2014-12-23 23:00:49 -05:00
echo ""
2015-01-12 18:33:34 -05:00
echo " -p <port> Port of a local Solr instance where you want to create the new core"
echo " If not specified, the script will search the local system for a running"
echo " Solr instance and will use the port of the first server it finds."
2015-01-11 11:39:11 -05:00
echo ""
2014-10-31 00:30:52 -04:00
elif [ "$CMD" == "create_collection" ]; then
echo ""
2015-01-12 18:33:34 -05:00
echo "Usage: solr create_collection [-c collection] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]"
2014-10-31 00:30:52 -04:00
echo ""
2015-01-12 18:33:34 -05:00
echo " -c <collection> Name of collection to create"
echo ""
echo " -d <confdir> Configuration directory to copy when creating the new collection, built-in options are:"
2014-10-31 00:30:52 -04:00
echo ""
echo " basic_configs: Minimal Solr configuration"
echo " data_driven_schema_configs: Managed schema with field-guessing support enabled"
echo " sample_techproducts_configs: Example configuration with many optional features enabled to"
echo " demonstrate the full power of Solr"
2015-01-12 18:33:34 -05:00
echo ""
2014-10-31 00:30:52 -04:00
echo " If not specified, default is: data_driven_schema_configs"
echo ""
2014-12-23 23:00:49 -05:00
echo " Alternatively, you can pass the path to your own configuration directory instead of using"
2015-01-12 18:33:34 -05:00
echo " one of the built-in configurations, such as: bin/solr create_collection -c mycoll -d /tmp/myconfig"
echo ""
2015-12-10 10:32:33 -05:00
echo " By default the script will upload the specified confdir directory into Zookeeper using the same"
2015-01-12 18:33:34 -05:00
echo " name as the collection (-c) option. Alternatively, if you want to reuse an existing directory"
2015-12-10 10:32:33 -05:00
echo " or create a confdir in Zookeeper that can be shared by multiple collections, use the -n option"
2015-01-12 18:33:34 -05:00
echo ""
2015-12-10 10:32:33 -05:00
echo " -n <configName> Name the configuration directory in Zookeeper; by default, the configuration"
echo " will be uploaded to Zookeeper using the collection name (-c), but if you want"
2015-01-12 18:33:34 -05:00
echo " to use an existing directory or override the name of the configuration in"
2015-12-10 10:32:33 -05:00
echo " Zookeeper, then use the -c option."
2014-12-23 23:00:49 -05:00
echo ""
echo " -shards <#> Number of shards to split the collection into; default is 1"
2014-10-31 00:30:52 -04:00
echo ""
2014-12-23 23:00:49 -05:00
echo " -replicationFactor <#> Number of copies of each document in the collection, default is 1 (no replication)"
2014-10-31 00:30:52 -04:00
echo ""
2015-01-12 18:33:34 -05:00
echo " -p <port> Port of a local Solr instance where you want to create the new collection"
echo " If not specified, the script will search the local system for a running"
echo " Solr instance and will use the port of the first server it finds."
2014-10-31 00:30:52 -04:00
echo ""
2015-12-10 10:32:33 -05:00
elif [ "$CMD" == "zk" ]; then
echo "Usage: solr zk [-upconfig|-downconfig] [-d confdir] [-n configName] [-z zkHost]"
echo ""
echo " -upconfig to move a configset from the local machine to Zookeeper."
echo ""
echo " -downconfig to move a configset from Zookeeper to the local machine."
echo ""
echo " -n configName Name of the configset in Zookeeper that will be the destinatino of"
echo " 'upconfig' and the source for 'downconfig'."
echo ""
echo " -d confdir The local directory the configuration will be uploaded from for"
echo " 'upconfig' or downloaded to for 'downconfig'. For 'upconfig', this"
echo " can be one of the example configsets, basic_configs, data_driven_schema_configs or"
echo " sample_techproducts_configs or an arbitrary directory."
echo ""
echo " -z zkHost Zookeeper connection string."
echo ""
echo " NOTE: Solr must have been started least once (or have it running) before using this command."
echo " This initialized Zookeeper for Solr"
echo ""
2014-08-06 12:30:01 -04:00
fi
} # end print_usage
# used to show the script is still alive when waiting on work to complete
2014-12-23 18:20:42 -05:00
function spinner() {
2014-08-06 12:30:01 -04:00
local pid=$1
local delay=0.5
local spinstr='|/-\'
2015-04-22 18:42:19 -04:00
while [ "$(ps aux | awk '{print $2}' | grep -w $pid)" ]; do
2014-08-06 12:30:01 -04:00
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
2014-10-09 18:28:05 -04:00
# given a port, find the pid for a Solr process
function solr_pid_by_port() {
THE_PORT="$1"
2014-12-23 18:20:42 -05:00
if [ -e "$SOLR_PID_DIR/solr-$THE_PORT.pid" ]; then
2015-03-27 13:25:05 -04:00
PID=`cat "$SOLR_PID_DIR/solr-$THE_PORT.pid"`
2015-04-22 18:42:19 -04:00
CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $PID | sort -r | tr -d ' '`
2014-10-09 18:28:05 -04:00
if [ "$CHECK_PID" != "" ]; then
local solrPID=$PID
fi
fi
echo "$solrPID"
}
2014-08-06 12:30:01 -04:00
# extract the value of the -Djetty.port parameter from a running Solr process
function jetty_port() {
SOLR_PID="$1"
2015-04-22 18:42:19 -04:00
SOLR_PROC=`ps auxww | grep -w $SOLR_PID | grep start\.jar | grep jetty.port`
2014-08-06 12:30:01 -04:00
IFS=' ' read -a proc_args <<< "$SOLR_PROC"
for arg in "${proc_args[@]}"
do
IFS='=' read -a pair <<< "$arg"
if [ "${pair[0]}" == "-Djetty.port" ]; then
local jetty_port="${pair[1]}"
break
fi
done
echo "$jetty_port"
} # end jetty_port func
# run a Solr command-line tool using the SolrCLI class;
# useful for doing cross-platform work from the command-line using Java
function run_tool() {
2015-03-27 13:25:05 -04:00
2015-05-19 17:10:16 -04:00
"$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS -Dsolr.install.dir="$SOLR_TIP" \
2015-03-27 13:25:05 -04:00
-Dlog4j.configuration="file:$DEFAULT_SERVER_DIR/scripts/cloud-scripts/log4j.properties" \
2014-08-06 12:30:01 -04:00
-classpath "$DEFAULT_SERVER_DIR/solr-webapp/webapp/WEB-INF/lib/*:$DEFAULT_SERVER_DIR/lib/ext/*" \
2015-03-27 13:25:05 -04:00
org.apache.solr.util.SolrCLI "$@"
2014-08-06 12:30:01 -04:00
2014-12-23 23:00:49 -05:00
return $?
2014-08-06 12:30:01 -04:00
} # end run_tool function
# get information about any Solr nodes running on this host
function get_info() {
2015-11-25 14:29:09 -05:00
CODE=4
2014-08-06 12:30:01 -04:00
# first, see if Solr is running
2015-03-27 13:25:05 -04:00
numSolrs=`find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' '`
2014-08-06 12:30:01 -04:00
if [ "$numSolrs" != "0" ]; then
echo -e "\nFound $numSolrs Solr nodes: "
2015-11-25 14:29:09 -05:00
while read PIDF
2014-08-06 12:30:01 -04:00
do
2015-03-27 13:25:05 -04:00
ID=`cat "$PIDF"`
2014-08-06 12:30:01 -04:00
port=`jetty_port "$ID"`
if [ "$port" != "" ]; then
2014-12-23 18:20:42 -05:00
echo -e "\nSolr process $ID running on port $port"
2015-05-17 17:07:52 -04:00
run_tool status -solr "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr"
2015-11-25 14:29:09 -05:00
CODE=$?
2014-08-06 12:30:01 -04:00
echo ""
2014-12-23 18:20:42 -05:00
else
echo -e "\nSolr process $ID from $PIDF not found."
2015-11-25 14:29:09 -05:00
CODE=1
2014-12-23 18:20:42 -05:00
fi
2015-11-25 14:29:09 -05:00
done < <(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)
2014-08-06 12:30:01 -04:00
else
2014-10-13 15:23:22 -04:00
# no pid files but check using ps just to be sure
2015-03-10 00:39:51 -04:00
numSolrs=`ps auxww | grep start\.jar | grep solr.solr.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//'`
2014-10-13 15:23:22 -04:00
if [ "$numSolrs" != "0" ]; then
echo -e "\nFound $numSolrs Solr nodes: "
2015-11-25 14:29:09 -05:00
PROCESSES=$(ps auxww | grep start\.jar | grep solr.solr.home | grep -v grep | awk '{print $2}' | sort -r)
for ID in $PROCESSES
2014-10-13 15:23:22 -04:00
do
port=`jetty_port "$ID"`
if [ "$port" != "" ]; then
echo ""
2014-12-02 11:57:06 -05:00
echo "Solr process $ID running on port $port"
2015-05-17 17:07:52 -04:00
run_tool status -solr "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr"
2015-11-25 14:29:09 -05:00
CODE=$?
2014-10-13 15:23:22 -04:00
echo ""
fi
done
else
echo -e "\nNo Solr nodes are running.\n"
2015-11-25 14:29:09 -05:00
CODE=3
2014-10-13 15:23:22 -04:00
fi
2014-08-06 12:30:01 -04:00
fi
2015-11-25 14:29:09 -05:00
return $CODE
2014-08-06 12:30:01 -04:00
} # end get_info
# tries to gracefully stop Solr using the Jetty
# stop command and if that fails, then uses kill -9
function stop_solr() {
DIR="$1"
SOLR_PORT="$2"
2014-10-31 12:56:22 -04:00
STOP_PORT=`expr $SOLR_PORT - 1000`
2014-08-06 12:30:01 -04:00
STOP_KEY="$3"
2014-10-09 18:28:05 -04:00
SOLR_PID="$4"
2014-08-06 12:30:01 -04:00
if [ "$SOLR_PID" != "" ]; then
2014-10-23 17:45:21 -04:00
echo -e "Sending stop command to Solr running on port $SOLR_PORT ... waiting 5 seconds to allow Jetty process $SOLR_PID to stop gracefully."
2015-05-19 17:10:16 -04:00
"$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS -jar "$DIR/start.jar" "STOP.PORT=$STOP_PORT" "STOP.KEY=$STOP_KEY" --stop || true
2014-09-05 12:30:23 -04:00
(sleep 5) &
spinner $!
2015-03-27 13:25:05 -04:00
rm -f "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
2014-08-06 12:30:01 -04:00
else
echo -e "No Solr nodes found to stop."
exit 0
fi
2015-04-22 18:42:19 -04:00
CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
2014-10-09 18:28:05 -04:00
if [ "$CHECK_PID" != "" ]; then
2014-08-06 12:30:01 -04:00
echo -e "Solr process $SOLR_PID is still running; forcefully killing it now."
kill -9 $SOLR_PID
echo "Killed process $SOLR_PID"
2015-03-27 13:25:05 -04:00
rm -f "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
2014-10-09 18:28:05 -04:00
sleep 1
2014-08-06 12:30:01 -04:00
fi
2015-04-22 18:42:19 -04:00
CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
2014-10-09 18:28:05 -04:00
if [ "$CHECK_PID" != "" ]; then
2014-08-06 12:30:01 -04:00
echo "ERROR: Failed to kill previous Solr Java process $SOLR_PID ... script fails."
exit 1
fi
} # end stop_solr
if [ $# -eq 1 ]; then
case $1 in
2015-08-26 08:33:10 -04:00
-help|-usage|-h|--help)
2014-08-06 12:30:01 -04:00
print_usage ""
exit
;;
2014-12-23 18:20:42 -05:00
-info|-i|status)
2014-08-06 12:30:01 -04:00
get_info
2015-11-25 14:29:09 -05:00
exit $?
2014-08-06 12:30:01 -04:00
;;
2015-08-26 08:33:10 -04:00
-version|-v|version)
run_tool version
exit
;;
2014-08-06 12:30:01 -04:00
esac
fi
if [ $# -gt 0 ]; then
# if first arg starts with a dash (and it's not -help or -info),
# then assume they are starting Solr, such as: solr -f
if [[ $1 == -* ]]; then
SCRIPT_CMD="start"
else
2015-03-27 13:25:05 -04:00
SCRIPT_CMD="$1"
2014-08-06 12:30:01 -04:00
shift
fi
else
# no args - just show usage and exit
print_usage ""
exit
fi
2014-12-23 18:20:42 -05:00
if [ "$SCRIPT_CMD" == "status" ]; then
# hacky - the script hits this if the user passes additional args with the status command,
# which is not supported but also not worth complaining about either
get_info
exit
fi
2014-08-06 12:30:01 -04:00
# run a healthcheck and exit if requested
if [ "$SCRIPT_CMD" == "healthcheck" ]; then
if [ $# -gt 0 ]; then
while true; do
2015-03-27 13:25:05 -04:00
case "$1" in
2014-08-06 12:30:01 -04:00
-c|-collection)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Collection name is required when using the $1 option!"
exit 1
2014-08-19 22:56:18 -04:00
fi
2015-03-27 13:25:05 -04:00
HEALTHCHECK_COLLECTION="$2"
2014-08-06 12:30:01 -04:00
shift 2
;;
2014-08-19 22:56:18 -04:00
-z|-zkhost)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "ZooKeepeer connection string is required when using the $1 option!"
exit 1
fi
2014-08-06 12:30:01 -04:00
ZK_HOST="$2"
shift 2
;;
-help|-usage)
2014-08-19 22:56:18 -04:00
print_usage "$SCRIPT_CMD"
2014-08-06 12:30:01 -04:00
exit 0
;;
--)
shift
break
;;
*)
if [ "$1" != "" ]; then
2014-08-19 22:56:18 -04:00
print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
2014-08-06 12:30:01 -04:00
exit 1
else
break # out-of-args, stop looping
fi
;;
esac
done
fi
2014-12-23 18:20:42 -05:00
if [ -z "$ZK_HOST" ]; then
2014-08-06 12:30:01 -04:00
ZK_HOST=localhost:9983
fi
2014-08-19 22:56:18 -04:00
2014-12-23 18:20:42 -05:00
if [ -z "$HEALTHCHECK_COLLECTION" ]; then
2014-08-19 22:56:18 -04:00
echo "collection parameter is required!"
print_usage "healthcheck"
exit 1
fi
2014-08-06 12:30:01 -04:00
2015-03-27 13:25:05 -04:00
run_tool healthcheck -zkHost "$ZK_HOST" -collection "$HEALTHCHECK_COLLECTION"
2014-08-06 12:30:01 -04:00
exit $?
fi
2014-10-31 00:30:52 -04:00
# create a core or collection
2015-01-12 18:33:34 -05:00
if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CMD" == "create_collection" ]]; then
2014-10-31 00:30:52 -04:00
CREATE_NUM_SHARDS=1
CREATE_REPFACT=1
if [ $# -gt 0 ]; then
while true; do
2015-03-27 13:25:05 -04:00
case "$1" in
2015-01-12 18:33:34 -05:00
-c|-core|-collection)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2015-01-12 18:33:34 -05:00
print_usage "$SCRIPT_CMD" "name is required when using the $1 option!"
2014-10-31 00:30:52 -04:00
exit 1
fi
2015-03-27 13:25:05 -04:00
CREATE_NAME="$2"
2014-10-31 00:30:52 -04:00
shift 2
;;
2015-01-12 18:33:34 -05:00
-n|-confname)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Configuration name is required when using the $1 option!"
exit 1
fi
CREATE_CONFNAME="$2"
shift 2
;;
-d|-confdir)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2015-01-12 18:33:34 -05:00
print_usage "$SCRIPT_CMD" "Configuration directory is required when using the $1 option!"
2014-10-31 00:30:52 -04:00
exit 1
fi
2015-01-12 18:33:34 -05:00
CREATE_CONFDIR="$2"
2014-10-31 00:30:52 -04:00
shift 2
;;
2014-12-02 11:57:06 -05:00
-s|-shards)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Shard count is required when using the $1 option!"
2014-10-31 00:30:52 -04:00
exit 1
fi
CREATE_NUM_SHARDS="$2"
shift 2
;;
2014-12-02 11:57:06 -05:00
-rf|-replicationFactor)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Replication factor is required when using the $1 option!"
2014-10-31 00:30:52 -04:00
exit 1
fi
CREATE_REPFACT="$2"
shift 2
;;
2014-11-26 18:12:08 -05:00
-p|-port)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Solr port is required when using the $1 option!"
exit 1
fi
CREATE_PORT="$2"
shift 2
;;
2014-10-31 00:30:52 -04:00
-help|-usage)
print_usage "$SCRIPT_CMD"
exit 0
;;
--)
shift
break
;;
*)
if [ "$1" != "" ]; then
print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
exit 1
else
break # out-of-args, stop looping
fi
;;
esac
done
fi
2015-01-12 18:33:34 -05:00
if [ -z "$CREATE_CONFDIR" ]; then
2015-03-27 13:25:05 -04:00
CREATE_CONFDIR='data_driven_schema_configs'
2014-10-31 00:30:52 -04:00
fi
2015-01-12 18:33:34 -05:00
# validate the confdir arg
if [[ ! -d "$SOLR_TIP/server/solr/configsets/$CREATE_CONFDIR" && ! -d "$CREATE_CONFDIR" ]]; then
echo -e "\nSpecified configuration directory $CREATE_CONFDIR not found!\n"
2014-12-23 23:00:49 -05:00
exit 1
fi
2014-12-23 18:20:42 -05:00
if [ -z "$CREATE_NAME" ]; then
2015-01-12 18:33:34 -05:00
echo "Name (-c) argument is required!"
2014-10-31 00:30:52 -04:00
print_usage "$SCRIPT_CMD"
exit 1
fi
2015-12-10 10:32:33 -05:00
# If not defined, use the collection name for the name of the configuration in Zookeeper
2015-01-12 18:33:34 -05:00
if [ -z "$CREATE_CONFNAME" ]; then
2015-03-27 13:25:05 -04:00
CREATE_CONFNAME="$CREATE_NAME"
2015-01-12 18:33:34 -05:00
fi
2014-12-23 18:20:42 -05:00
if [ -z "$CREATE_PORT" ]; then
2015-03-10 00:39:51 -04:00
for ID in `ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r`
2014-11-26 18:12:08 -05:00
do
port=`jetty_port "$ID"`
if [ "$port" != "" ]; then
CREATE_PORT=$port
break
fi
done
2014-10-31 00:30:52 -04:00
fi
2014-12-23 18:20:42 -05:00
if [ -z "$CREATE_PORT" ]; then
2015-01-12 18:33:34 -05:00
echo "Failed to determine the port of a local Solr instance, cannot create $CREATE_NAME!"
2014-11-26 18:12:08 -05:00
exit 1
2014-10-31 00:30:52 -04:00
fi
2015-01-12 18:33:34 -05:00
if [ "$SCRIPT_CMD" == "create_core" ]; then
2015-05-17 17:07:52 -04:00
run_tool create_core -name "$CREATE_NAME" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$CREATE_PORT/solr" \
2015-03-27 13:25:05 -04:00
-confdir "$CREATE_CONFDIR" -configsetsDir "$SOLR_TIP/server/solr/configsets"
2014-12-23 23:00:49 -05:00
exit $?
2014-10-31 00:30:52 -04:00
else
2015-05-17 17:07:52 -04:00
run_tool "$SCRIPT_CMD" -name "$CREATE_NAME" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$CREATE_PORT/solr" \
2015-03-27 13:25:05 -04:00
-shards "$CREATE_NUM_SHARDS" -replicationFactor "$CREATE_REPFACT" \
-confname "$CREATE_CONFNAME" -confdir "$CREATE_CONFDIR" \
-configsetsDir "$SOLR_TIP/server/solr/configsets"
2014-12-23 23:00:49 -05:00
exit $?
2014-10-31 00:30:52 -04:00
fi
fi
2015-01-16 01:36:15 -05:00
# delete a core or collection
if [[ "$SCRIPT_CMD" == "delete" ]]; then
if [ $# -gt 0 ]; then
while true; do
2015-03-27 13:25:05 -04:00
case "$1" in
2015-01-16 01:36:15 -05:00
-c|-core|-collection)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "name is required when using the $1 option!"
exit 1
fi
2015-03-27 13:25:05 -04:00
DELETE_NAME="$2"
2015-01-16 01:36:15 -05:00
shift 2
;;
-p|-port)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Solr port is required when using the $1 option!"
exit 1
fi
DELETE_PORT="$2"
shift 2
;;
-deleteConfig)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "true|false is required when using the $1 option!"
exit 1
fi
DELETE_CONFIG="$2"
shift 2
;;
-help|-usage)
print_usage "$SCRIPT_CMD"
exit 0
;;
--)
shift
break
;;
*)
if [ "$1" != "" ]; then
print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
exit 1
else
break # out-of-args, stop looping
fi
;;
esac
done
fi
if [ -z "$DELETE_NAME" ]; then
echo "Name (-c) argument is required!"
print_usage "$SCRIPT_CMD"
exit 1
fi
2015-12-10 10:32:33 -05:00
# If not defined, use the collection name for the name of the configuration in Zookeeper
2015-01-16 01:36:15 -05:00
if [ -z "$DELETE_CONFIG" ]; then
DELETE_CONFIG=true
fi
if [ -z "$DELETE_PORT" ]; then
2015-03-10 00:39:51 -04:00
for ID in `ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r`
2015-01-16 01:36:15 -05:00
do
port=`jetty_port "$ID"`
if [ "$port" != "" ]; then
DELETE_PORT=$port
break
fi
done
fi
if [ -z "$DELETE_PORT" ]; then
echo "Failed to determine the port of a local Solr instance, cannot delete $DELETE_NAME!"
exit 1
fi
2015-03-27 13:25:05 -04:00
run_tool delete -name "$DELETE_NAME" -deleteConfig "$DELETE_CONFIG" \
2015-05-17 17:07:52 -04:00
-solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$DELETE_PORT/solr"
2015-01-16 01:36:15 -05:00
exit $?
fi
2014-10-31 00:30:52 -04:00
2015-12-10 10:32:33 -05:00
# Upload or download a configset to Zookeeper
if [[ "$SCRIPT_CMD" == "zk" ]]; then
if [ $# -gt 0 ]; then
while true; do
case "$1" in
-z|-zkhost)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "ZooKeepeer connection string is required when using the $1 option!"
exit 1
fi
ZK_HOST="$2"
shift 2
;;
-n|-confname)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Configuration name is required when using the $1 option!"
exit 1
fi
CONFIGSET_CONFNAME="$2"
shift 2
;;
-d|-confdir)
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Configuration directory is required when using the $1 option!"
exit 1
fi
CONFIGSET_CONFDIR="$2"
shift 2
;;
-upconfig)
ZK_OP="upconfig"
shift 1
;;
-downconfig)
ZK_OP="downconfig"
shift 1
;;
-help|-usage|-h)
print_usage "$SCRIPT_CMD"
exit 0
;;
--)
shift
break
;;
*)
if [ "$1" != "" ]; then
print_usage "$SCRIPT_CMD" "Unrecognized or misplaced argument: $1!"
exit 1
else
break # out-of-args, stop looping
fi
;;
esac
done
fi
if [ -z "$ZK_OP" ]; then
echo "Zookeeper operation (one of '-upconfig' or '-downconfig') is required!"
print_usage "$SCRIPT_CMD"
exit 1
fi
if [ -z "$ZK_HOST" ]; then
echo "Zookeeper address (-z) argument is required!"
print_usage "$SCRIPT_CMD"
exit 1
fi
if [ -z "$CONFIGSET_CONFDIR" ]; then
echo "Local directory of the configset (-d) argument is required!"
print_usage "$SCRIPT_CMD"
exit 1
fi
if [ -z "$CONFIGSET_CONFNAME" ]; then
echo "Configset name on Zookeeper (-n) argument is required!"
print_usage "$SCRIPT_CMD"
exit 1
fi
if [ "$ZK_OP" == "upconfig" ]; then
run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST" -configsetsDir "$SOLR_TIP/server/solr/configsets"
else
run_tool "$ZK_OP" -confname "$CONFIGSET_CONFNAME" -confdir "$CONFIGSET_CONFDIR" -zkHost "$ZK_HOST"
fi
exit $?
fi
2014-08-06 12:30:01 -04:00
# verify the command given is supported
2014-12-23 18:20:42 -05:00
if [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD" != "restart" ] && [ "$SCRIPT_CMD" != "status" ]; then
2014-11-26 18:12:08 -05:00
print_usage "" "$SCRIPT_CMD is not a valid command!"
2014-08-06 12:30:01 -04:00
exit 1
fi
# Run in foreground (default is to run in the background)
FG="false"
noprompt=false
2015-04-18 15:13:00 -04:00
SOLR_OPTS=($SOLR_OPTS)
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE=
2014-08-06 12:30:01 -04:00
if [ $# -gt 0 ]; then
while true; do
2015-03-27 13:25:05 -04:00
case "$1" in
2014-08-06 12:30:01 -04:00
-c|-cloud)
SOLR_MODE="solrcloud"
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" -c"
2014-08-06 12:30:01 -04:00
shift
;;
-d|-dir)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Server directory is required when using the $1 option!"
exit 1
2014-08-19 22:56:18 -04:00
fi
2014-12-02 11:57:06 -05:00
if [[ "$2" == "." || "$2" == "./" || "$2" == ".." || "$2" == "../" ]]; then
2015-03-27 13:25:05 -04:00
SOLR_SERVER_DIR="$(pwd)/$2"
2014-10-09 14:42:21 -04:00
else
2014-12-02 11:57:06 -05:00
# see if the arg value is relative to the tip vs full path
2015-03-27 13:25:05 -04:00
if [[ "$2" != /* ]] && [[ -d "$SOLR_TIP/$2" ]]; then
2014-12-02 11:57:06 -05:00
SOLR_SERVER_DIR="$SOLR_TIP/$2"
else
SOLR_SERVER_DIR="$2"
fi
2014-08-06 12:30:01 -04:00
fi
2014-12-02 11:57:06 -05:00
# resolve it to an absolute path
2015-03-27 13:25:05 -04:00
SOLR_SERVER_DIR="$(cd "$SOLR_SERVER_DIR"; pwd)"
2014-08-06 12:30:01 -04:00
shift 2
;;
2014-10-09 14:42:21 -04:00
-s|-solr.home)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Solr home directory is required when using the $1 option!"
2014-10-09 14:42:21 -04:00
exit 1
fi
SOLR_HOME="$2"
shift 2
;;
2014-08-06 12:30:01 -04:00
-e|-example)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Example name is required when using the $1 option!"
exit 1
2014-08-19 22:56:18 -04:00
fi
2014-08-06 12:30:01 -04:00
EXAMPLE="$2"
shift 2
;;
-f|-foreground)
FG="true"
shift
;;
-h|-host)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Hostname is required when using the $1 option!"
exit 1
2014-08-19 22:56:18 -04:00
fi
2014-08-06 12:30:01 -04:00
SOLR_HOST="$2"
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" -h $SOLR_HOST"
2014-08-06 12:30:01 -04:00
shift 2
;;
-m|-memory)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Memory setting is required when using the $1 option!"
exit 1
fi
2014-08-06 12:30:01 -04:00
SOLR_HEAP="$2"
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" -m $SOLR_HEAP"
2014-08-06 12:30:01 -04:00
shift 2
;;
-p|-port)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2014-11-26 18:12:08 -05:00
print_usage "$SCRIPT_CMD" "Port number is required when using the $1 option!"
exit 1
fi
2014-08-06 12:30:01 -04:00
SOLR_PORT="$2"
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" -p $SOLR_PORT"
2014-08-06 12:30:01 -04:00
shift 2
;;
-z|-zkhost)
2014-12-23 18:20:42 -05:00
if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
2015-12-10 10:32:33 -05:00
print_usage "$SCRIPT_CMD" "Zookeeper connection string is required when using the $1 option!"
2014-11-26 18:12:08 -05:00
exit 1
2014-08-19 22:56:18 -04:00
fi
2014-08-06 12:30:01 -04:00
ZK_HOST="$2"
2014-12-23 18:20:42 -05:00
SOLR_MODE="solrcloud"
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" -z $ZK_HOST"
2014-08-06 12:30:01 -04:00
shift 2
;;
2014-09-22 12:48:32 -04:00
-a|-addlopts)
ADDITIONAL_CMD_OPTS="$2"
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" -a \"$ADDITIONAL_CMD_OPTS\""
2014-09-22 12:48:32 -04:00
shift 2
;;
2014-10-09 14:42:21 -04:00
-k|-key)
STOP_KEY="$2"
shift 2
;;
2014-08-06 12:30:01 -04:00
-help|-usage)
2014-08-19 22:56:18 -04:00
print_usage "$SCRIPT_CMD"
2014-08-06 12:30:01 -04:00
exit 0
;;
-noprompt)
noprompt=true
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" -noprompt"
2014-08-06 12:30:01 -04:00
shift
;;
-V|-verbose)
verbose=true
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" --verbose"
2014-08-06 12:30:01 -04:00
shift
;;
2014-10-09 18:28:05 -04:00
-all)
stop_all=true
shift
;;
2014-08-06 12:30:01 -04:00
--)
shift
break
;;
*)
2014-12-11 19:21:27 -05:00
if [ "${1:0:2}" == "-D" ]; then
# pass thru any opts that begin with -D (java system props)
2015-03-27 13:25:05 -04:00
SOLR_OPTS+=("$1")
2015-08-04 12:32:12 -04:00
PASS_TO_RUN_EXAMPLE+=" $1"
2014-12-11 19:21:27 -05:00
shift
2014-08-06 12:30:01 -04:00
else
2014-12-11 19:21:27 -05:00
if [ "$1" != "" ]; then
print_usage "$SCRIPT_CMD" "$1 is not supported by this script"
exit 1
else
break # out-of-args, stop looping
fi
fi
2014-08-06 12:30:01 -04:00
;;
esac
done
fi
2014-12-23 18:20:42 -05:00
if [ -z "$SOLR_SERVER_DIR" ]; then
2015-03-27 13:25:05 -04:00
SOLR_SERVER_DIR="$DEFAULT_SERVER_DIR"
2014-08-06 12:30:01 -04:00
fi
if [ ! -e "$SOLR_SERVER_DIR" ]; then
echo -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n"
exit 1
fi
2015-03-27 13:25:05 -04:00
if [[ "$FG" == 'true' && "$EXAMPLE" != "" ]]; then
FG='false'
2014-12-02 11:57:06 -05:00
echo -e "\nWARNING: Foreground mode (-f) not supported when running examples.\n"
fi
2015-08-04 12:32:12 -04:00
#
# If the user specified an example to run, invoke the run_example tool (Java app) and exit
# otherwise let this script proceed to process the user request
#
if [ -n "$EXAMPLE" ] && [ "$SCRIPT_CMD" == "start" ]; then
run_tool run_example -e $EXAMPLE -d "$SOLR_SERVER_DIR" -urlScheme $SOLR_URL_SCHEME $PASS_TO_RUN_EXAMPLE
exit $?
fi
############# start/stop logic below here ################
if $verbose ; then
echo "Using Solr root directory: $SOLR_TIP"
echo "Using Java: $JAVA"
"$JAVA" -version
fi
if [ "$SOLR_HOST" != "" ]; then
SOLR_HOST_ARG=("-Dhost=$SOLR_HOST")
else
SOLR_HOST_ARG=()
fi
2014-12-23 18:20:42 -05:00
if [ -z "$STOP_KEY" ]; then
2015-03-27 13:25:05 -04:00
STOP_KEY='solrrocks'
2014-08-06 12:30:01 -04:00
fi
# stop all if no port specified
2014-12-23 18:20:42 -05:00
if [[ "$SCRIPT_CMD" == "stop" && -z "$SOLR_PORT" ]]; then
2014-10-09 18:28:05 -04:00
if $stop_all; then
none_stopped=true
2015-03-27 13:25:05 -04:00
find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | while read PIDF
2014-08-06 12:30:01 -04:00
do
2015-03-27 13:25:05 -04:00
NEXT_PID=`cat "$PIDF"`
2014-10-09 18:28:05 -04:00
port=`jetty_port "$NEXT_PID"`
if [ "$port" != "" ]; then
stop_solr "$SOLR_SERVER_DIR" "$port" "$STOP_KEY" "$NEXT_PID"
none_stopped=false
fi
2015-03-27 13:25:05 -04:00
rm -f "$PIDF"
2014-10-09 18:28:05 -04:00
done
2015-04-18 15:13:00 -04:00
# TODO: none_stopped doesn't get reflected across the subshell
# This can be uncommented once we find a clean way out of it
# if $none_stopped; then
# echo -e "\nNo Solr nodes found to stop.\n"
# fi
2014-08-06 12:30:01 -04:00
else
2014-12-23 18:20:42 -05:00
# 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
none_stopped=true
2015-03-27 13:25:05 -04:00
numSolrs=`find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' '`
2015-01-22 14:17:01 -05:00
if [ $numSolrs -eq 1 ]; then
# only do this if there is only 1 node running, otherwise they must provide the -p or -all
2015-03-27 13:25:05 -04:00
PID="$(cat "$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)")"
2015-04-22 18:42:19 -04:00
CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $PID | sort -r | tr -d ' '`
2014-12-23 18:20:42 -05:00
if [ "$CHECK_PID" != "" ]; then
port=`jetty_port "$CHECK_PID"`
if [ "$port" != "" ]; then
stop_solr "$SOLR_SERVER_DIR" "$port" "$STOP_KEY" "$CHECK_PID"
none_stopped=false
fi
fi
fi
2015-01-22 14:17:01 -05:00
2014-12-23 18:20:42 -05:00
if $none_stopped; then
2015-01-22 14:17:01 -05:00
if [ $numSolrs -gt 0 ]; then
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"
else
echo -e "\nNo Solr nodes found to stop.\n"
fi
2014-12-23 18:20:42 -05:00
exit 1
fi
2014-08-06 12:30:01 -04:00
fi
2014-10-09 18:28:05 -04:00
exit
2014-08-06 12:30:01 -04:00
fi
2014-12-23 18:20:42 -05:00
if [ -z "$SOLR_PORT" ]; then
2015-03-27 13:25:05 -04:00
SOLR_PORT=8983
2014-08-06 12:30:01 -04:00
fi
2014-12-23 18:20:42 -05:00
if [ -z "$STOP_PORT" ]; then
2014-10-31 12:56:22 -04:00
STOP_PORT=`expr $SOLR_PORT - 1000`
2014-08-06 12:30:01 -04:00
fi
if [[ "$SCRIPT_CMD" == "start" ]]; then
# see if Solr is already running
2014-10-09 18:28:05 -04:00
SOLR_PID=`solr_pid_by_port "$SOLR_PORT"`
2014-10-13 12:38:49 -04:00
2014-12-23 18:20:42 -05:00
if [ -z "$SOLR_PID" ]; then
2014-10-13 12:38:49 -04:00
# not found using the pid file ... but use ps to ensure not found
2015-03-10 00:39:51 -04:00
SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`
2014-10-13 12:38:49 -04:00
fi
2014-08-06 12:30:01 -04:00
if [ "$SOLR_PID" != "" ]; then
2014-12-23 18:20:42 -05:00
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"
2014-12-02 11:57:06 -05:00
exit 1
2014-08-06 12:30:01 -04:00
fi
else
# either stop or restart
2014-10-13 15:23:22 -04:00
# see if Solr is already running
2014-10-09 18:28:05 -04:00
SOLR_PID=`solr_pid_by_port "$SOLR_PORT"`
2014-12-23 18:20:42 -05:00
if [ -z "$SOLR_PID" ]; then
2014-10-13 15:23:22 -04:00
# not found using the pid file ... but use ps to ensure not found
2015-04-22 18:42:19 -04:00
SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`
2014-10-13 15:23:22 -04:00
fi
2014-10-09 18:28:05 -04:00
if [ "$SOLR_PID" != "" ]; then
2014-10-13 15:23:22 -04:00
stop_solr "$SOLR_SERVER_DIR" "$SOLR_PORT" "$STOP_KEY" "$SOLR_PID"
2014-10-09 18:28:05 -04:00
else
2014-12-05 10:10:21 -05:00
if [ "$SCRIPT_CMD" == "stop" ]; then
echo -e "No process found for Solr node running on port $SOLR_PORT"
exit 1
fi
2014-10-09 18:28:05 -04:00
fi
2014-08-06 12:30:01 -04:00
fi
2014-12-23 18:20:42 -05:00
if [ -z "$SOLR_HOME" ]; then
2014-12-11 19:21:27 -05:00
SOLR_HOME="$SOLR_SERVER_DIR/solr"
else
if [[ $SOLR_HOME != /* ]] && [[ -d "$SOLR_SERVER_DIR/$SOLR_HOME" ]]; then
SOLR_HOME="$SOLR_SERVER_DIR/$SOLR_HOME"
2015-03-27 13:25:05 -04:00
SOLR_PID_DIR="$SOLR_HOME"
2014-12-11 19:21:27 -05:00
elif [[ $SOLR_HOME != /* ]] && [[ -d "`pwd`/$SOLR_HOME" ]]; then
2015-03-27 13:25:05 -04:00
SOLR_HOME="$(pwd)/$SOLR_HOME"
2014-08-06 12:30:01 -04:00
fi
fi
2014-12-11 19:21:27 -05:00
# This is quite hacky, but examples rely on a different log4j.properties
# so that we can write logs for examples to $SOLR_HOME/../logs
2014-12-23 18:20:42 -05:00
if [ -z "$SOLR_LOGS_DIR" ]; then
2015-03-27 13:25:05 -04:00
SOLR_LOGS_DIR="$SOLR_SERVER_DIR/logs"
2014-12-23 18:20:42 -05:00
fi
2015-03-27 13:25:05 -04:00
EXAMPLE_DIR="$SOLR_TIP/example"
if [ "${SOLR_HOME:0:${#EXAMPLE_DIR}}" = "$EXAMPLE_DIR" ]; then
LOG4J_PROPS="$EXAMPLE_DIR/resources/log4j.properties"
SOLR_LOGS_DIR="$SOLR_HOME/../logs"
2014-12-23 18:20:42 -05:00
fi
2015-03-27 13:25:05 -04:00
LOG4J_CONFIG=()
2014-12-23 18:20:42 -05:00
if [ -n "$LOG4J_PROPS" ]; then
2015-03-27 13:25:05 -04:00
LOG4J_CONFIG+=("-Dlog4j.configuration=file:$LOG4J_PROPS")
2014-08-06 12:30:01 -04:00
fi
if [ "$SCRIPT_CMD" == "stop" ]; then
# already stopped, script is done.
exit 0
fi
2014-12-11 19:21:27 -05:00
# NOTE: If the script gets to here, then it is starting up a Solr node.
2014-10-09 18:28:05 -04:00
if [ ! -e "$SOLR_HOME" ]; then
echo -e "\nSolr home directory $SOLR_HOME not found!\n"
exit 1
fi
2014-08-06 12:30:01 -04:00
2014-12-11 19:21:27 -05:00
# backup the log files before starting
2015-03-27 13:25:05 -04:00
if [ -f "$SOLR_LOGS_DIR/solr.log" ]; then
2014-12-11 19:21:27 -05:00
if $verbose ; then
echo "Backing up $SOLR_LOGS_DIR/solr.log"
fi
2015-03-27 13:25:05 -04:00
mv "$SOLR_LOGS_DIR/solr.log" "$SOLR_LOGS_DIR/solr_log_$(date +"%Y%m%d_%H%M")"
2014-12-11 19:21:27 -05:00
fi
2015-03-27 13:25:05 -04:00
if [ -f "$SOLR_LOGS_DIR/solr_gc.log" ]; then
2014-12-11 19:21:27 -05:00
if $verbose ; then
echo "Backing up $SOLR_LOGS_DIR/solr_gc.log"
fi
2015-03-27 13:25:05 -04:00
mv "$SOLR_LOGS_DIR/solr_gc.log" "$SOLR_LOGS_DIR/solr_gc_log_$(date +"%Y%m%d_%H%M")"
2014-12-11 19:21:27 -05:00
fi
2015-07-08 07:43:22 -04:00
java_ver_out=`echo "$("$JAVA" -version 2>&1)"`
JAVA_VERSION=`echo $java_ver_out | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'`
JAVA_VENDOR="Oracle"
if [ "`echo $java_ver_out | grep -i "IBM J9"`" != "" ]; then
JAVA_VENDOR="IBM J9"
fi
2014-08-06 12:30:01 -04:00
# if verbose gc logging enabled, setup the location of the log file
if [ "$GC_LOG_OPTS" != "" ]; then
2015-07-08 07:43:22 -04:00
gc_log_flag="-Xloggc"
if [ "$JAVA_VENDOR" == "IBM J9" ]; then
gc_log_flag="-Xverbosegclog"
fi
GC_LOG_OPTS=($GC_LOG_OPTS "$gc_log_flag:$SOLR_LOGS_DIR/solr_gc.log")
2015-03-27 13:25:05 -04:00
else
GC_LOG_OPTS=()
2014-08-06 12:30:01 -04:00
fi
2015-05-06 01:38:01 -04:00
# If ZK_HOST is defined, the assume SolrCloud mode
if [[ -n "$ZK_HOST" ]]; then
SOLR_MODE="solrcloud"
fi
2015-03-27 13:25:05 -04:00
if [ "$SOLR_MODE" == 'solrcloud' ]; then
2014-12-23 18:20:42 -05:00
if [ -z "$ZK_CLIENT_TIMEOUT" ]; then
2014-08-06 12:30:01 -04:00
ZK_CLIENT_TIMEOUT="15000"
fi
2015-03-27 13:25:05 -04:00
CLOUD_MODE_OPTS=("-DzkClientTimeout=$ZK_CLIENT_TIMEOUT")
2014-08-06 12:30:01 -04:00
if [ "$ZK_HOST" != "" ]; then
2015-03-27 13:25:05 -04:00
CLOUD_MODE_OPTS+=("-DzkHost=$ZK_HOST")
2014-08-06 12:30:01 -04:00
else
if $verbose ; then
2015-12-10 10:32:33 -05:00
echo "Configuring SolrCloud to launch an embedded Zookeeper using -DzkRun"
2014-08-06 12:30:01 -04:00
fi
2015-03-27 13:25:05 -04:00
CLOUD_MODE_OPTS+=('-DzkRun')
2014-09-22 13:23:14 -04:00
fi
# and if collection1 needs to be bootstrapped
if [ -e "$SOLR_HOME/collection1/core.properties" ]; then
2015-03-27 13:25:05 -04:00
CLOUD_MODE_OPTS+=('-Dbootstrap_confdir=./solr/collection1/conf' '-Dcollection.configName=myconf' '-DnumShards=1')
2014-08-06 12:30:01 -04:00
fi
2014-08-19 22:56:18 -04:00
2015-07-25 20:15:27 -04:00
else
if [ ! -e "$SOLR_HOME/solr.xml" ]; then
echo -e "\nSolr home directory $SOLR_HOME must contain a solr.xml file!\n"
exit 1
fi
2014-08-06 12:30:01 -04:00
fi
2015-01-11 20:00:04 -05:00
# These are useful for attaching remote profilers like VisualVM/JConsole
2014-08-06 12:30:01 -04:00
if [ "$ENABLE_REMOTE_JMX_OPTS" == "true" ]; then
2014-12-01 14:50:30 -05:00
2014-12-23 18:20:42 -05:00
if [ -z "$RMI_PORT" ]; then
2015-03-27 13:25:05 -04:00
RMI_PORT="1$SOLR_PORT"
2014-12-01 14:50:30 -05:00
fi
2015-03-27 13:25:05 -04:00
REMOTE_JMX_OPTS=('-Dcom.sun.management.jmxremote' \
'-Dcom.sun.management.jmxremote.local.only=false' \
'-Dcom.sun.management.jmxremote.ssl=false' \
'-Dcom.sun.management.jmxremote.authenticate=false' \
"-Dcom.sun.management.jmxremote.port=$RMI_PORT" \
"-Dcom.sun.management.jmxremote.rmi.port=$RMI_PORT")
2014-08-06 12:30:01 -04:00
# if the host is set, then set that as the rmi server hostname
if [ "$SOLR_HOST" != "" ]; then
2015-03-27 13:25:05 -04:00
REMOTE_JMX_OPTS+=("-Djava.rmi.server.hostname=$SOLR_HOST")
2014-08-06 12:30:01 -04:00
fi
else
2015-03-27 13:25:05 -04:00
REMOTE_JMX_OPTS=()
2014-08-06 12:30:01 -04:00
fi
2015-04-18 15:13:00 -04:00
JAVA_MEM_OPTS=()
if [ -z "$SOLR_HEAP" ] && [ -n "$SOLR_JAVA_MEM" ]; then
JAVA_MEM_OPTS=($SOLR_JAVA_MEM)
else
SOLR_HEAP="${SOLR_HEAP:-512m}"
JAVA_MEM_OPTS=("-Xms$SOLR_HEAP" "-Xmx$SOLR_HEAP")
2014-08-06 12:30:01 -04:00
fi
2014-12-23 18:20:42 -05:00
if [ -z "$SOLR_TIMEZONE" ]; then
2015-03-27 13:25:05 -04:00
SOLR_TIMEZONE='UTC'
2014-08-06 12:30:01 -04:00
fi
# Launches Solr in foreground/background depending on parameters
function launch_solr() {
run_in_foreground="$1"
2014-10-31 12:56:22 -04:00
stop_port="$STOP_PORT"
2014-08-06 12:30:01 -04:00
SOLR_ADDL_ARGS="$2"
2015-03-27 13:25:05 -04:00
GC_TUNE=($GC_TUNE)
2014-11-10 23:21:44 -05:00
# deal with Java version specific GC and other flags
if [ "${JAVA_VERSION:0:3}" == "1.7" ]; then
# Specific Java version hacking
2015-03-27 13:25:05 -04:00
GC_TUNE+=('-XX:CMSFullGCsBeforeCompaction=1' '-XX:CMSTriggerPermRatio=80')
2015-07-08 07:43:22 -04:00
if [ "$JAVA_VENDOR" != "IBM J9" ]; then
JAVA_MINOR_VERSION=${JAVA_VERSION:(-2)}
if [[ $JAVA_MINOR_VERSION -ge 40 && $JAVA_MINOR_VERSION -le 51 ]]; then
GC_TUNE+=('-XX:-UseSuperWord')
echo -e "\nWARNING: Java version $JAVA_VERSION has known bugs with Lucene and requires the -XX:-UseSuperWord flag. Please consider upgrading your JVM.\n"
fi
2014-11-10 23:21:44 -05:00
fi
fi
2015-01-15 13:24:48 -05:00
# If SSL-related system props are set, add them to SOLR_OPTS
if [ -n "$SOLR_SSL_OPTS" ]; then
2015-04-23 10:17:35 -04:00
# If using SSL and solr.jetty.https.port not set explicitly, use the jetty.port
SSL_PORT_PROP="-Dsolr.jetty.https.port=$SOLR_PORT"
2015-03-27 13:25:05 -04:00
SOLR_OPTS+=($SOLR_SSL_OPTS "$SSL_PORT_PROP")
2015-01-15 13:24:48 -05:00
fi
2015-05-19 17:10:16 -04:00
# If authentication system props are set, add them to SOLR_OPTS
if [ -n "$AUTHC_OPTS" ]; then
SOLR_OPTS+=($AUTHC_OPTS)
fi
2014-08-06 12:30:01 -04:00
if $verbose ; then
echo -e "\nStarting Solr using the following settings:"
2014-12-01 14:50:30 -05:00
echo -e " JAVA = $JAVA"
2014-08-06 12:30:01 -04:00
echo -e " SOLR_SERVER_DIR = $SOLR_SERVER_DIR"
echo -e " SOLR_HOME = $SOLR_HOME"
echo -e " SOLR_HOST = $SOLR_HOST"
echo -e " SOLR_PORT = $SOLR_PORT"
2014-12-01 14:50:30 -05:00
echo -e " STOP_PORT = $STOP_PORT"
2015-04-18 15:13:00 -04:00
echo -e " JAVA_MEM_OPTS = ${JAVA_MEM_OPTS[@]}"
2015-03-29 18:43:14 -04:00
echo -e " GC_TUNE = ${GC_TUNE[@]}"
echo -e " GC_LOG_OPTS = ${GC_LOG_OPTS[@]}"
2014-08-06 12:30:01 -04:00
echo -e " SOLR_TIMEZONE = $SOLR_TIMEZONE"
2014-12-01 14:50:30 -05:00
if [ "$SOLR_MODE" == "solrcloud" ]; then
2015-03-29 18:43:14 -04:00
echo -e " CLOUD_MODE_OPTS = ${CLOUD_MODE_OPTS[@]}"
2014-12-01 14:50:30 -05:00
fi
2014-11-11 16:20:56 -05:00
if [ "$SOLR_OPTS" != "" ]; then
2015-03-29 18:43:14 -04:00
echo -e " SOLR_OPTS = ${SOLR_OPTS[@]}"
2014-11-11 16:20:56 -05:00
fi
2014-12-01 14:50:30 -05:00
2014-08-06 12:30:01 -04:00
if [ "$SOLR_ADDL_ARGS" != "" ]; then
echo -e " SOLR_ADDL_ARGS = $SOLR_ADDL_ARGS"
fi
2014-12-01 14:50:30 -05:00
if [ "$ENABLE_REMOTE_JMX_OPTS" == "true" ]; then
echo -e " RMI_PORT = $RMI_PORT"
2015-03-29 18:43:14 -04:00
echo -e " REMOTE_JMX_OPTS = ${REMOTE_JMX_OPTS[@]}"
2014-12-01 14:50:30 -05:00
fi
echo -e "\n"
2014-08-06 12:30:01 -04:00
fi
# need to launch solr from the server dir
2015-03-27 13:25:05 -04:00
cd "$SOLR_SERVER_DIR"
2014-08-06 12:30:01 -04:00
if [ ! -e "$SOLR_SERVER_DIR/start.jar" ]; then
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"
exit 1
fi
2015-08-06 11:26:11 -04:00
SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE[@]}" "${GC_LOG_OPTS[@]}" \
2015-03-27 13:25:05 -04:00
"${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" \
"-Djetty.port=$SOLR_PORT" "-DSTOP.PORT=$stop_port" "-DSTOP.KEY=$STOP_KEY" \
"${SOLR_HOST_ARG[@]}" "-Duser.timezone=$SOLR_TIMEZONE" \
"-Djetty.home=$SOLR_SERVER_DIR" "-Dsolr.solr.home=$SOLR_HOME" "-Dsolr.install.dir=$SOLR_TIP" \
"${LOG4J_CONFIG[@]}" "${SOLR_OPTS[@]}")
2014-08-06 12:30:01 -04:00
if [ "$SOLR_MODE" == "solrcloud" ]; then
IN_CLOUD_MODE=" in SolrCloud mode"
fi
2014-11-10 23:21:44 -05:00
2015-03-27 13:25:05 -04:00
mkdir -p "$SOLR_LOGS_DIR"
2014-11-10 23:21:44 -05:00
2014-08-06 12:30:01 -04:00
if [ "$run_in_foreground" == "true" ]; then
echo -e "\nStarting Solr$IN_CLOUD_MODE on port $SOLR_PORT from $SOLR_SERVER_DIR\n"
2015-10-14 17:51:56 -04:00
exec "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -jar start.jar "${SOLR_JETTY_CONFIG[@]}"
2014-08-06 12:30:01 -04:00
else
# run Solr in the background
2015-03-27 13:25:05 -04:00
nohup "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -jar start.jar \
2015-04-23 10:17:35 -04:00
"-XX:OnOutOfMemoryError=$SOLR_TIP/bin/oom_solr.sh $SOLR_PORT $SOLR_LOGS_DIR" "${SOLR_JETTY_CONFIG[@]}" \
2015-03-27 13:25:05 -04:00
1>"$SOLR_LOGS_DIR/solr-$SOLR_PORT-console.log" 2>&1 & echo $! > "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
2014-08-19 22:56:18 -04:00
# no lsof on cygwin though
2015-01-30 20:32:03 -05:00
if hash lsof 2>/dev/null ; then # hash returns true if lsof is on the path
2015-08-04 12:32:12 -04:00
echo -n "Waiting up to 30 seconds to see Solr running on port $SOLR_PORT"
2014-09-05 12:30:23 -04:00
# Launch in a subshell to show the spinner
(loops=0
while true
do
2015-06-13 14:03:01 -04:00
running=`lsof -PniTCP:$SOLR_PORT -sTCP:LISTEN`
2014-12-23 18:20:42 -05:00
if [ -z "$running" ]; then
2014-09-05 12:30:23 -04:00
if [ $loops -lt 6 ]; then
sleep 5
loops=$[$loops+1]
else
echo -e "Still not seeing Solr listening on $SOLR_PORT after 30 seconds!"
2015-03-27 13:25:05 -04:00
tail -30 "$SOLR_LOGS_DIR/solr.log"
2015-06-17 17:27:10 -04:00
exit # subshell!
2014-09-05 12:30:23 -04:00
fi
2014-08-06 12:30:01 -04:00
else
2015-04-22 18:42:19 -04:00
SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`
2014-09-05 12:30:23 -04:00
echo -e "\nStarted Solr server on port $SOLR_PORT (pid=$SOLR_PID). Happy searching!\n"
2015-06-17 17:27:10 -04:00
exit # subshell!
2014-09-05 12:30:23 -04:00
fi
done) &
spinner $!
else
2015-06-17 17:27:10 -04:00
echo -e "NOTE: Please install lsof as this script needs it to determine if Solr is listening on port $SOLR_PORT."
sleep 10
2015-04-22 18:42:19 -04:00
SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`
2014-09-05 12:30:23 -04:00
echo -e "\nStarted Solr server on port $SOLR_PORT (pid=$SOLR_PID). Happy searching!\n"
2015-06-17 17:27:10 -04:00
return;
2014-09-05 12:30:23 -04:00
fi
2014-08-06 12:30:01 -04:00
fi
}
2015-08-04 12:32:12 -04:00
launch_solr "$FG" "$ADDITIONAL_CMD_OPTS"
2014-08-06 12:30:01 -04:00
exit $?