From aa3259583f065f0f8da08cbd57631bd2c366e688 Mon Sep 17 00:00:00 2001 From: hy Date: Thu, 23 Apr 2026 13:14:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8D=E8=AF=AF=E6=9D=80systemd?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/common.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/common.sh b/scripts/common.sh index 72225b3..d51f470 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -142,6 +142,22 @@ has_full_systemd_suite() { return 0 } +systemd_main_pid() { + local name="$1" + local main_pid + + if ! has_systemd_unit "$name"; then + return 1 + fi + + main_pid="$(systemctl show --property MainPID --value "$(service_unit_name "$name")" 2>/dev/null || true)" + if [ -z "${main_pid:-}" ] || [ "$main_pid" = "0" ]; then + return 1 + fi + + echo "$main_pid" +} + pid_matches_project() { local name="$1" local pid="$2" @@ -231,8 +247,15 @@ stop_legacy_process() { local name="$1" local pid local pid_file + local managed_pid pid_file="$(service_pid_file "$name")" pid="$(read_pid "$name" || true)" + managed_pid="$(systemd_main_pid "$name" || true)" + + if [ -n "${pid:-}" ] && [ -n "${managed_pid:-}" ] && [ "$pid" = "$managed_pid" ]; then + rm -f "$pid_file" + return 0 + fi if [ -n "${pid:-}" ] && kill -0 "$pid" >/dev/null 2>&1; then kill "$pid" >/dev/null 2>&1 || true