#!/bin/bash # Wave 75 Agent 1: Start all backend services with proper TLS configuration set -e # Load and export environment variables set -a source .env set +a # Create logs directory mkdir -p logs echo "Starting Foxhunt HFT Services..." echo "================================" # Start Trading Service (port 50051) echo "[1/4] Starting Trading Service on port 50051..." ./target/release/trading_service &> logs/trading.log & TRADING_PID=$! sleep 3 # Check if trading service started successfully if ! kill -0 $TRADING_PID 2>/dev/null; then echo "ERROR: Trading Service failed to start. Check logs/trading.log" tail -20 logs/trading.log exit 1 fi echo "✓ Trading Service started (PID: $TRADING_PID)" # Start Backtesting Service (port 50052) echo "[2/4] Starting Backtesting Service on port 50052..." ./target/release/backtesting_service &> logs/backtesting.log & BACKTEST_PID=$! sleep 3 # Check if backtesting service started successfully if ! kill -0 $BACKTEST_PID 2>/dev/null; then echo "ERROR: Backtesting Service failed to start. Check logs/backtesting.log" tail -20 logs/backtesting.log exit 1 fi echo "✓ Backtesting Service started (PID: $BACKTEST_PID)" # Start ML Training Service (port 50053) echo "[3/4] Starting ML Training Service on port 50053..." ./target/release/ml_training_service serve &> logs/ml_training.log & ML_PID=$! sleep 3 # Check if ML training service started successfully if ! kill -0 $ML_PID 2>/dev/null; then echo "ERROR: ML Training Service failed to start. Check logs/ml_training.log" tail -20 logs/ml_training.log exit 1 fi echo "✓ ML Training Service started (PID: $ML_PID)" # Wait for backend services to be ready echo "Waiting for backend services to initialize..." sleep 5 # Start API Gateway (port 50050) echo "[4/4] Starting API Gateway on port 50050..." ./target/release/api_gateway &> logs/api_gateway.log & GATEWAY_PID=$! sleep 3 # Check if API gateway started successfully if ! kill -0 $GATEWAY_PID 2>/dev/null; then echo "ERROR: API Gateway failed to start. Check logs/api_gateway.log" tail -20 logs/api_gateway.log exit 1 fi echo "✓ API Gateway started (PID: $GATEWAY_PID)" echo "" echo "================================" echo "All services started successfully!" echo "================================" echo "Trading Service: localhost:50051 (PID: $TRADING_PID)" echo "Backtesting Service: localhost:50052 (PID: $BACKTEST_PID)" echo "ML Training Service: localhost:50053 (PID: $ML_PID)" echo "API Gateway: localhost:50050 (PID: $GATEWAY_PID)" echo "" echo "Environment:" echo " DATABASE: $DATABASE_URL" echo " REDIS: $REDIS_URL" echo " TLS CA: $TLS_CA_PATH" echo "" echo "Logs: ./logs/" echo "" echo "To stop all services: pkill -f '(trading_service|backtesting_service|ml_training_service|api_gateway)'"