改用ps-ef识别部署进程
This commit is contained in:
@@ -196,12 +196,12 @@ is_managed_backend_pid() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
args=$(ps -o args= -p "$pid" 2>/dev/null || true)
|
process_line=$(ps -ef | awk -v target_pid="$pid" '$2 == target_pid {print $0}')
|
||||||
if [ -z "${args:-}" ]; then
|
if [ -z "${process_line:-}" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$args" in
|
case "$process_line" in
|
||||||
*"$BACKEND_MARKER"*"$BACKEND_JAR_TARGET"*|*"$BACKEND_JAR_TARGET"*"$BACKEND_MARKER"*)
|
*"$BACKEND_MARKER"*"$BACKEND_JAR_TARGET"*|*"$BACKEND_JAR_TARGET"*"$BACKEND_MARKER"*)
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@@ -220,7 +220,11 @@ collect_backend_pids() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
marker_pids=$(pgrep -f "$BACKEND_MARKER" 2>/dev/null || true)
|
marker_pids=$(
|
||||||
|
ps -ef | awk -v marker="$BACKEND_MARKER" -v jar="$BACKEND_JAR_TARGET" '
|
||||||
|
index($0, marker) > 0 && index($0, jar) > 0 {print $2}
|
||||||
|
'
|
||||||
|
)
|
||||||
if [ -n "${marker_pids:-}" ]; then
|
if [ -n "${marker_pids:-}" ]; then
|
||||||
for pid in $marker_pids; do
|
for pid in $marker_pids; do
|
||||||
if is_managed_backend_pid "$pid"; then
|
if is_managed_backend_pid "$pid"; then
|
||||||
@@ -331,7 +335,6 @@ main() {
|
|||||||
require_dir "$FRONTEND_DIR"
|
require_dir "$FRONTEND_DIR"
|
||||||
require_command unzip
|
require_command unzip
|
||||||
require_command find
|
require_command find
|
||||||
require_command pgrep
|
|
||||||
require_command ps
|
require_command ps
|
||||||
require_command nohup
|
require_command nohup
|
||||||
require_port_command
|
require_port_command
|
||||||
|
|||||||
@@ -204,8 +204,19 @@ test_netstat_fallback_should_work() {
|
|||||||
cleanup_release_dir "$release_dir"
|
cleanup_release_dir "$release_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_should_use_ps_ef_for_process_detection() {
|
||||||
|
if rg -n 'pgrep' "$SCRIPT_UNDER_TEST" >/dev/null 2>&1; then
|
||||||
|
fail "expected deploy_from_package.sh not to depend on pgrep"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! rg -n 'ps -ef' "$SCRIPT_UNDER_TEST" >/dev/null 2>&1; then
|
||||||
|
fail "expected deploy_from_package.sh to use ps -ef for process detection"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
[ -f "$SCRIPT_UNDER_TEST" ] || fail "script under test not found: $SCRIPT_UNDER_TEST"
|
[ -f "$SCRIPT_UNDER_TEST" ] || fail "script under test not found: $SCRIPT_UNDER_TEST"
|
||||||
|
test_should_use_ps_ef_for_process_detection
|
||||||
test_deploy_success
|
test_deploy_success
|
||||||
test_multiple_release_zip_should_fail
|
test_multiple_release_zip_should_fail
|
||||||
test_netstat_fallback_should_work
|
test_netstat_fallback_should_work
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# 生产一键部署脚本改用 ps -ef 识别进程实施记录
|
||||||
|
|
||||||
|
## 修改内容
|
||||||
|
- 更新 `bin/prod/deploy_from_package.sh`
|
||||||
|
- 将后端进程识别与收集方式从 `pgrep` 改为 `ps -ef`
|
||||||
|
- 删除脚本对 `pgrep` 命令的前置依赖
|
||||||
|
- 更新 `bin/prod/deploy_from_package_test.sh`
|
||||||
|
- 新增断言,要求脚本不能再依赖 `pgrep`,并必须包含 `ps -ef` 进程识别逻辑
|
||||||
|
|
||||||
|
## 调整原因
|
||||||
|
- 用户要求使用 `ps -ef` 判断进程
|
||||||
|
- 旧实现依赖 `pgrep -f` 收集托管进程,不符合当前要求
|
||||||
|
|
||||||
|
## 实现说明
|
||||||
|
- `is_managed_backend_pid` 现在通过 `ps -ef | awk` 按 PID 读取目标进程行
|
||||||
|
- `collect_backend_pids` 现在通过 `ps -ef | awk` 同时匹配:
|
||||||
|
- `-Dloan.pricing.home=<脚本目录>`
|
||||||
|
- `backend/ruoyi-admin.jar`
|
||||||
|
- 只有同时满足托管标记和目标 jar 路径的进程才会被纳入停止范围
|
||||||
|
|
||||||
|
## 验证结果
|
||||||
|
- 已执行 `sh -n bin/prod/deploy_from_package.sh`
|
||||||
|
- 已执行 `sh bin/prod/deploy_from_package_test.sh`
|
||||||
|
- 自测结果确认:
|
||||||
|
- 脚本中已不存在 `pgrep`
|
||||||
|
- 脚本中已使用 `ps -ef`
|
||||||
|
- 正常部署链路仍然通过
|
||||||
|
- 多个发布 zip 失败场景仍然通过
|
||||||
|
- `netstat` 端口检测回退场景仍然通过
|
||||||
Reference in New Issue
Block a user