Change to the ongoing execution validation

In order to avoid multiple instances of the tool, the script searches
for some known processes names in local and remote hosts. However, the
search for a very broad pattern was causing false positives, leading to
the tool to exit even when no other instance was running.

This change provides a more strict search pattern, focusing only on
the exact process names used by the main script (local and remote).

TEST PLAN:
PASS: Successfully execution of the collect command.
PASS: Successfully blocks new instances and notifies the user if collect
      is started while another already is running on the same node.
PASS: Successfully identifies and notifies the user if a new instance is
      started on some node (like stand-by controller or compute)
      while another instance is running in active controller (with --all
      option).
PASS: Successfully avoids false positives when other processes are
      running with similar names.

Closes-Bug: #2133935

Change-Id: Ia9a6e9a6683478ce149069fbd2d262171aef5257
Signed-off-by: Eduardo Alberti <eduardo.alberti@windriver.com>
This commit is contained in:
Eduardo Alberti
2025-12-05 08:34:29 -03:00
parent 822c36c2ce
commit 01ec87c7e1

View File

@@ -640,11 +640,11 @@ function report_error()
function check_if_collect_is_running()
{
# Looks for collect and collect_* processes. If more than one PID is avail-
# able, the actual instance will exit, given the application is already
# Looks for collect and collect_host processes. If more than one PID is
# available, the actual instance will exit, given the application is already
# running on the system.
local filtered_pids=()
read -a collect_pids <<< "$(ps -eo pid,comm | grep -E 'collect$|collect_' | awk '{print $1}' | tr '\n' ' ')"
read -a collect_pids <<< "$(ps -eo pid,comm | grep -E '\bcollect$|\bcollect_host$' | awk '{print $1}' | tr '\n' ' ')"
for pid in "${collect_pids[@]}"; do
if [ "$pid" != "$$" ]; then
filtered_pids+=("$pid")
@@ -1470,7 +1470,7 @@ EOF
function check_host_reachable_and_collect()
{
local hostname=${1}
local ps_command="ps -eo comm | grep -F collect | grep -v collectd"
local ps_command="ps -eo comm | grep -G -w -e collect\$ -e collect_host\$"
if [ "${hostname}" == "${HOSTNAME}" ] ; then
return ${PASS}