#!/bin/bash set -e # Colors GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[0;33m' RED='\033[0;31m' NC='\033[0m' echo -e "${BLUE}🚀 Force-Starting Veza Web (Boot Mode)...${NC}" echo -e "${YELLOW}⚠️ WARNING: Many services will be disabled or mocked.${NC}" # ========================================== # 1. Force Environment Configuration # ========================================== # We export these BEFORE loading .env so they take precedence if .env exists, # or we just rely on the fact that we set them here. export VEZA_MODE=boot # Disable RabbitMQ (Message Broker) export RABBITMQ_ENABLE=false export RABBITMQ_URL="" # Disable ClamAV (Virus Scanning) export ENABLE_CLAMAV=false export CLAMAV_REQUIRED=false # Disable S3 (File Storage) export AWS_S3_ENABLED=false # Disable Config Watcher (Hot Reload Config) export CONFIG_WATCH=false # Ensure Redis is Enabled (Needed for Session/Auth) export REDIS_ENABLE=true # Ensure Database is Enabled # export DATABASE_URL (Assumed from .env or set below) # Load other vars from .env if present, but DO NOT override the above if [ -f .env ]; then echo -e "${BLUE}📄 Loading .env (skipping forced overrides)...${NC}" # Using set -a to export variables set -a # Source .env but ignore lines that would overwrite our forced vars # Actually, standard sourcing overwrites. We need to be careful. # Strategy: Load .env first, THEN enforce overrides. source .env set +a fi # RE-ENFORCE OVERRIDES because .env might have overwritten them export RABBITMQ_ENABLE=false export ENABLE_CLAMAV=false export CLAMAV_REQUIRED=false export AWS_S3_ENABLED=false export CONFIG_WATCH=false echo -e "${BLUE}🔧 Active Configuration:${NC}" echo -e " RABBITMQ_ENABLE: ${RED}$RABBITMQ_ENABLE${NC}" echo -e " ENABLE_CLAMAV: ${RED}$ENABLE_CLAMAV${NC}" echo -e " AWS_S3_ENABLED: ${RED}$AWS_S3_ENABLED${NC}" # ========================================== # 2. Infra (Postgres + Redis ONLY) # ========================================== echo -e "${BLUE}📦 Starting Critical Infra (Postgres + Redis)...${NC}" # We explicitly do NOT start rabbitmq docker compose -f docker-compose.yml up -d postgres redis # Wait for DB echo -e "${BLUE}⏳ Waiting for DB...${NC}" until docker compose -f docker-compose.yml exec -T postgres pg_isready -U veza > /dev/null 2>&1; do echo -n "."; sleep 1; done echo -e " ${GREEN}OK${NC}" # ========================================== # 3. Migrations # ========================================== echo -e "${BLUE}🔄 Checking Migrations...${NC}" # We assume the user has Go installed or we should use docker? # The original script used local Go. We stick to that. if command -v go &> /dev/null; then (cd veza-backend-api && go run cmd/migrate_tool/main.go up) || echo -e "${YELLOW}⚠️ Migration failed (ignoring in boot mode)${NC}" else echo -e "${YELLOW}⚠️ Go not found, skipping migrations.${NC}" fi # ========================================== # 4. Start Backend # ========================================== echo -e "${BLUE}⚙️ Starting Backend API (port 8080)...${NC}" # Check if port 8080 is busy if lsof -i :8080 -t >/dev/null 2>&1; then echo -e "${YELLOW}⚠️ Port 8080 is busy. Killing old process...${NC}" kill -9 $(lsof -t -i:8080) || true fi # Start Backend in background (cd veza-backend-api && go run cmd/api/main.go) > backend_boot.log 2>&1 & BACKEND_PID=$! echo $BACKEND_PID > backend.pid echo -e "${GREEN}✅ Backend running (PID: $BACKEND_PID). Logs: backend_boot.log${NC}" # ========================================== # 5. Start Frontend # ========================================== echo -e "${BLUE}🎨 Starting Frontend (port 5173)...${NC}" # Check if port 5173 is busy if lsof -i :5173 -t >/dev/null 2>&1; then echo -e "${YELLOW}⚠️ Port 5173 is busy. Killing old process...${NC}" kill -9 $(lsof -t -i:5173) || true fi (cd apps/web && npm run dev) > frontend_boot.log 2>&1 & FRONTEND_PID=$! echo $FRONTEND_PID > frontend.pid echo -e "${GREEN}✅ boot mode active.${NC}" echo -e "${GREEN}👉 App: http://localhost:5173${NC}" echo -e "${BLUE}Type 'kill $BACKEND_PID $FRONTEND_PID' to stop manually if needed.${NC}" # Wait for frontend to ensure script doesn't exit immediately wait $FRONTEND_PID