#!/bin/bash # StreamCore - Start the backend. # # The backend owns everything: it serves the built frontend, starts the media # origin at boot, supervises ffmpeg, and restarts either if it dies. This script # only has to bring up the process that owns all of that. Node is a build-time # dependency only (see the frontend build below), never a runtime one. set -e BASE="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" export LS_HLS_RUNTIME_DIR="${LS_HLS_RUNTIME_DIR:-$BASE/runtime/hls}" export LS_REPLAY_MEDIA_DIR="${LS_REPLAY_MEDIA_DIR:-$BASE/runtime/replay}" mkdir -p "$LS_HLS_RUNTIME_DIR" "$LS_REPLAY_MEDIA_DIR" "$BASE/runtime/logs" HOST="${LS_HOST:-0.0.0.0}" PORT="${LS_PORT:-8080}" # Build the frontend once, so a fresh checkout does not come up as a 503. if [ ! -f "$BASE/frontend/dist/index.html" ]; then if command -v npm >/dev/null 2>&1; then echo "[StreamCore] Building frontend..." cd "$BASE/frontend" [ -d node_modules ] || npm install npm run build else echo "[StreamCore] WARNING: npm not found and frontend/dist is missing; the site will return 503." >&2 echo "[StreamCore] WARNING: install Node.js and run: cd frontend && npm install && npm run build" >&2 fi fi cd "$BASE/backend" PY="$BASE/backend/venv/bin/python" [ -x "$PY" ] || PY="$BASE/backend/.venv/bin/python" [ -x "$PY" ] || PY="python" echo "[StreamCore] Starting backend on ${HOST}:${PORT}..." echo "[StreamCore] Frontend, MediaMTX, transcoders and HLS are served by the backend." exec "$PY" -m uvicorn main:app --host "$HOST" --port "$PORT"