From 07a9deb2977dda38e41c33763f06b4595736071b Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 2 Apr 2024 11:06:34 +0800 Subject: [PATCH] Script Refactoring --- scripts-new/lib/util.sh | 14 ++++++++++++++ scripts-new/stop.sh | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 scripts-new/stop.sh diff --git a/scripts-new/lib/util.sh b/scripts-new/lib/util.sh index 435666b0c..3be4931d6 100644 --- a/scripts-new/lib/util.sh +++ b/scripts-new/lib/util.sh @@ -2873,6 +2873,20 @@ check_binary_ports() { } +kill_binary() { + binary_path="$1" + + pids=$(pgrep -f "$binary_path") + + if [ -z "$pids" ]; then + echo "No process found for $binary_path" + else + for pid in $pids; do + echo "Killing process $pid associated with $binary_path" + kill -9 "$pid" + done + fi +} diff --git a/scripts-new/stop.sh b/scripts-new/stop.sh new file mode 100644 index 000000000..5dca030c0 --- /dev/null +++ b/scripts-new/stop.sh @@ -0,0 +1,19 @@ + +#!/usr/bin/env bash + + + +OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/ +source "${OPENIM_ROOT}/lib/util.sh" +source "${OPENIM_ROOT}/define/binaries.sh" +source "${OPENIM_ROOT}/lib/path.sh" + + + +for binary in "${!binaries[@]}"; do + expected_count=${binaries[$binary]} + full_path=$(get_bin_full_path "$binary") + kill_binary "$full_path" +done + +