From 3e5c26140e712ab5910bcecdb0b607ba4aa9f9e9 Mon Sep 17 00:00:00 2001 From: sindoring Date: Mon, 9 Mar 2026 16:52:05 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D1=83=D1=81=D0=BA=D0=B0=20ad-db=20ad-db-import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- start-server.sh | 87 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/start-server.sh b/start-server.sh index 9cdb3f7..ab56c14 100644 --- a/start-server.sh +++ b/start-server.sh @@ -31,6 +31,68 @@ log() { printf '[start-server] %s\n' "$*" } +print_service_logs() { + local service="$1" + printf '\n[%s logs]\n' "$service" >&2 + docker compose logs --tail=120 "$service" >&2 || true + printf '\n' >&2 +} + +wait_for_healthy() { + local container_name="$1" + local timeout_seconds="${2:-180}" + local start_ts now status + + start_ts="$(date +%s)" + + while :; do + status="$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$container_name" 2>/dev/null || true)" + + case "$status" in + healthy|running) + return 0 + ;; + unhealthy|exited|dead) + return 1 + ;; + esac + + now="$(date +%s)" + if (( now - start_ts >= timeout_seconds )); then + return 1 + fi + + sleep 2 + done +} + +run_one_shot_service() { + local service="$1" + local container_name="$2" + + if [[ -n "$BUILD_FLAG" ]]; then + if ! docker compose up --build --no-deps "$service"; then + print_service_logs "$service" + printf '%s failed during startup\n' "$service" >&2 + exit 1 + fi + else + if ! docker compose up --no-deps "$service"; then + print_service_logs "$service" + printf '%s failed during startup\n' "$service" >&2 + exit 1 + fi + fi + + local exit_code + exit_code="$(docker inspect -f '{{.State.ExitCode}}' "$container_name" 2>/dev/null || printf '1')" + if [[ "$exit_code" != "0" ]]; then + print_service_logs "$service" + printf '%s failed with exit code %s\n' "$service" "$exit_code" >&2 + exit 1 + fi +} + require_docker() { if ! command -v docker >/dev/null 2>&1; then printf 'docker is not installed or not in PATH\n' >&2 @@ -80,11 +142,30 @@ require_docker log "applying module configuration" bash "$ROOT_DIR/setup-modules.sh" -log "starting docker services" +log "starting database" if [[ -n "$BUILD_FLAG" ]]; then - docker compose up -d --build + docker compose up -d --build ac-database else - docker compose up -d + docker compose up -d ac-database +fi + +if ! wait_for_healthy "ac-database" 180; then + print_service_logs "ac-database" + printf 'ac-database did not become healthy\n' >&2 + exit 1 +fi + +log "running database import" +run_one_shot_service "ac-db-import" "ac-db-import" + +log "initializing client data" +run_one_shot_service "ac-client-data-init" "ac-client-data-init" + +log "starting authserver and worldserver" +if [[ -n "$BUILD_FLAG" ]]; then + docker compose up -d --build ac-authserver ac-worldserver +else + docker compose up -d ac-authserver ac-worldserver fi log "synchronizing realmlist"