fix(deploy): 等待 Nginx 新配置生效后再验收入口

This commit is contained in:
2026-10-18 00:21:54 +08:00
parent b99eb849b4
commit 4122907936
3 changed files with 35 additions and 12 deletions
+28 -8
View File
@@ -574,7 +574,7 @@ verify_proxy_entry() {
case "$DEPLOY_MODE" in ip|domain) ;; *) return 0 ;; esac
local public_host response
if [ "$DEPLOY_MODE" = ip ]; then public_host="$DEPLOY_IP"; else public_host="$DEPLOY_DOMAIN"; fi
local curl_options=(--fail --silent --show-error --max-time 30)
local curl_options=(--fail --silent --show-error --max-time 10)
local origin='http://127.0.0.1'
if [ "$DEPLOY_HTTPS" = true ]; then
curl_options+=(--resolve "${public_host}:443:127.0.0.1")
@@ -582,13 +582,33 @@ verify_proxy_entry() {
else
curl_options+=(-H "Host: ${public_host}")
fi
curl "${curl_options[@]}" "${origin}/" -o /dev/null || { echo '❌ 首页访问失败,部署未完成' >&2; return 1; }
response="$(curl "${curl_options[@]}" "${origin}/api/health/update-ready")" || return 1
if ! printf '%s' "$response" | python3 -c 'import json,sys; value=json.load(sys.stdin); sys.exit(0 if value.get("status")=="ok" and value.get("service")=="easyai-server-main" else 1)'; then
echo '❌ 后端公开入口尚未就绪,部署未完成' >&2
return 1
fi
echo '✅ 同机 Nginx 首页和后端入口检查通过'
local timeout="${DEPLOY_PROXY_TIMEOUT_SECONDS:-60}" deadline homepage_status api_status
[[ "$timeout" =~ ^[1-9][0-9]*$ ]] || { echo '❌ 入口检查等待秒数必须为正整数' >&2; return 1; }
deadline=$((SECONDS + timeout))
# nginx -s reload returns before its new workers have accepted requests.
# A previous vhost can briefly answer with a redirect during replacement.
while (( SECONDS < deadline )); do
homepage_status="$(curl "${curl_options[@]}" -w '%{http_code}' "${origin}/" -o /dev/null 2>/dev/null || true)"
if [ "$homepage_status" = 200 ]; then
response="$(curl "${curl_options[@]}" -w '\n%{http_code}' "${origin}/api/health/update-ready" 2>/dev/null || true)"
api_status="${response##*$'\n'}"
response="${response%$'\n'*}"
if [ "$api_status" = 200 ] && printf '%s' "$response" | python3 -c '
import json,sys
try:
value=json.load(sys.stdin)
sys.exit(0 if value.get("status")=="ok" and value.get("service")=="easyai-server-main" else 1)
except (ValueError, AttributeError):
sys.exit(1)
'; then
echo '✅ 同机 Nginx 首页和后端入口检查通过'
return 0
fi
fi
sleep 2
done
echo '❌ Nginx 首页或后端公开入口未在规定时间内就绪,部署未完成' >&2
return 1
}
# ==================== 执行 HTTPS 配置 ====================