diff --git a/install.sh b/install.sh index 26870b4..8e9044a 100644 --- a/install.sh +++ b/install.sh @@ -205,7 +205,12 @@ fi if [[ $PG_HOST == postgres ]]; then ready=0 for elapsed in $(seq 0 298 2); do - if "${COMPOSE[@]}" --profile local-db --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" exec -T postgres pg_isready -U "$PG_USER" -d "$PG_DB" >/dev/null 2>&1; then + container_id=$("${COMPOSE[@]}" --profile local-db --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" ps -q postgres 2>>"$INSTALL_LOG" || true) + health= + if [[ -n $container_id ]]; then + health=$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$container_id" 2>>"$INSTALL_LOG" || true) + fi + if [[ $health == healthy ]]; then ready=1 break fi @@ -235,7 +240,12 @@ if ! run_logged "${COMPOSE[@]}" --project-directory "$INSTALL_DIR" --env-file "$ die 'XyMediaVault 启动失败' fi for elapsed in $(seq 0 118 2); do - curl --fail --silent "http://127.0.0.1:$API_PORT/api/health" >/dev/null && { cp "$INSTALL_LOG" "$INSTALL_DIR/install.log" 2>/dev/null || true; printf '\033[2K\r[%d/%d] 安装完成:XyMediaVault 已就绪\n' "$TOTAL_STEPS" "$TOTAL_STEPS"; printf '管理地址:http://127.0.0.1:%s\n安装日志:%s\n' "$API_PORT" "$INSTALL_LOG"; exit 0; } + if curl --fail --silent "http://127.0.0.1:$API_PORT/api/health" >/dev/null; then + cp "$INSTALL_LOG" "$INSTALL_DIR/install.log" 2>/dev/null || true + printf '\033[2K\r[%d/%d] 安装完成:XyMediaVault 已就绪\n' "$TOTAL_STEPS" "$TOTAL_STEPS" + printf '管理地址:http://127.0.0.1:%s\n安装日志:%s\n' "$API_PORT" "$INSTALL_LOG" + exit 0 + fi printf '\033[2K\r[%d/%d] 等待 XyMediaVault 健康检查(%s 秒)' "$STEP" "$TOTAL_STEPS" "$elapsed" sleep 2 done