Re-load deploy helpers after pull and wait for HTTP ready.
Quick update was verifying with stale in-memory functions before Flask bound. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -19,6 +19,9 @@ require_installed() {
|
|||||||
update_quick() {
|
update_quick() {
|
||||||
step "快速更新"
|
step "快速更新"
|
||||||
bash "${REPO_ROOT}/deploy/pull_and_restart.sh"
|
bash "${REPO_ROOT}/deploy/pull_and_restart.sh"
|
||||||
|
# git pull 后重新加载,避免菜单进程仍用旧的 verify_deployment
|
||||||
|
# shellcheck source=common.sh
|
||||||
|
source "${LIB_DIR}/common.sh"
|
||||||
verify_deployment "$(detect_server_ip)" || true
|
verify_deployment "$(detect_server_ip)" || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ pm2_has_app() {
|
|||||||
if ! command -v pm2 >/dev/null 2>&1; then
|
if ! command -v pm2 >/dev/null 2>&1; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# 勿用 pm2 pid:部分版本对不存在进程仍 exit 0
|
|
||||||
if command -v python3 >/dev/null 2>&1; then
|
if command -v python3 >/dev/null 2>&1; then
|
||||||
pm2 jlist 2>/dev/null | python3 -c '
|
pm2 jlist 2>/dev/null | python3 -c '
|
||||||
import json,sys
|
import json,sys
|
||||||
@@ -38,6 +37,43 @@ sys.exit(0 if any(isinstance(a,dict) and a.get("name")==name for a in (apps or [
|
|||||||
pm2 describe "${name}" 2>/dev/null | grep -qE 'status[[:space:]]*[|:]'
|
pm2 describe "${name}" 2>/dev/null | grep -qE 'status[[:space:]]*[|:]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read_port() {
|
||||||
|
local env_file="${REPO}/.env"
|
||||||
|
local port="5004"
|
||||||
|
if [[ -f "${env_file}" ]]; then
|
||||||
|
local line
|
||||||
|
line="$(grep -E '^[[:space:]]*APP_PORT=' "${env_file}" | tail -n1 || true)"
|
||||||
|
if [[ -n "${line}" ]]; then
|
||||||
|
port="${line#*=}"
|
||||||
|
port="$(echo "${port}" | tr -d '"' | tr -d "'" | xargs)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "${port:-5004}"
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_http_ready() {
|
||||||
|
local port="$1"
|
||||||
|
local url="http://127.0.0.1:${port}/"
|
||||||
|
local i code
|
||||||
|
echo ">>> 等待 HTTP 就绪 ${url} (最多 30s)"
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
code="$(curl -sS -o /dev/null -w '%{http_code}' --connect-timeout 2 --max-time 3 "${url}" 2>/dev/null || echo "000")"
|
||||||
|
if [[ "${code}" == "200" || "${code}" == "302" || "${code}" == "301" || "${code}" == "401" || "${code}" == "403" ]]; then
|
||||||
|
echo ">>> HTTP OK (${code}) after ${i}s"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
# 进程挂了就别空等
|
||||||
|
if ! pm2_has_app "${PM2_APP_NAME}"; then
|
||||||
|
echo ">>> PM2 进程已消失" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo ">>> HTTP 仍未就绪 (最后 code=${code:-000})" >&2
|
||||||
|
echo ">>> 请查看: pm2 logs ${PM2_APP_NAME} --lines 50" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
cd "${REPO}"
|
cd "${REPO}"
|
||||||
echo ">>> git pull"
|
echo ">>> git pull"
|
||||||
git pull
|
git pull
|
||||||
@@ -65,4 +101,7 @@ else
|
|||||||
pm2 start ecosystem.config.cjs
|
pm2 start ecosystem.config.cjs
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
port="$(read_port)"
|
||||||
|
wait_http_ready "${port}" || true
|
||||||
|
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|||||||
Reference in New Issue
Block a user