修复健康检查

This commit is contained in:
yml2213
2026-09-04 17:07:47 +08:00
parent 182b21f192
commit da3c2f461b
4 changed files with 34 additions and 8 deletions
+2
View File
@@ -41,3 +41,5 @@ deploy/caddy/conf.d/show.caddy
logs
.gocache
artifacts/
frontend/coverage/
+1 -1
View File
@@ -165,7 +165,7 @@ HFB_SHOW_DIR=../hfb_show
- 通过 Caddy 自动申请或续签 HTTPS 证书。
- 等待 MySQL、Redis 就绪。
- 按顺序执行尚未应用的数据库迁移。
- 重启后端并检查 `https://你的域名/api/health`。
- 重启后端并在容器内检查 `http://127.0.0.1:8080/api/health`。默认不依赖公网 DNS、TLS 或 Caddy;如需检查公网入口,可设置 `PROD_HEALTH_URL=https://你的域名/api/health`。
如需部署完成后直接跟随查看后端日志:
+6
View File
@@ -104,6 +104,12 @@ services:
condition: service_healthy
expose:
- "8080"
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null -T 5 http://127.0.0.1:8080/api/health"]
interval: 10s
timeout: 6s
retries: 12
start_period: 10s
beszel:
image: henrygd/beszel:0.18.7
+25 -7
View File
@@ -69,7 +69,7 @@ show_help() {
环境变量:
PROD_HEALTH_URL=https://你的域名/api/health
部署后健康检查地址,默认使用 CADDY_DOMAIN
部署后公网健康检查地址;设置后使用外部 curl 检查
PROD_PUBLIC_URL=https://你的域名
输出给用户看的访问地址
PROD_READY_TIMEOUT=120
@@ -591,18 +591,36 @@ run_migrations() {
wait_http_ready() {
local attempt
local url
url="$(health_url)"
log "等待接口健康检查通过..."
local url="${HEALTH_URL}"
if [[ -n "${url}" ]]; then
log "等待公网接口健康检查通过..."
for ((attempt = 1; attempt <= READY_TIMEOUT; attempt++)); do
if curl -fsS --max-time 5 "${url}" >/dev/null 2>&1; then
log_success "公网健康检查通过:${url}"
return 0
fi
sleep 1
done
log_error "公网健康检查超时:${url}"
exit 1
fi
url="http://127.0.0.1:8080/api/health"
log "等待后端容器内健康检查通过..."
for ((attempt = 1; attempt <= READY_TIMEOUT; attempt++)); do
if curl -fsS --max-time 5 "${url}" >/dev/null 2>&1; then
log_success "健康检查通过:${url}"
if compose exec -T backend wget -q -O /dev/null -T 5 "${url}" >/dev/null 2>&1; then
log_success "容器内健康检查通过:${url}"
return 0
fi
sleep 1
done
log_error "健康检查超时:${url}"
log_error "后端容器内健康检查超时:${url}"
log_warn "最近 backend 日志:"
compose logs --tail=120 backend || true
log_error "可继续执行:$(compose_user_cmd) logs backend"
exit 1
}