完善更新脚本服务启动等待

This commit is contained in:
Rei
2026-09-30 16:39:30 +08:00
parent fc19fb0c4b
commit c236de6688
+15 -2
View File
@@ -16,6 +16,19 @@ fail() {
exit 1 exit 1
} }
wait_for_url() {
local url="$1"
local attempts="${2:-20}"
local i
for ((i = 1; i <= attempts; i += 1)); do
if curl --fail --silent --show-error --max-time 10 "$url" >/dev/null 2>&1; then
return 0
fi
sleep 1
done
fail "健康检查超时:$url"
}
command -v git >/dev/null 2>&1 || fail '未安装 git' command -v git >/dev/null 2>&1 || fail '未安装 git'
command -v npm >/dev/null 2>&1 || fail '未安装 npm' command -v npm >/dev/null 2>&1 || fail '未安装 npm'
command -v pm2 >/dev/null 2>&1 || fail '未安装 pm2' command -v pm2 >/dev/null 2>&1 || fail '未安装 pm2'
@@ -85,8 +98,8 @@ pm2 restart ameba-cms --update-env
pm2 save pm2 save
log '执行服务健康检查' log '执行服务健康检查'
curl --fail --silent --show-error --max-time 15 http://127.0.0.1:13001/health >/dev/null wait_for_url http://127.0.0.1:13001/health
curl --fail --silent --show-error --max-time 20 https://www.ameiba.cn/ >/dev/null wait_for_url https://www.ameiba.cn/
NEW_COMMIT="$(git rev-parse --short HEAD)" NEW_COMMIT="$(git rev-parse --short HEAD)"
log "更新完成:$OLD_COMMIT -> $NEW_COMMIT" log "更新完成:$OLD_COMMIT -> $NEW_COMMIT"