- Added RUNNERS env var to .env.example (comma-separated runner names) - Updated supervisor binary to accept --runners flag - Runners are automatically registered on startup using first admin secret - Updated run.sh to pass RUNNERS from env to supervisor binary
139 lines
3.3 KiB
Bash
Executable File
139 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
PROJECT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
|
|
|
|
# Load environment variables
|
|
source "$SCRIPT_DIR/environment.sh"
|
|
|
|
# Spinner function
|
|
spinner() {
|
|
local pid=$1
|
|
local delay=0.1
|
|
local spinstr='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
|
|
while ps -p $pid > /dev/null 2>&1; do
|
|
local temp=${spinstr#?}
|
|
printf " [%c] " "$spinstr"
|
|
local spinstr=$temp${spinstr%"$temp"}
|
|
sleep $delay
|
|
printf "\b\b\b\b\b\b"
|
|
done
|
|
printf " \b\b\b\b"
|
|
}
|
|
|
|
echo "Starting Hero Supervisor"
|
|
echo ""
|
|
|
|
# Build
|
|
printf "🔨 Building... "
|
|
if "$SCRIPT_DIR/build.sh" > /tmp/supervisor-run-build.log 2>&1 & spinner $!; wait $!; then
|
|
echo "✅"
|
|
else
|
|
echo "❌"
|
|
echo " Error: Build failed. Check /tmp/supervisor-run-build.log"
|
|
exit 1
|
|
fi
|
|
|
|
# Validate required environment variables
|
|
if [ -z "$ADMIN_SECRETS" ]; then
|
|
echo "❌ Error: ADMIN_SECRETS not set in .env"
|
|
echo " Generate a secret with: ./scripts/generate_secret.sh"
|
|
exit 1
|
|
fi
|
|
|
|
# Set defaults
|
|
REDIS_URL="${REDIS_URL:-redis://127.0.0.1:6379}"
|
|
PORT="${PORT:-3030}"
|
|
BIND_ADDRESS="${BIND_ADDRESS:-127.0.0.1}"
|
|
ADMIN_UI_PORT="${ADMIN_UI_PORT:-8080}"
|
|
LOG_LEVEL="${LOG_LEVEL:-error}"
|
|
|
|
# Cleanup function
|
|
cleanup() {
|
|
echo ""
|
|
printf "🛑 Stopping... "
|
|
kill $(jobs -p) 2>/dev/null || true
|
|
echo "✅"
|
|
exit 0
|
|
}
|
|
|
|
trap cleanup SIGINT SIGTERM
|
|
|
|
# Start supervisor
|
|
printf "📡 Supervisor... "
|
|
cd "$PROJECT_DIR"
|
|
|
|
# Build command with flags
|
|
SUPERVISOR_CMD="target/release/supervisor --redis-url $REDIS_URL --port $PORT --bind-address $BIND_ADDRESS"
|
|
|
|
# Add admin secrets
|
|
IFS=',' read -ra SECRETS <<< "$ADMIN_SECRETS"
|
|
for secret in "${SECRETS[@]}"; do
|
|
SUPERVISOR_CMD="$SUPERVISOR_CMD --admin-secret $secret"
|
|
done
|
|
|
|
# Add user secrets if provided
|
|
if [ ! -z "$USER_SECRETS" ]; then
|
|
IFS=',' read -ra SECRETS <<< "$USER_SECRETS"
|
|
for secret in "${SECRETS[@]}"; do
|
|
SUPERVISOR_CMD="$SUPERVISOR_CMD --user-secret $secret"
|
|
done
|
|
fi
|
|
|
|
# Add register secrets if provided
|
|
if [ ! -z "$REGISTER_SECRETS" ]; then
|
|
IFS=',' read -ra SECRETS <<< "$REGISTER_SECRETS"
|
|
for secret in "${SECRETS[@]}"; do
|
|
SUPERVISOR_CMD="$SUPERVISOR_CMD --register-secret $secret"
|
|
done
|
|
fi
|
|
|
|
# Add mycelium URL if provided
|
|
if [ ! -z "$MYCELIUM_URL" ]; then
|
|
SUPERVISOR_CMD="$SUPERVISOR_CMD --mycelium-url $MYCELIUM_URL"
|
|
fi
|
|
|
|
# Add runners if provided
|
|
if [ ! -z "$RUNNERS" ]; then
|
|
SUPERVISOR_CMD="$SUPERVISOR_CMD --runners $RUNNERS"
|
|
fi
|
|
|
|
RUST_LOG="$LOG_LEVEL" RUST_LOG_STYLE=never $SUPERVISOR_CMD > /tmp/supervisor-run.log 2>&1 &
|
|
SUPERVISOR_PID=$!
|
|
|
|
sleep 2
|
|
|
|
if ! ps -p $SUPERVISOR_PID > /dev/null 2>&1; then
|
|
echo "❌"
|
|
echo " Error: Supervisor failed to start. Check /tmp/supervisor-run.log"
|
|
exit 1
|
|
fi
|
|
echo "✅"
|
|
|
|
# Start admin UI
|
|
printf "🎨 Admin UI... "
|
|
cd "$PROJECT_DIR/ui"
|
|
|
|
if ! command -v trunk &> /dev/null; then
|
|
echo "⚠️ (trunk not installed)"
|
|
else
|
|
trunk serve --port "$ADMIN_UI_PORT" > /tmp/supervisor-ui.log 2>&1 &
|
|
ADMIN_UI_PID=$!
|
|
sleep 1
|
|
if ps -p $ADMIN_UI_PID > /dev/null 2>&1; then
|
|
echo "✅"
|
|
else
|
|
echo "❌"
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "📡 http://$BIND_ADDRESS:$PORT"
|
|
if [ ! -z "$ADMIN_UI_PID" ] && ps -p $ADMIN_UI_PID > /dev/null 2>&1; then
|
|
echo "🎨 http://127.0.0.1:$ADMIN_UI_PORT"
|
|
fi
|
|
echo ""
|
|
echo "Press Ctrl+C to stop"
|
|
|
|
# Wait for processes
|
|
wait |