Apache Solr open-source search software
SOLR-9509 Fix problems reported by shellcheck (#1225)
Jan Høydahl025c0305fa82
diff --git a/solr/bin/solr b/solr/bin/solrold mode 100755new mode 100644index a73e2403c59..73394d66a56--- a/solr/bin/solr+++ b/solr/bin/solr@@ -48,7 +48,7 @@SOLR_SCRIPT="$0"verbose=false-THIS_OS=`uname -s`+THIS_OS=$(uname -s)# What version of Java is required to run this version of Solr.JAVA_VER_REQ=11@@ -62,6 +62,7 @@ if [ "${THIS_OS:0:6}" == "CYGWIN" ]; thenexit 1fi# Alpine Linux BusyBox comes with a stripped down ps, make sure we have a fully featured one+# shellcheck disable=SC2046if [ $$ -ne $(ps -o pid='' -p $$ || echo 0) ] ; thenecho -e "This script relies on a version of ps that supports the -p flag.\n\nPlease install a POSIX compliant version and try again."exit 1@@ -73,25 +74,26 @@ fi# Resolve symlinks to this scriptwhile [ -h "$SOLR_SCRIPT" ] ; do- ls=`ls -ld "$SOLR_SCRIPT"`+ ls=$(ls -ld "$SOLR_SCRIPT")# Drop everything prior to ->- link=`expr "$ls" : '.*-> \(.*\)$'`+ link=$(expr "$ls" : '.*-> \(.*\)$')if expr "$link" : '/.*' > /dev/null; thenSOLR_SCRIPT="$link"else- SOLR_SCRIPT=`dirname "$SOLR_SCRIPT"`/"$link"+ SOLR_SCRIPT=$(dirname "$SOLR_SCRIPT")/"$link"fidoneCDPATH='' # Prevent "file or directory not found" for 'cdpath' users-SOLR_TIP=`dirname "$SOLR_SCRIPT"`/..-SOLR_TIP=`cd "$SOLR_TIP"; pwd`+SOLR_TIP=$(dirname "$SOLR_SCRIPT")/..+# shellcheck disable=SC2164+SOLR_TIP=$(cd "$SOLR_TIP"; pwd)DEFAULT_SERVER_DIR="$SOLR_TIP/server"# If an include wasn't specified in the environment, then search for one...if [[ -z "${SOLR_INCLUDE:-}" ]]; then# Locations (in order) to use when searching for an include file.- for include in "`dirname "$0"`/solr.in.sh" \+ 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 \@@ -109,7 +111,7 @@ elif [ -r "$SOLR_INCLUDE" ]; thenfi# if pid dir is unset, deafult to $solr_tip/bin-: ${SOLR_PID_DIR:=$SOLR_TIP/bin}+: "${SOLR_PID_DIR:=$SOLR_TIP/bin}"if [ -n "${SOLR_JAVA_HOME:-}" ]; thenJAVA="$SOLR_JAVA_HOME/bin/java"@@ -140,11 +142,12 @@ elseJSTACK=jstackfi-: ${SOLR_STOP_WAIT:=180}-: ${SOLR_START_WAIT:=$SOLR_STOP_WAIT} # defaulting to $SOLR_STOP_WAIT for backwards compatibility reasons+: "${SOLR_STOP_WAIT:=180}"+: "${SOLR_START_WAIT:=$SOLR_STOP_WAIT}" # defaulting to $SOLR_STOP_WAIT for backwards compatibility reasons# test that Java exists, is executable and correct versionJAVA_VER=$("$JAVA" -version 2>&1)+# shellcheck disable=SC2181if [[ $? -ne 0 ]] ; thenecho >&2 "Java not found, or an error was encountered when running java."echo >&2 "A working Java $JAVA_VER_REQ JRE is required to run Solr!"@@ -158,7 +161,7 @@ if [[ $? -ne 0 ]] ; thenecho >&2 "${PATH}"exit 1else- JAVA_VER_NUM=$(echo $JAVA_VER | head -1 | awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//')+ JAVA_VER_NUM=$(echo "$JAVA_VER" | head -1 | awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//')if [[ "$JAVA_VER_NUM" -lt "$JAVA_VER_REQ" ]] ; thenecho >&2 "Your current version of Java is too old to run this version of Solr."echo >&2 "We found major version $JAVA_VER_NUM, using command '${JAVA} -version', with response:"@@ -174,7 +177,7 @@ elsefiJAVA_VENDOR="Oracle"# OpenJ9 was previously known as IBM J9, this will match both- if [ "`echo $JAVA_VER | grep -i -E "OpenJ9|IBM J9"`" != "" ]; then+ if [ "$(echo "$JAVA_VER" | grep -i -E "OpenJ9|IBM J9")" != "" ]; thenJAVA_VENDOR="OpenJ9"fifi@@ -299,7 +302,7 @@ if [ -n "${SOLR_AUTH_TYPE:-}" ] && [ -n "${SOLR_AUTHENTICATION_CLIENT_BUILDER:-}fiif [ -n "${SOLR_AUTH_TYPE:-}" ]; then- case "$(echo $SOLR_AUTH_TYPE | awk '{print tolower($0)}')" in+ case "$(echo "$SOLR_AUTH_TYPE" | awk '{print tolower($0)}')" inbasic)SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory";;@@ -686,8 +689,9 @@ function print_short_zk_usage() {function spinner() {local pid=$1local delay=0.5+ # shellcheck disable=SC1003local spinstr='|/-\'- while ps -o pid='' -p $pid &> /dev/null ; do+ while ps -o pid='' -p "$pid" &> /dev/null ; dolocal temp=${spinstr#?}printf " [%c] " "$spinstr"local spinstr=$temp${spinstr%"$temp"}@@ -701,10 +705,10 @@ function spinner() {function solr_pid_by_port() {THE_PORT="$1"if [ -e "$SOLR_PID_DIR/solr-$THE_PORT.pid" ]; then- PID=`cat "$SOLR_PID_DIR/solr-$THE_PORT.pid"`- CHECK_PID=`ps -o pid='' -p $PID | tr -d ' '`+ PID=$(cat "$SOLR_PID_DIR/solr-$THE_PORT.pid")+ CHECK_PID=$(ps -o pid='' -p "$PID" | tr -d ' ')if [ -n "$CHECK_PID" ]; then- echo $PID+ echo "$PID"fifi}@@ -712,7 +716,7 @@ function solr_pid_by_port() {# extract the value of the -Djetty.port parameter from a running Solr processfunction jetty_port() {SOLR_PID="$1"- SOLR_PROC=`ps -o command='' -p "$SOLR_PID" | grep start\.jar | grep jetty\.port`+ SOLR_PROC=$(ps -o command='' -p "$SOLR_PID" | grep start\.jar | grep jetty\.port)IFS=' ' read -a proc_args <<< "$SOLR_PROC"for arg in "${proc_args[@]}"do@@ -729,6 +733,7 @@ function jetty_port() {# useful for doing cross-platform work from the command-line using Javafunction run_tool() {+ # shellcheck disable=SC2086"$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS ${SOLR_ZK_CREDS_AND_ACLS:-} -Dsolr.install.dir="$SOLR_TIP" \-Dlog4j.configurationFile="$DEFAULT_SERVER_DIR/resources/log4j2-console.xml" \-classpath "$DEFAULT_SERVER_DIR/solr-webapp/webapp/WEB-INF/lib/*:$DEFAULT_SERVER_DIR/lib/ext/*:$DEFAULT_SERVER_DIR/lib/*" \@@ -741,13 +746,13 @@ function run_tool() {function get_info() {CODE=4# first, see if Solr is running- numSolrs=`find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' '`+ numSolrs=$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' ')if [ "$numSolrs" != "0" ]; thenecho -e "\nFound $numSolrs Solr nodes: "while read PIDFdo- ID=`cat "$PIDF"`- port=`jetty_port "$ID"`+ ID=$(cat "$PIDF")+ port=$(jetty_port "$ID")if [ "$port" != "" ]; thenecho -e "\nSolr process $ID running on port $port"run_tool status -solr "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr"@@ -760,13 +765,13 @@ function get_info() {done < <(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)else# no pid files but check using ps just to be sure- numSolrs=`ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//'`+ numSolrs=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//')if [ "$numSolrs" != "0" ]; thenecho -e "\nFound $numSolrs Solr nodes: "PROCESSES=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | awk '{print $2}' | sort -r)for ID in $PROCESSESdo- port=`jetty_port "$ID"`+ port=$(jetty_port "$ID")if [ "$port" != "" ]; thenecho ""echo "Solr process $ID running on port $port"@@ -787,13 +792,13 @@ function get_info() {function run_package() {runningSolrUrl=""- numSolrs=`find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' '`+ numSolrs=$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' ')if [ "$numSolrs" != "0" ]; then#echo -e "\nFound $numSolrs Solr nodes: "while read PIDFdo- ID=`cat "$PIDF"`- port=`jetty_port "$ID"`+ ID=$(cat "$PIDF")+ port=$(jetty_port "$ID")if [ "$port" != "" ]; then#echo -e "\nSolr process $ID running on port $port"runningSolrUrl="$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$port/solr"@@ -807,13 +812,13 @@ function run_package() {done < <(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)else# no pid files but check using ps just to be sure- numSolrs=`ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//'`+ numSolrs=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | wc -l | sed -e 's/^[ \t]*//')if [ "$numSolrs" != "0" ]; thenecho -e "\nFound $numSolrs Solr nodes: "PROCESSES=$(ps auxww | grep start\.jar | grep solr\.solr\.home | grep -v grep | awk '{print $2}' | sort -r)for ID in $PROCESSESdo- port=`jetty_port "$ID"`+ port=$(jetty_port "$ID")if [ "$port" != "" ]; thenecho ""echo "Solr process $ID running on port $port"@@ -841,12 +846,13 @@ function stop_solr() {DIR="$1"SOLR_PORT="$2"- THIS_STOP_PORT="${STOP_PORT:-$(expr $SOLR_PORT - 1000)}"+ THIS_STOP_PORT="${STOP_PORT:-$((SOLR_PORT - 1000))}"STOP_KEY="$3"SOLR_PID="$4"if [ -n "$SOLR_PID" ]; thenecho -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."+ # shellcheck disable=SC2086"$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS -jar "$DIR/start.jar" "STOP.PORT=$THIS_STOP_PORT" "STOP.KEY=$STOP_KEY" --stop || true(loops=0while true@@ -854,12 +860,13 @@ function stop_solr() {# Check if a process is running with the specified PID.# -o stat will output the STAT, where Z indicates a zombie# stat='' removes the header (--no-headers isn't supported on all platforms)- STAT=`(ps -o stat='' -p $SOLR_PID || :) | tr -d ' '`+ # Note the space after '$('. It is needed to avoid confusion with special bash eval syntax+ STAT=$( (ps -o stat='' -p "$SOLR_PID" || :) | tr -d ' ')if [[ "${STAT:-Z}" != "Z" ]]; thenslept=$((loops * 2))if [ $slept -lt $SOLR_STOP_WAIT ]; thensleep 2- loops=$[$loops+1]+ loops=$((loops+1))elseexit # subshell!fi@@ -874,23 +881,25 @@ function stop_solr() {exit 0fi- STAT=`(ps -o stat='' -p $SOLR_PID || :) | tr -d ' '`+ # Note the space after '$('. It is needed to avoid confusion with special bash eval syntax+ STAT=$( (ps -o stat='' -p "$SOLR_PID" || :) | tr -d ' ')if [[ "${STAT:-Z}" != "Z" ]]; thenif [ -n "${JSTACK:-}" ]; thenecho -e "Solr process $SOLR_PID is still running; jstacking it now."- $JSTACK $SOLR_PID+ $JSTACK "$SOLR_PID"elif [ "$JATTACH" != "" ]; thenecho -e "Solr process $SOLR_PID is still running; jattach threaddumping it now."- $JATTACH $SOLR_PID threaddump+ $JATTACH "$SOLR_PID" threaddumpfiecho -e "Solr process $SOLR_PID is still running; forcefully killing it now."- kill -9 $SOLR_PID+ kill -9 "$SOLR_PID"echo "Killed process $SOLR_PID"rm -f "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"sleep 10fi- STAT=`(ps -o stat='' -p $SOLR_PID || :) | tr -d ' '`+ # Note the space after '$('. It is needed to avoid confusion with special bash eval syntax+ STAT=$( (ps -o stat='' -p "$SOLR_PID" || :) | tr -d ' ')if [ "${STAT:-}" == "Z" ]; then# This can happen if, for example, you are running Solr inside a docker container with multiple processes# rather than running it is as the only service. The --init flag on docker avoids that particular problem.@@ -943,7 +952,7 @@ fi# assert toolif [ "$SCRIPT_CMD" == "assert" ]; then- run_tool assert $*+ run_tool assert "$@"exit $?fi@@ -1140,7 +1149,7 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CMdonefi- : ${CREATE_CONFDIR:=_default}+ : "${CREATE_CONFDIR:=_default}"# validate the confdir arg (if provided)if [[ ! -d "$SOLR_TIP/server/solr/configsets/$CREATE_CONFDIR" && ! -d "$CREATE_CONFDIR" ]]; then@@ -1155,9 +1164,9 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CMfiif [ -z "${CREATE_PORT:-}" ]; then- for ID in `ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r`+ for ID in $(ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r)do- port=`jetty_port "$ID"`+ port=$(jetty_port "$ID")if [ "$port" != "" ]; thenCREATE_PORT=$portbreak@@ -1259,12 +1268,12 @@ if [[ "$SCRIPT_CMD" == "delete" ]]; thenfi# If not defined, use the collection name for the name of the configuration in Zookeeper- : ${DELETE_CONFIG:=true}+ : "${DELETE_CONFIG:=true}"if [ -z "${DELETE_PORT:-}" ]; then- for ID in `ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r`+ for ID in $(ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r)do- port=`jetty_port "$ID"`+ port=$(jetty_port "$ID")if [ "$port" != "" ]; thenDELETE_PORT=$portbreak@@ -1471,7 +1480,7 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; thenshift 2;;-config)- AUTH_CONFIG="`echo $2| base64`"+ AUTH_CONFIG="$(echo "$2"| base64)"AUTH_PARAMS=("${AUTH_PARAMS[@]}" "-config" "$AUTH_CONFIG")shift 2;;@@ -1512,7 +1521,7 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; thenfifi# resolve it to an absolute path- SOLR_SERVER_DIR="$(cd "$SOLR_SERVER_DIR"; pwd)"+ SOLR_SERVER_DIR="$(cd "$SOLR_SERVER_DIR" || (echo "SOLR_SERVER_DIR not found" && exit 1); pwd)"shift 2;;-s|-solr.home)@@ -1540,7 +1549,7 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; thendonefi- : ${SOLR_SERVER_DIR:=$DEFAULT_SERVER_DIR}+ : "${SOLR_SERVER_DIR:=$DEFAULT_SERVER_DIR}"if [ ! -e "$SOLR_SERVER_DIR" ]; thenecho -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n"exit 1@@ -1549,7 +1558,7 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; thenif [ -z "${SOLR_HOME:-}" ]; thenSOLR_HOME="$SOLR_SERVER_DIR/solr"elif [[ $SOLR_HOME != /* ]]; then- if [[ -d "`pwd`/$SOLR_HOME" ]]; then+ if [[ -d "$(pwd)/$SOLR_HOME" ]]; thenSOLR_HOME="$(pwd)/$SOLR_HOME"elif [[ -d "$SOLR_SERVER_DIR/$SOLR_HOME" ]]; thenSOLR_HOME="$SOLR_SERVER_DIR/$SOLR_HOME"@@ -1565,9 +1574,9 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; thenAUTH_PARAMS=("${AUTH_PARAMS[@]}" "-solrIncludeFile" "$SOLR_INCLUDE")if [ -z "${AUTH_PORT:-}" ]; then- for ID in `ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r`+ for ID in $(ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r)do- port=`jetty_port "$ID"`+ port=$(jetty_port "$ID")if [ "$port" != "" ]; thenAUTH_PORT=$portbreak@@ -1582,14 +1591,14 @@ fi# verify the command given is supportedif [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD" != "restart" ] && [ "$SCRIPT_CMD" != "status" ] && [ "$SCRIPT_CMD" != "assert" ]; then# handoff this command to the SolrCLI and let it handle the option parsing and validation- run_tool $SCRIPT_CMD "$@"+ run_tool "$SCRIPT_CMD" "$@"exit $?fi#Check current Ulimits for Open Files and Max Processes. Warn if they are below the recommended values.-: ${SOLR_RECOMMENDED_MAX_PROCESSES:=65000}-: ${SOLR_RECOMMENDED_OPEN_FILES:=65000}+: "${SOLR_RECOMMENDED_MAX_PROCESSES:=65000}"+: "${SOLR_RECOMMENDED_OPEN_FILES:=65000}"if [[ "${SOLR_ULIMIT_CHECKS:-}" != "false" ]]; thenif [ "$SCRIPT_CMD" == "start" ] || [ "$SCRIPT_CMD" == "restart" ] || [ "$SCRIPT_CMD" == "status" ]; then@@ -1598,23 +1607,23 @@ if [[ "${SOLR_ULIMIT_CHECKS:-}" != "false" ]]; thenmaxProcs=$(ulimit -u)virtualMemory=$(ulimit -v)maxMemory=$(ulimit -m)- if [ $openFiles != "unlimited" ] && [ $openFiles -lt "$SOLR_RECOMMENDED_OPEN_FILES" ]; then+ if [ "$openFiles" != "unlimited" ] && [ "$openFiles" -lt "$SOLR_RECOMMENDED_OPEN_FILES" ]; thenecho "*** [WARN] *** Your open file limit is currently $openFiles. "echo " It should be set to $SOLR_RECOMMENDED_OPEN_FILES to avoid operational disruption. "echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"fi- if [ $maxProcs != "unlimited" ] && [ $maxProcs -lt "$SOLR_RECOMMENDED_MAX_PROCESSES" ]; then+ if [ "$maxProcs" != "unlimited" ] && [ "$maxProcs" -lt "$SOLR_RECOMMENDED_MAX_PROCESSES" ]; thenecho "*** [WARN] *** Your Max Processes Limit is currently $maxProcs. "echo " It should be set to $SOLR_RECOMMENDED_MAX_PROCESSES to avoid operational disruption. "echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"fi- if [ $virtualMemory != "unlimited" ]; then+ if [ "$virtualMemory" != "unlimited" ]; thenecho "*** [WARN] *** Your Virtual Memory limit is $virtualMemory. "echo " It should be set to 'unlimited' to avoid operational disruption. "echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"fi- if [ $maxMemory != "unlimited" ]; then+ if [ "$maxMemory" != "unlimited" ]; thenecho "*** [WARN] *** Your Max Memory Size limit is $maxMemory. "echo " It should be set to 'unlimited' to avoid operational disruption. "echo " If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh"@@ -1633,7 +1642,6 @@ fi# Run in foreground (default is to run in the background)FG="false"FORCE=false-noprompt=falseSOLR_OPTS=(${SOLR_OPTS:-})PASS_TO_RUN_EXAMPLE=@@ -1662,7 +1670,7 @@ if [ $# -gt 0 ]; thenfifi# resolve it to an absolute path- SOLR_SERVER_DIR="$(cd "$SOLR_SERVER_DIR"; pwd)"+ SOLR_SERVER_DIR="$(cd "$SOLR_SERVER_DIR" || (echo "SOLR_SERVER_DIR not found" && exit 1); pwd)"shift 2;;-s|-solr.home)@@ -1746,7 +1754,6 @@ if [ $# -gt 0 ]; thenexit 0;;-noprompt)- noprompt=truePASS_TO_RUN_EXAMPLE+=" -noprompt"shift;;@@ -1826,7 +1833,7 @@ fi# 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+ run_tool run_example -e "$EXAMPLE" -d "$SOLR_SERVER_DIR" -urlScheme "$SOLR_URL_SCHEME" "$PASS_TO_RUN_EXAMPLE"exit $?fi@@ -1847,7 +1854,7 @@ elseSOLR_HOST_ARG=()fi-: ${STOP_KEY:=solrrocks}+: "${STOP_KEY:=solrrocks}"# stop all if no port specifiedif [[ "$SCRIPT_CMD" == "stop" && -z "${SOLR_PORT:-}" ]]; then@@ -1855,8 +1862,8 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "${SOLR_PORT:-}" ]]; thennone_stopped=truefind "$SOLR_PID_DIR" -name "solr-*.pid" -type f | while read PIDFdo- NEXT_PID=`cat "$PIDF"`- port=`jetty_port "$NEXT_PID"`+ NEXT_PID=$(cat "$PIDF")+ port=$(jetty_port "$NEXT_PID")if [ "$port" != "" ]; thenstop_solr "$SOLR_SERVER_DIR" "$port" "$STOP_KEY" "$NEXT_PID"none_stopped=false@@ -1871,13 +1878,13 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "${SOLR_PORT:-}" ]]; thenelse# not stopping all and don't have a port, but if we can find the pid file for the default port 8983, then use thatnone_stopped=true- numSolrs=`find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' '`- if [ $numSolrs -eq 1 ]; then+ numSolrs=$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f | wc -l | tr -d ' ')+ if [ "$numSolrs" -eq 1 ]; then# only do this if there is only 1 node running, otherwise they must provide the -p or -allPID="$(cat "$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)")"- CHECK_PID=`ps -o pid='' -p $PID | tr -d ' '`+ CHECK_PID=$(ps -o pid='' -p "$PID" | tr -d ' ')if [ "$CHECK_PID" != "" ]; then- port=`jetty_port "$CHECK_PID"`+ port=$(jetty_port "$CHECK_PID")if [ "$port" != "" ]; thenstop_solr "$SOLR_SERVER_DIR" "$port" "$STOP_KEY" "$CHECK_PID"none_stopped=false@@ -1886,7 +1893,7 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "${SOLR_PORT:-}" ]]; thenfiif $none_stopped; then- if [ $numSolrs -gt 0 ]; then+ if [ "$numSolrs" -gt 0 ]; thenecho -e "\nFound $numSolrs Solr nodes running! Must either specify a port using -p or -all to stop all Solr nodes on this host.\n"elseecho -e "\nNo Solr nodes found to stop.\n"@@ -1897,7 +1904,7 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "${SOLR_PORT:-}" ]]; thenexitfi-: ${SOLR_PORT:=8983}+: "${SOLR_PORT:=8983}"if [ -n "${SOLR_PORT_ADVERTISE:-}" ]; thenSOLR_OPTS+=("-Dsolr.port.advertise=$SOLR_PORT_ADVERTISE")@@ -1907,7 +1914,7 @@ if [ -n "${SOLR_JETTY_HOST:-}" ]; thenSOLR_OPTS+=("-Dsolr.jetty.host=$SOLR_JETTY_HOST")fi-: ${STOP_PORT:=`expr $SOLR_PORT - 1000`}+: "${STOP_PORT:=$((SOLR_PORT - 1000))}"if [ "$SCRIPT_CMD" == "start" ] || [ "$SCRIPT_CMD" == "restart" ] ; thenif [[ $EUID -eq 0 ]] && [[ "$FORCE" == "false" ]] ; then@@ -1919,11 +1926,11 @@ fiif [[ "$SCRIPT_CMD" == "start" ]]; then# see if Solr is already running- SOLR_PID=`solr_pid_by_port "$SOLR_PORT"`+ SOLR_PID=$(solr_pid_by_port "$SOLR_PORT")if [ -z "${SOLR_PID:-}" ]; then# not found using the pid file ... but use ps to ensure not found- SOLR_PID=`ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' {print $2}' | sort -r`+ SOLR_PID=$(ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' {print $2}' | sort -r)fiif [ -n "${SOLR_PID:-}" ]; then@@ -1933,10 +1940,10 @@ if [[ "$SCRIPT_CMD" == "start" ]]; thenelse# either stop or restart# see if Solr is already running- SOLR_PID=`solr_pid_by_port "$SOLR_PORT"`+ SOLR_PID=$(solr_pid_by_port "$SOLR_PORT")if [ -z "$SOLR_PID" ]; then# not found using the pid file ... but use ps to ensure not found- SOLR_PID=`ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' {print $2}' | sort -r`+ SOLR_PID=$(ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' {print $2}' | sort -r)fiif [ "$SOLR_PID" != "" ]; thenstop_solr "$SOLR_SERVER_DIR" "$SOLR_PORT" "$STOP_KEY" "$SOLR_PID"@@ -1951,7 +1958,7 @@ fiif [ -z "${SOLR_HOME:-}" ]; thenSOLR_HOME="$SOLR_SERVER_DIR/solr"elif [[ $SOLR_HOME != /* ]]; then- if [[ -d "`pwd`/$SOLR_HOME" ]]; then+ if [[ -d "$(pwd)/$SOLR_HOME" ]]; thenSOLR_HOME="$(pwd)/$SOLR_HOME"elif [[ -d "$SOLR_SERVER_DIR/$SOLR_HOME" ]]; thenSOLR_HOME="$SOLR_SERVER_DIR/$SOLR_HOME"@@ -1960,11 +1967,11 @@ elif [[ $SOLR_HOME != /* ]]; thenfi# Set the default configset dir to be bootstrapped as _default-: ${DEFAULT_CONFDIR:="$SOLR_SERVER_DIR/solr/configsets/_default/conf"}+: "${DEFAULT_CONFDIR:="$SOLR_SERVER_DIR/solr/configsets/_default/conf"}"# This is quite hacky, but examples rely on a different log4j2.xml# so that we can write logs for examples to $SOLR_HOME/../logs-: ${SOLR_LOGS_DIR:="$SOLR_SERVER_DIR/logs"}+: "${SOLR_LOGS_DIR:="$SOLR_SERVER_DIR/logs"}"EXAMPLE_DIR="$SOLR_TIP/example"# if SOLR_HOME is inside of EXAMPLE_DIRif [ "${SOLR_HOME:0:${#EXAMPLE_DIR}}" = "$EXAMPLE_DIR" ]; then@@ -1994,7 +2001,7 @@ if [[ -n ${SOLR_DATA_HOME:-} ]] && [ ! -e "$SOLR_DATA_HOME" ]; thenfi# Establish default GC logging opts if no env var set (otherwise init to sensible default)-if [ -z ${GC_LOG_OPTS+x} ]; then+if [ -z "${GC_LOG_OPTS}" ]; thenif [[ "$JAVA_VER_NUM" -lt "9" ]] ; thenGC_LOG_OPTS=('-verbose:gc' '-XX:+PrintHeapAtGC' '-XX:+PrintGCDetails' \'-XX:+PrintGCDateStamps' '-XX:+PrintGCTimeStamps' '-XX:+PrintTenuringDistribution' \@@ -2003,11 +2010,13 @@ if [ -z ${GC_LOG_OPTS+x} ]; thenGC_LOG_OPTS=('-Xlog:gc*')fielse+ # TODO: Should probably not overload GC_LOG_OPTS as both string and array, but leaving it be for now+ # shellcheck disable=SC2128GC_LOG_OPTS=($GC_LOG_OPTS)fi# if verbose gc logging enabled, setup the location of the log file and rotation-if [ "$GC_LOG_OPTS" != "" ]; then+if [ "${#GC_LOG_OPTS[@]}" -gt 0 ]; thenif [[ "$JAVA_VER_NUM" -lt "9" ]] || [ "$JAVA_VENDOR" == "OpenJ9" ]; thengc_log_flag="-Xloggc"if [ "$JAVA_VENDOR" == "OpenJ9" ]; then@@ -2025,7 +2034,8 @@ if [ "$GC_LOG_OPTS" != "" ]; then# for simplicity, we only look at the prefix '-Xlog:gc'# (if 'all' or multiple tags are used starting with anything other then 'gc' the user is on their own)# if a single additional ':' exists in param, then there is already an explicit output specifier- 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|")+ # shellcheck disable=SC2001+ 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|")donefifi@@ -2036,7 +2046,7 @@ if [[ -n "${ZK_HOST:-}" ]]; thenfiif [ "${SOLR_MODE:-}" == 'solrcloud' ]; then- : ${ZK_CLIENT_TIMEOUT:=30000}+ : "${ZK_CLIENT_TIMEOUT:=30000}"CLOUD_MODE_OPTS=("-DzkClientTimeout=$ZK_CLIENT_TIMEOUT")if [ -n "${ZK_HOST:-}" ]; then@@ -2082,7 +2092,7 @@ IP_ACL_OPTS=("-Dsolr.jetty.inetaccess.includes=${SOLR_IP_ALLOWLIST:-}" \if [ "${ENABLE_REMOTE_JMX_OPTS:-false}" == "true" ]; thenif [ -z "$RMI_PORT" ]; then- RMI_PORT=`expr $SOLR_PORT + 10000`+ RMI_PORT=$((SOLR_PORT + 10000))if [ $RMI_PORT -gt 65535 ]; thenecho -e "\nRMI_PORT is $RMI_PORT, which is invalid!\n"exit 1@@ -2133,7 +2143,7 @@ fi# Pick default for Java thread stack size, and then add to SOLR_OPTSSOLR_OPTS+=(${SOLR_JAVA_STACK_SIZE:-"-Xss256k"})-: ${SOLR_TIMEZONE:=UTC}+: "${SOLR_TIMEZONE:=UTC}"function mk_writable_dir() {local DIRNAME="$1"@@ -2158,8 +2168,8 @@ function start_solr() {SOLR_JETTY_ADDL_CONFIG="$3"# define default GC_TUNE- if [ -z ${GC_TUNE+x} ]; then # I think this check is backwards?- GC_TUNE=('-XX:+UseG1GC' \+ if [ -z "${GC_TUNE}" ]; then+ GC_TUNE_ARR=('-XX:+UseG1GC' \'-XX:+PerfDisableSharedMem' \'-XX:+ParallelRefProcEnabled' \'-XX:MaxGCPauseMillis=250' \@@ -2167,7 +2177,8 @@ function start_solr() {'-XX:+AlwaysPreTouch' \'-XX:+ExplicitGCInvokesConcurrent')else- GC_TUNE=($GC_TUNE)+ # shellcheck disable=SC2128+ GC_TUNE_ARR=($GC_TUNE) # Stuff the string from outside into first value of the arrayfiif [ -n "${SOLR_WAIT_FOR_ZK:-}" ]; then@@ -2209,7 +2220,7 @@ function start_solr() {echo -e " SOLR_PORT = $SOLR_PORT"echo -e " STOP_PORT = $STOP_PORT"echo -e " JAVA_MEM_OPTS = ${JAVA_MEM_OPTS[*]}"- echo -e " GC_TUNE = ${GC_TUNE[*]}"+ echo -e " GC_TUNE = ${GC_TUNE_ARR[*]}"echo -e " GC_LOG_OPTS = ${GC_LOG_OPTS[*]}"echo -e " SOLR_TIMEZONE = $SOLR_TIMEZONE"@@ -2242,7 +2253,7 @@ function start_solr() {fi# need to launch solr from the server dir- cd "$SOLR_SERVER_DIR"+ cd "$SOLR_SERVER_DIR" || (echo -e "\nCd to SOLR_SERVER_DIR failed" && exit 1)if [ ! -e "$SOLR_SERVER_DIR/start.jar" ]; thenecho -e "\nERROR: start.jar file not found in $SOLR_SERVER_DIR!\nPlease check your -d parameter to set the correct Solr server directory.\n"@@ -2261,7 +2272,7 @@ function start_solr() {echo "Java $JAVA_VER_NUM detected. Added --enable-preview to enable MemorySegment support in MMapDirectory. See SOLR-16500"fi- SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE[@]}" "${GC_LOG_OPTS[@]}" "${IP_ACL_OPTS[@]}" \+ SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE_ARR[@]}" "${GC_LOG_OPTS[@]}" "${IP_ACL_OPTS[@]}" \"${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" ${SOLR_LOG_LEVEL_OPT:-} -Dsolr.log.dir="$SOLR_LOGS_DIR" \"-Djetty.port=$SOLR_PORT" "-DSTOP.PORT=$stop_port" "-DSTOP.KEY=$STOP_KEY" \# '-OmitStackTraceInFastThrow' ensures stack traces in errors,@@ -2285,15 +2296,17 @@ function start_solr() {esacif [ "$run_in_foreground" == "true" ]; then+ # shellcheck disable=SC2086exec "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -jar start.jar "${SOLR_JETTY_CONFIG[@]}" $SOLR_JETTY_ADDL_CONFIGelse# run Solr in the background+ # shellcheck disable=SC2086nohup "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -Dsolr.log.muteconsole \-jar start.jar "${SOLR_JETTY_CONFIG[@]}" $SOLR_JETTY_ADDL_CONFIG \1>"$SOLR_LOGS_DIR/solr-$SOLR_PORT-console.log" 2>&1 & echo $! > "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"# 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- if [[ -f /proc/sys/kernel/random/entropy_avail ]] && (( `cat /proc/sys/kernel/random/entropy_avail` < 300)); then+ if [[ -f /proc/sys/kernel/random/entropy_avail ]] && (( $(cat /proc/sys/kernel/random/entropy_avail) < 300)); thenecho "Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require"echo "RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'."echo ""@@ -2310,14 +2323,14 @@ function start_solr() {slept=$((loops * 2))if [ $slept -lt $SOLR_START_WAIT ]; thensleep 2- loops=$[$loops+1]+ loops=$((loops+1))elseecho -e "Still not seeing Solr listening on $SOLR_PORT after $SOLR_START_WAIT seconds!"tail -30 "$SOLR_LOGS_DIR/solr.log"exit # subshell!fielse- SOLR_PID=`ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' {print $2}' | sort -r`+ SOLR_PID=$(ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' {print $2}' | sort -r)echo -e "\nStarted Solr server on port $SOLR_PORT (pid=$SOLR_PID). Happy searching!\n"exit # subshell!fi@@ -2326,7 +2339,7 @@ function start_solr() {elseecho -e "NOTE: Please install lsof as this script needs it to determine if Solr is listening on port $SOLR_PORT."sleep 10- SOLR_PID=`ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' {print $2}' | sort -r`+ SOLR_PID=$(ps auxww | grep start\.jar | awk "/\-Djetty\.port=$SOLR_PORT/"' {print $2}' | sort -r)echo -e "\nStarted Solr server on port $SOLR_PORT (pid=$SOLR_PID). Happy searching!\n"return;fi