cleanup and refactor
This commit is contained in:
138
scripts/run.sh
138
scripts/run.sh
@@ -3,60 +3,12 @@
|
||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
PROJECT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
|
||||
|
||||
# Check for --kill-ports flag
|
||||
if [ "$1" = "--kill-ports" ]; then
|
||||
echo "Killing processes on ports..."
|
||||
PORT="${PORT:-3030}"
|
||||
ADMIN_UI_PORT="${ADMIN_UI_PORT:-8080}"
|
||||
|
||||
# Kill process on supervisor port
|
||||
SUPERVISOR_PID=$(lsof -ti:$PORT)
|
||||
if [ ! -z "$SUPERVISOR_PID" ]; then
|
||||
kill -9 $SUPERVISOR_PID 2>/dev/null
|
||||
echo " ✅ Killed process on port $PORT"
|
||||
fi
|
||||
|
||||
# Kill process on admin UI port
|
||||
UI_PID=$(lsof -ti:$ADMIN_UI_PORT)
|
||||
if [ ! -z "$UI_PID" ]; then
|
||||
kill -9 $UI_PID 2>/dev/null
|
||||
echo " ✅ Killed process on port $ADMIN_UI_PORT"
|
||||
fi
|
||||
|
||||
echo "Done"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 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
|
||||
# Build first
|
||||
echo "🔨 Building supervisor..."
|
||||
"$SCRIPT_DIR/build.sh"
|
||||
|
||||
# Validate required environment variables
|
||||
if [ -z "$ADMIN_SECRETS" ]; then
|
||||
@@ -65,29 +17,15 @@ if [ -z "$ADMIN_SECRETS" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set defaults
|
||||
# Set defaults from env vars
|
||||
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}"
|
||||
LOG_LEVEL="${LOG_LEVEL:-info}"
|
||||
|
||||
# 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
|
||||
# Build command with flags from env vars
|
||||
SUPERVISOR_CMD="target/release/supervisor --redis-url $REDIS_URL --port $PORT --bind-address $BIND_ADDRESS"
|
||||
|
||||
# Add admin secrets
|
||||
@@ -122,64 +60,12 @@ 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"
|
||||
|
||||
UI_STARTED=false
|
||||
UI_ERROR=""
|
||||
if ! command -v trunk &> /dev/null; then
|
||||
echo "⚠️"
|
||||
UI_ERROR="Trunk not installed. Run: cargo install trunk"
|
||||
else
|
||||
trunk serve --port "$ADMIN_UI_PORT" > /tmp/supervisor-ui.log 2>&1 &
|
||||
ADMIN_UI_PID=$!
|
||||
sleep 2
|
||||
|
||||
# Check if process is still running
|
||||
if ps -p $ADMIN_UI_PID > /dev/null 2>&1; then
|
||||
# Check for port binding errors in log
|
||||
if grep -q "Address already in use" /tmp/supervisor-ui.log 2>/dev/null; then
|
||||
echo "❌"
|
||||
UI_ERROR="Port $ADMIN_UI_PORT already in use. Run: ./scripts/run.sh --kill-ports"
|
||||
kill $ADMIN_UI_PID 2>/dev/null
|
||||
else
|
||||
echo "✅"
|
||||
UI_STARTED=true
|
||||
fi
|
||||
else
|
||||
echo "❌"
|
||||
UI_ERROR="Failed to start"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "Hero Supervisor Running"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "📡 OpenRPC Server: http://$BIND_ADDRESS:$PORT"
|
||||
if [ "$UI_STARTED" = true ]; then
|
||||
echo "🎨 Admin UI: http://127.0.0.1:$ADMIN_UI_PORT"
|
||||
else
|
||||
echo "🎨 Admin UI: ❌ $UI_ERROR"
|
||||
fi
|
||||
echo "🚀 Starting Hero Supervisor"
|
||||
echo " Redis: $REDIS_URL"
|
||||
echo " Port: $PORT"
|
||||
echo " Log Level: $LOG_LEVEL"
|
||||
echo ""
|
||||
echo "Logs: tail -f /tmp/supervisor-run.log /tmp/supervisor-ui.log"
|
||||
echo ""
|
||||
echo "Press Ctrl+C to stop all services"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
|
||||
# Wait for processes
|
||||
wait
|
||||
# Run supervisor directly with output visible
|
||||
exec env RUST_LOG="$LOG_LEVEL" RUST_LOG_STYLE=never $SUPERVISOR_CMD
|
||||
Reference in New Issue
Block a user