Skip to content

Apache Lucene open-source search software

SOLR-7018: bin/solr stop should stop if there is only one node running or generate an error message prompting the user to be explicit about which of multiple nodes to stop using the -p or -all options

Timothy Potter69dd5e42f2a1
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b47d3fc9da2..5fda6a09c6a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -803,6 +803,10 @@ Other Changes
* SOLR-6521: CloudSolrClient should synchronize cache cluster state loading
( Noble Paul, Jessica Cheng Mallet)
+* SOLR-7018: bin/solr stop should stop if there is only one node running or generate
+ an error message prompting the user to be explicit about which of multiple nodes
+ to stop using the -p or -all options (Timothy Potter)
+
================== 4.10.3 ==================
Bug Fixes
diff --git a/solr/bin/solr b/solr/bin/solr
index ad7f4a148b6..01db4255fef 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -1060,8 +1060,10 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "$SOLR_PORT" ]]; then
else
# 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
- if [ -e "$SOLR_PID_DIR/solr-8983.pid" ]; then
- PID=`cat $SOLR_PID_DIR/solr-8983.pid`
+ 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 -all
+ PID=`find $SOLR_PID_DIR -name "solr-*.pid" -type f -exec cat {} \;`
CHECK_PID=`ps auxww | awk '{print $2}' | grep $PID | sort -r | tr -d ' '`
if [ "$CHECK_PID" != "" ]; then
port=`jetty_port "$CHECK_PID"`
@@ -1069,11 +1071,15 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "$SOLR_PORT" ]]; then
stop_solr "$SOLR_SERVER_DIR" "$port" "$STOP_KEY" "$CHECK_PID"
none_stopped=false
fi
- rm -f $SOLR_PID_DIR/solr-8983.pid
fi
fi
+
if $none_stopped; then
- echo -e "\nMust either specify a port using -p or -all to stop all Solr nodes on this host.\nUse the status command to see if any Solr nodes are running."
+ 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
exit 1
fi
fi