Apache Lucene open-source search software
SOLR-7450: Fix grep options used when searching for numbers in bin/solr
Ramkumar Aiyengare86dec20580b
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 57d92aa54a0..8ad9808154a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -165,6 +165,9 @@ Bug Fixes* SOLR-7408: Listeners set by SolrCores on config directories in ZK could be removed if collectionsare created/deleted in paralle against the same config set. (Shai Erera, Anshum Gupta)+* SOLR-7450: Fix edge case which could cause `bin/solr stop` to hang forever+ (Ramkumar Aiyengar)+Optimizations----------------------diff --git a/solr/bin/solr b/solr/bin/solrindex def681049dd..cd8d76702ff 100755--- a/solr/bin/solr+++ b/solr/bin/solr@@ -335,7 +335,7 @@ function spinner() {local pid=$1local delay=0.5local spinstr='|/-\'- while [ "$(ps aux | awk '{print $2}' | grep $pid)" ]; do+ while [ "$(ps aux | awk '{print $2}' | grep -w $pid)" ]; dolocal temp=${spinstr#?}printf " [%c] " "$spinstr"local spinstr=$temp${spinstr%"$temp"}@@ -350,7 +350,7 @@ function solr_pid_by_port() {THE_PORT="$1"if [ -e "$SOLR_PID_DIR/solr-$THE_PORT.pid" ]; thenPID=`cat "$SOLR_PID_DIR/solr-$THE_PORT.pid"`- CHECK_PID=`ps auxww | awk '{print $2}' | grep $PID | sort -r | tr -d ' '`+ CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $PID | sort -r | tr -d ' '`if [ "$CHECK_PID" != "" ]; thenlocal solrPID=$PIDfi@@ -361,7 +361,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 auxww | grep $SOLR_PID | grep start\.jar | grep jetty.port`+ SOLR_PROC=`ps auxww | grep -w $SOLR_PID | grep start\.jar | grep jetty.port`IFS=' ' read -a proc_args <<< "$SOLR_PROC"for arg in "${proc_args[@]}"do@@ -454,7 +454,7 @@ function stop_solr() {exit 0fi- CHECK_PID=`ps auxww | awk '{print $2}' | grep $SOLR_PID | sort -r | tr -d ' '`+ CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`if [ "$CHECK_PID" != "" ]; thenecho -e "Solr process $SOLR_PID is still running; forcefully killing it now."kill -9 $SOLR_PID@@ -463,7 +463,7 @@ function stop_solr() {sleep 1fi- CHECK_PID=`ps auxww | awk '{print $2}' | grep $SOLR_PID | sort -r | tr -d ' '`+ CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`if [ "$CHECK_PID" != "" ]; thenecho "ERROR: Failed to kill previous Solr Java process $SOLR_PID ... script fails."exit 1@@ -1082,7 +1082,7 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "$SOLR_PORT" ]]; thenif [ $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 auxww | awk '{print $2}' | grep $PID | sort -r | tr -d ' '`+ CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $PID | sort -r | tr -d ' '`if [ "$CHECK_PID" != "" ]; thenport=`jetty_port "$CHECK_PID"`if [ "$port" != "" ]; then@@ -1131,7 +1131,7 @@ elseSOLR_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 | grep $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`+ SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`fiif [ "$SOLR_PID" != "" ]; thenstop_solr "$SOLR_SERVER_DIR" "$SOLR_PORT" "$STOP_KEY" "$SOLR_PID"@@ -1377,14 +1377,14 @@ function launch_solr() {exitfielse- SOLR_PID=`ps auxww | grep start\.jar | grep $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`+ SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`echo -e "\nStarted Solr server on port $SOLR_PORT (pid=$SOLR_PID). Happy searching!\n"exitfidone) &spinner $!else- SOLR_PID=`ps auxww | grep start\.jar | grep $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`+ SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`echo -e "\nStarted Solr server on port $SOLR_PORT (pid=$SOLR_PID). Happy searching!\n"exit;fi