#!/bin/bash
set -e

FLAMENCO_MODE="${FLAMENCO_MODE:-manager}"

if [ "$FLAMENCO_MODE" = "manager" ]; then
    echo "Starting Flamenco Manager..."
    # Flamenco 3.x reads flamenco-manager.yaml from the working directory
    exec /opt/flamenco/flamenco-manager
elif [ "$FLAMENCO_MODE" = "worker" ]; then
    echo "Starting Flamenco Worker..."
    echo "Manager URL: ${FLAMENCO_MANAGER_URL:-http://flamenco-manager:8080}"
    # Flamenco 3.x reads flamenco-worker.yaml from the working directory
    exec /opt/flamenco/flamenco-worker
else
    echo "ERROR: Unknown FLAMENCO_MODE='${FLAMENCO_MODE}'. Use 'manager' or 'worker'."
    exit 1
fi
