Fix PM2 start falsely treating missing crypto_okx as existing.
Use jlist name match and fall back to start when restart fails. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+22
-2
@@ -236,7 +236,23 @@ remove_backup_cron() {
|
||||
|
||||
pm2_app_exists() {
|
||||
local name="$1"
|
||||
pm2 pid "${name}" >/dev/null 2>&1
|
||||
# pm2 pid 在部分版本对不存在的进程仍返回 0;改用 jlist 精确匹配 name
|
||||
if ! command -v pm2 >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
if ! command -v python3 >/dev/null 2>&1; then
|
||||
pm2 describe "${name}" 2>/dev/null | grep -q "status"
|
||||
return $?
|
||||
fi
|
||||
pm2 jlist 2>/dev/null | python3 -c '
|
||||
import json,sys
|
||||
name=sys.argv[1]
|
||||
try:
|
||||
apps=json.load(sys.stdin)
|
||||
except Exception:
|
||||
sys.exit(1)
|
||||
sys.exit(0 if any(isinstance(a,dict) and a.get("name")==name for a in (apps or [])) else 1)
|
||||
' "${name}"
|
||||
}
|
||||
|
||||
pm2_stop_project_apps() {
|
||||
@@ -281,8 +297,12 @@ pm2_start_app() {
|
||||
[[ -x "${REPO_ROOT}/.venv/bin/python" ]] || die "缺少 .venv,请先运行 setup_env.sh"
|
||||
if pm2_app_exists "${PM2_APP_NAME}"; then
|
||||
log "已存在,执行 restart --update-env"
|
||||
pm2 restart "${PM2_APP_NAME}" --update-env
|
||||
if ! pm2 restart "${PM2_APP_NAME}" --update-env; then
|
||||
log "restart 失败,改为 start ecosystem.config.cjs"
|
||||
pm2 start ecosystem.config.cjs
|
||||
fi
|
||||
else
|
||||
log "首次启动: pm2 start ecosystem.config.cjs"
|
||||
pm2 start ecosystem.config.cjs
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user