Stop uninstall from killing unrelated PM2 processes on the server.

Only stop and delete crypto_monitor app names (plus legacy aliases) instead of pm2 stop/delete all.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-12 12:56:08 +08:00
parent 337a6bc54f
commit 8e492987ec
3 changed files with 60 additions and 11 deletions
+48
View File
@@ -27,6 +27,13 @@ PM2_APPS=(
manual-agent-gate
)
# 历史进程名(仅 stop/delete 时兼容,不计入验收)
PM2_APPS_LEGACY=(
crypto-monitor-binance
crypto-monitor-gate
crypto-monitor-okx
)
CONFIG_PATHS=(
crypto_monitor_binance/.env
crypto_monitor_okx/.env
@@ -255,6 +262,47 @@ remove_backup_cron_all() {
fi
}
pm2_app_exists() {
local name="$1"
pm2 pid "${name}" >/dev/null 2>&1
}
# 仅操作本项目 PM2 进程,不影响服务器上其它应用
pm2_stop_project_apps() {
if ! command -v pm2 >/dev/null 2>&1; then
log "未安装 pm2,跳过"
return 0
fi
local name stopped=0
for name in "${PM2_APPS[@]}" "${PM2_APPS_LEGACY[@]}"; do
if pm2_app_exists "${name}"; then
log "pm2 stop ${name}"
pm2 stop "${name}" 2>/dev/null || true
stopped=$((stopped + 1))
fi
done
if [[ "${stopped}" -eq 0 ]]; then
log "未发现本项目 PM2 进程(其它 PM2 不受影响)"
fi
}
pm2_delete_project_apps() {
if ! command -v pm2 >/dev/null 2>&1; then
return 0
fi
local name deleted=0
for name in "${PM2_APPS[@]}" "${PM2_APPS_LEGACY[@]}"; do
if pm2_app_exists "${name}"; then
log "pm2 delete ${name}"
pm2 delete "${name}" 2>/dev/null || true
deleted=$((deleted + 1))
fi
done
if [[ "${deleted}" -gt 0 ]]; then
pm2 save 2>/dev/null || true
fi
}
pm2_save_startup() {
step "PM2 save & startup"
pm2 save 2>/dev/null || true
+3 -8
View File
@@ -41,14 +41,9 @@ main_uninstall() {
echo "removed_dir=${removed_dir}"
} >"${backup_dir}/uninstall.manifest"
step "停止并清空 PM2"
if command -v pm2 >/dev/null 2>&1; then
pm2 stop all 2>/dev/null || true
pm2 delete all 2>/dev/null || true
pm2 save 2>/dev/null || true
else
log "未安装 pm2,跳过"
fi
step "停止并移除本项目 PM2 进程(不影响其它 PM2)"
pm2_stop_project_apps
pm2_delete_project_apps
remove_backup_cron_all