From 8c8a0232d9fa3cd48451a6e9120b3f04ed9179fe Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Thu, 21 Mar 2024 18:50:21 +0800 Subject: [PATCH] Optimizing scripts --- scripts/lib/util.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 9588f727d..92f809e73 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -613,21 +613,26 @@ openim::util::stop_services_with_name() { continue fi local stopped_this_time=false - for pid in $pids; do + for pid in $pids; do - # Exclude the PID of the current script - if [[ "$pid" == "$$" ]]; then - continue - fi + # Exclude the PID of the current script + if [[ "$pid" == "$$" ]]; then + continue + fi + + # If there's a Process ID, it means the service with the name is running. + if [[ -n $pid ]]; then + # Print the binary path for the PID + binary_path=$(readlink -f /proc/$pid/exe) + echo "PID $pid corresponds to binary path: $binary_path" + + # Try to stop the service by killing its process. + if kill -15 $pid 2>/dev/null; then + stopped_this_time=true + fi + fi + done - # If there's a Process ID, it means the service with the name is running. - if [[ -n $pid ]]; then - # Try to stop the service by killing its process. - if kill -15 $pid 2>/dev/null; then - stopped_this_time=true - fi - fi - done if $stopped_this_time; then stopped+=("$server_name")