blob: 65062441819d1802f0e20fea0fbe9e90dc871bfc [file] [log] [blame]
#!/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:
#
# TODO: Write instructions here.
#
##### Setup
DEFAULT_X_WHICH=/usr/bin/which
verbose=false
stop_all=false
##### End Setup
#
#----
# DO NOT EDIT BELOW THIS LINE WITHOUT GUIDANCE
#----
# If the variable for the which command isn't set, set
# it to the default.
if [ -z "${X_WHICH}" ]; then
X_WHICH="${DEFAULT_X_WHICH}"
fi
# Abort if certain required commands are are not found.
if [ ! -x "${X_WHICH}" ]; then
# last-ditch effort for locating which, will succeed if it's
# on the path.
X_WHICH="`which which`"
RET=$?
# TODO: Consider only relying on the exit code.
if [ ${RET} -ne 0 ] || [ ! -x "${X_WHICH}" ]; then
echo >&2 "The "which" command is not found or not executable."
echo >&2 "This command is required. Aborting."
echo >&2 "The X_WHICH env variable can explicitly set its location."
exit 1
fi
fi
X_DIRNAME=`"${X_WHICH}" dirname`
# The which command should only return files that are executable,
# so we are only checking that the value is present.
if [ -z "${X_DIRNAME}" ]; then
echo >&2 "The dirname command is not found or not executable."
echo >&2 "This command is required. Aborting."
echo >&2 "The X_DIRNAME env variable can explicitly set its location."
exit 1
fi
# Figure out where this script is and load function definitions.
# Abort the script if not found.
THIS_SCRIPT="$0"
cd `"${X_DIRNAME}" "${THIS_SCRIPT}"`
SCRIPT_DIR="`pwd`"
SCRIPT_FUNCTIONS="${SCRIPT_DIR}/functions.sh"
if [ -r "${SCRIPT_FUNCTIONS}" ]; then
. ${SCRIPT_FUNCTIONS}
else
echo >&2 "Function include file ${SCRIPT_FUNCTIONS} not found or not readable."
echo >&2 "These functions are critical for script operation. Aborting."
exit 1
fi
# Exit if bash not found or too old.
exit_if_no_bash
exit_if_bash_too_old
# Running this script from cygwin is not supported.
# If somebody creates a bulletproof implementation,
# This might be reconsidered.
THIS_OS="`uname -s`"
if [ -z "${SOLR_FORCE_FLAG}" ] && [[ "${THIS_OS,,}" = *cygwin* ]]; then
echo >&2 "This script does not support cygwin."
echo >&2 "Use the native solr.cmd script on Windows."
echo >&2 "You can continue by setting SOLR_FORCE_FLAG,"
echo >&2 "but you'll be in unsupported territory."
err_msg_contact_community
exit 1
fi
# If there are other platforms that are not supported, detect above this line.
# Call function to set location variables, including SOLR_TIP. The
# function will also change the current directory to SOLR_TIP.
find_dirs_and_change_cwd ${SCRIPT_DIR}
# Find required system executables and assign variables to access them.
# Exit the script if something critical is not found.
find_system_programs_or_exit
# Call the included function for locating Java, exit if not found.
find_java_or_exit
# Create and then delete a tempfile for this script run.
# We will then use the filename later in the script.
mkdir -p ${SOLR_TMP_DIR}
RET=$?
if [ ${RET} -ne 0 ]; then
echo >&2 "Error creating temp directory ${SOLR_TMP_DIR}. Aborting."
err_msg_contact_community
exit 1
fi
TMP_FILE=`"${X_TEMPFILE}" -d "${SOLR_TMP_DIR}"`
RET=$?
if [ ${RET} -ne 0 ]; then
echo >&2 "Unable to create tempfile. Aborting."
err_msg_contact_community
exit 1
fi
rm -rf ${TMP_FILE}
# Ask the agent for commands to set environment variables.
# Write the commands to the tempfile, source the file, and
# then delete it. This step will also do validation of the
# JVM and OS, setting environment variables for further action.
agent_get_env > ${TMP_FILE}
RET=$?
RET=0
if [ ${RET} -ne 0 ]; then
rm -rf ${TMP_FILE}
echo >&2 "Error getting env variables from agent. Aborting."
err_msg_contact_community
exit 1
fi
. ${TMP_FILE}
rm -rf ${TMP_FILE}
# If set, display generic message from the agent on stdout.
if [ -n "${SOLR_AGENT_MESSAGE}" ]; then
echo -e "${SOLR_AGENT_MESSAGE}"
fi
# If the environment variables set by the previous step indicate
# exit is required, display the exit message and then exit.
if [ -n "${SOLR_AGENT_NEEDS_EXIT}" ]; then
echo >&2 -e "${SOLR_AGENT_EXIT_MESSAGE}"
err_msg_contact_community
exit 1;
fi
# Call a function to locate the agent properties. If the function is
# unable to analyze things to decide how to operate, it will abort the
# script.
find_agent_properties_or_exit