Files
AI_A4000/video_worker/center_dispatch/scripts/start.sh
2026-04-07 17:09:46 +08:00

49 lines
1.5 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
PROJECT_DIR="${ROOT_DIR}/center_dispatch"
cd "$PROJECT_DIR"
if [ ! -f .env ]; then
cp .env.example .env
echo "[INFO] .env created from .env.example, please set GIT_REPO_URL/OSS config."
fi
if ! command -v docker >/dev/null 2>&1; then
echo "[ERROR] docker not found"
exit 1
fi
if ! docker compose version >/dev/null 2>&1; then
echo "[ERROR] docker compose not available"
exit 1
fi
PORT=$(grep '^EDGE_DISPATCH_PORT=' .env | tail -n1 | cut -d'=' -f2- || true)
PORT="${PORT:-8060}"
# AUTO_PULL_LATEST=true requires GIT_REPO_URL. If empty, fallback to local source build.
AUTO_PULL="$(grep '^AUTO_PULL_LATEST=' .env | tail -n1 | cut -d'=' -f2- || true)"
AUTO_PULL="${AUTO_PULL:-true}"
GIT_REPO_URL_VAL="$(grep '^GIT_REPO_URL=' .env | tail -n1 | cut -d'=' -f2- || true)"
if [ "$AUTO_PULL" = "true" ] && [ -z "$GIT_REPO_URL_VAL" ]; then
if [ -d "${ROOT_DIR}/.git" ]; then
REPO_FROM_GIT="$(git -C "$ROOT_DIR" config --get remote.origin.url || true)"
else
REPO_FROM_GIT=""
fi
if [ -n "$REPO_FROM_GIT" ]; then
echo "[WARN] GIT_REPO_URL empty; use git remote origin: $REPO_FROM_GIT"
export GIT_REPO_URL="$REPO_FROM_GIT"
else
echo "[WARN] GIT_REPO_URL empty; fallback AUTO_PULL_LATEST=false (build from local source)"
export AUTO_PULL_LATEST=false
fi
fi
docker compose up -d --build
echo "[OK] center dispatch started"
echo "[INFO] health: curl http://127.0.0.1:${PORT}/health"