Fix quick-update PM2 path when crypto_okx was never started.

Stop trusting pm2 pid; start ecosystem if the app is missing.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-13 20:18:06 +08:00
parent 9079f94585
commit ecf35f6c09
+36 -10
View File
@@ -17,6 +17,27 @@ if [[ "${1:-}" == "--dry-run" ]]; then
echo "(dry-run mode)"
fi
pm2_has_app() {
local name="$1"
if ! command -v pm2 >/dev/null 2>&1; then
return 1
fi
# 勿用 pm2 pid:部分版本对不存在进程仍 exit 0
if command -v python3 >/dev/null 2>&1; then
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}"
return $?
fi
pm2 describe "${name}" 2>/dev/null | grep -qE 'status[[:space:]]*[|:]'
}
cd "${REPO}"
echo ">>> git pull"
git pull
@@ -26,17 +47,22 @@ if [[ "${DRY}" -eq 1 ]]; then
exit 0
fi
echo ">>> pm2 restart ${PM2_APP_NAME} --update-env"
if command -v pm2 >/dev/null 2>&1; then
if pm2 pid "${PM2_APP_NAME}" >/dev/null 2>&1; then
pm2 restart "${PM2_APP_NAME}" --update-env
elif [[ -f ecosystem.config.cjs ]]; then
pm2 start ecosystem.config.cjs
else
echo "warn: 未找到 PM2 进程 ${PM2_APP_NAME}" >&2
fi
else
if ! command -v pm2 >/dev/null 2>&1; then
echo "warn: 未安装 pm2" >&2
exit 1
fi
if [[ ! -f ecosystem.config.cjs ]]; then
echo "error: 缺少 ecosystem.config.cjs" >&2
exit 1
fi
if pm2_has_app "${PM2_APP_NAME}"; then
echo ">>> pm2 restart ${PM2_APP_NAME} --update-env"
pm2 restart "${PM2_APP_NAME}" --update-env
else
echo ">>> 未注册 ${PM2_APP_NAME},执行 pm2 start ecosystem.config.cjs"
pm2 start ecosystem.config.cjs
fi
echo "done"