fix: wait for admin startup readiness
This commit is contained in:
@@ -34,6 +34,19 @@ export ADM_WEB_HOST="${WEB_HOST}"
|
||||
export ADM_PORT="${PORT}"
|
||||
export VITE_BASE_PATH="${BASE_PATH%/}"
|
||||
|
||||
wait_for_http() {
|
||||
local url="$1"
|
||||
local attempts="${2:-30}"
|
||||
local attempt
|
||||
for ((attempt = 1; attempt <= attempts; attempt += 1)); do
|
||||
if curl -sf --max-time 2 "${url}" >/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
if [[ ! -d dist ]]; then
|
||||
echo "❌ ${ROOT}/dist 不存在,请先构建或 rsync dist" >&2
|
||||
exit 1
|
||||
@@ -61,9 +74,8 @@ sleep 1
|
||||
echo "==> 启动 Admin API @ ${API_HOST}:${API_PORT}..."
|
||||
nohup node server/index.mjs >>"${API_LOG}" 2>&1 &
|
||||
echo $! >"${API_PID_FILE}"
|
||||
sleep 2
|
||||
|
||||
if ! curl -sf "http://127.0.0.1:${API_PORT}/health" >/dev/null; then
|
||||
if ! wait_for_http "http://127.0.0.1:${API_PORT}/health" 30; then
|
||||
echo "❌ Admin API 启动失败,最近日志:" >&2
|
||||
tail -n 40 "${API_LOG}" >&2 || true
|
||||
exit 1
|
||||
@@ -72,11 +84,10 @@ fi
|
||||
echo "==> 启动 vite preview @ ${WEB_HOST}:${PORT} (base=${BASE_PATH})..."
|
||||
nohup npx vite preview --config scripts/vite-preview.config.mjs >>"${LOG}" 2>&1 &
|
||||
echo $! >"${PID_FILE}"
|
||||
sleep 2
|
||||
|
||||
preview_url="http://127.0.0.1:${PORT}${BASE_PATH}"
|
||||
login_probe="http://127.0.0.1:${PORT}/auth/status"
|
||||
if curl -sf "${preview_url}" >/dev/null && curl -sf "${login_probe}" >/dev/null; then
|
||||
if wait_for_http "${preview_url}" 30 && wait_for_http "${login_probe}" 15; then
|
||||
echo "✅ memind_adm 已就绪: ${preview_url}"
|
||||
curl -sf "${preview_url}" >/dev/null && echo " 首页 OK"
|
||||
echo " /auth 反代 OK"
|
||||
|
||||
Reference in New Issue
Block a user