You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by md...@apache.org on 2022/05/19 18:43:01 UTC

[solr] branch branch_9_0 updated (f452bf6dbea -> 4e0d2497c86)

This is an automated email from the ASF dual-hosted git repository.

mdrob pushed a change to branch branch_9_0
in repository https://gitbox.apache.org/repos/asf/solr.git


    from f452bf6dbea Update CHANGES entry to match 8.11
     new 920871dc4c2 SOLR-16191: Verify that ps supports -p (#867)
     new 4e0d2497c86 SOLR-16206: bats require minimum version 1.5.0

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 solr/CHANGES.txt                     |  4 +++-
 solr/bin/solr                        | 19 ++++++++++++-------
 solr/packaging/test/bats_helper.bash |  2 ++
 3 files changed, 17 insertions(+), 8 deletions(-)


[solr] 01/02: SOLR-16191: Verify that ps supports -p (#867)

Posted by md...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mdrob pushed a commit to branch branch_9_0
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 920871dc4c2eeb1ef585812ad4387d7f958675f2
Author: Mike Drob <md...@apache.org>
AuthorDate: Thu May 19 10:09:08 2022 -0500

    SOLR-16191: Verify that ps supports -p (#867)
    
    (cherry picked from commit 83953a4d18b31f568c7967e3abf2d735723dc791)
---
 solr/CHANGES.txt |  4 +++-
 solr/bin/solr    | 19 ++++++++++++-------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 44bdb4c35e3..c080b262596 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -5,9 +5,11 @@ Most people will find the solr-upgrade-notes.adoc file more approachable.
 https://github.com/apache/solr/blob/main/solr/solr-ref-guide/modules/upgrade-notes/pages/solr-upgrade-notes.adoc
 
 ==================  9.0.1 ==================
+
 Bug Fixes
 ---------------------
-(No changes)
+
+* SOLR-16191: Validate that installed ps utility supports -p flag, so that we do not inadvertantly stop the wrong process. (Mike Drob, Michael Gibney)
 
 ==================  9.0.0 ==================
 
diff --git a/solr/bin/solr b/solr/bin/solr
index c1ef2af1e00..bfee9829acb 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -61,6 +61,11 @@ 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
+# Alpine Linux BusyBox comes with a stripped down ps, make sure we have a fully featured one
+if [ $$ -ne $(ps -o pid='' -p $$ || echo 0) ] ; then
+  echo -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
+fi
 
 # This helps with debugging when running bats tests but not the whole script is compliant yet
 # set -u
@@ -682,7 +687,7 @@ function spinner() {
   local pid=$1
   local delay=0.5
   local spinstr='|/-\'
-  while [ "$(ps aux | awk '{print $2}' | grep -w $pid)" ]; do
+  while ps -o pid='' -p $pid &> /dev/null ; do
       local temp=${spinstr#?}
       printf " [%c]  " "$spinstr"
       local spinstr=$temp${spinstr%"$temp"}
@@ -697,7 +702,7 @@ 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='' $PID | tr -d ' '`
+    CHECK_PID=`ps -o pid='' -p $PID | tr -d ' '`
     if [ -n "$CHECK_PID" ]; then
       echo $PID
     fi
@@ -707,7 +712,7 @@ function solr_pid_by_port() {
 # extract the value of the -Djetty.port parameter from a running Solr process
 function jetty_port() {
   SOLR_PID="$1"
-  SOLR_PROC=`ps auxww | grep -w $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
@@ -849,7 +854,7 @@ 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='' $SOLR_PID || :) | tr -d ' '`
+        STAT=`(ps -o stat='' -p $SOLR_PID || :) | tr -d ' '`
         if [[ "${STAT:-Z}" != "Z" ]]; then
           slept=$((loops * 2))
           if [ $slept -lt $SOLR_STOP_WAIT ]; then
@@ -869,7 +874,7 @@ function stop_solr() {
     exit 0
   fi
 
-  STAT=`(ps -o stat='' $SOLR_PID || :) | tr -d ' '`
+  STAT=`(ps -o stat='' -p $SOLR_PID || :) | tr -d ' '`
   if [[ "${STAT:-Z}" != "Z" ]]; then
     if [ -n "{$JSTACK:-}" ]; then
       echo -e "Solr process $SOLR_PID is still running; jstacking it now."
@@ -885,7 +890,7 @@ function stop_solr() {
     sleep 10
   fi
 
-  STAT=`(ps -o stat='' $SOLR_PID || :) | tr -d ' '`
+  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.
@@ -1860,7 +1865,7 @@ if [[ "$SCRIPT_CMD" == "stop" && -z "${SOLR_PORT:-}" ]]; then
     if [ $numSolrs -eq 1 ]; then
       # only do this if there is only 1 node running, otherwise they must provide the -p or -all
       PID="$(cat "$(find "$SOLR_PID_DIR" -name "solr-*.pid" -type f)")"
-      CHECK_PID=`ps -o pid='' $PID | tr -d ' '`
+      CHECK_PID=`ps -o pid='' -p $PID | tr -d ' '`
       if [ "$CHECK_PID" != "" ]; then
         port=`jetty_port "$CHECK_PID"`
         if [ "$port" != "" ]; then


[solr] 02/02: SOLR-16206: bats require minimum version 1.5.0

Posted by md...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mdrob pushed a commit to branch branch_9_0
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 4e0d2497c869939846394d7371728ad37ae19b2e
Author: Mike Drob <md...@apache.org>
AuthorDate: Thu May 19 13:40:35 2022 -0500

    SOLR-16206: bats require minimum version 1.5.0
---
 solr/packaging/test/bats_helper.bash | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/solr/packaging/test/bats_helper.bash b/solr/packaging/test/bats_helper.bash
index 99f92ded39c..d408af72808 100644
--- a/solr/packaging/test/bats_helper.bash
+++ b/solr/packaging/test/bats_helper.bash
@@ -20,6 +20,8 @@
 #   The SOLR_HOME directory will be cleared when the next test file is executed.
 # - "setup" should use "common_setup" if a Solr process is NOT being started in that same "setup" function.
 common_setup() {
+    bats_require_minimum_version 1.5.0
+
     if [ -z ${BATS_LIB_PREFIX:-} ]; then
         # Debugging help, if you want to run bats directly, try to detect where libraries might be
         if brew list bats-core; then