veza/start_recovery.sh

112 lines
3.9 KiB
Bash
Raw Normal View History

#!/bin/bash
# Script de démarrage Veza avec vérification des ports
# P2.4: Vérifie que les ports sont libres avant de démarrer
set -e
cd "$(dirname "$0")"
# P2.4: Function to check if a port is in use
check_port() {
local port=$1
local service=$2
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1 ; then
echo "❌ Port $port already in use (required for $service)"
echo " Process using port: $(lsof -ti:$port | head -1)"
echo " Kill process: kill \$(lsof -t -i:$port)"
echo ""
return 1
fi
echo "✅ Port $port is available ($service)"
return 0
}
echo "🔍 Checking port availability..."
echo ""
# Check all required ports
PORTS_OK=true
check_port 8080 "Backend API" || PORTS_OK=false
check_port 5173 "Frontend (Vite)" || PORTS_OK=false
if [ "$PORTS_OK" = false ]; then
echo ""
echo "═══════════════════════════════════════════════════════════"
echo "❌ Cannot start: One or more ports are in use"
echo "═══════════════════════════════════════════════════════════"
echo ""
echo "Options:"
echo " 1. Kill processes manually: kill \$(lsof -t -i:8080 -i:5173)"
echo " 2. Use start_mvp.sh (kills processes automatically)"
echo ""
exit 1
fi
echo ""
echo "═══════════════════════════════════════════════════════════"
echo "✅ All ports available, starting services..."
echo "═══════════════════════════════════════════════════════════"
echo ""
# Nettoyer les fichiers temporaires
rm -f backend.pid frontend.pid backend.log frontend.log 2>/dev/null || true
echo "🔨 Compiling backend..."
cd veza-backend-api
if [ ! -f "bin/veza-api" ]; then
go build -o bin/veza-api ./cmd/api
echo "✅ Backend compiled"
else
echo "✅ Backend binary already present"
fi
echo "👤 Creating test user..."
TEST_EMAIL=test@veza.app TEST_PASSWORD=test123 TEST_USERNAME=testuser go run cmd/tools/create_test_user/main.go 2>&1 | grep -E "(Created|Updated|Email|Username|Password)" || echo "⚠️ User may already exist"
echo "🚀 Starting backend..."
echo "🚀 Starting backend..."
# Stay in veza-backend-api directory to ensure correct CWD for migrations/config
nohup ./bin/veza-api > ../backend.log 2>&1 &
echo $! > ../backend.pid
echo "✅ Backend started (PID: $(cat ../backend.pid))"
cd ..
sleep 3
echo "🌐 Starting frontend..."
cd apps/web
nohup npm run dev > ../../frontend.log 2>&1 &
echo $! > ../../frontend.pid
echo "✅ Frontend started (PID: $(cat ../../frontend.pid))"
cd ../..
sleep 3
echo ""
echo "═══════════════════════════════════════════════════════════"
echo "✅ Veza started successfully!"
echo "═══════════════════════════════════════════════════════════"
echo ""
echo "🌐 Frontend : http://localhost:5173"
echo "🔧 Backend : http://localhost:8080"
echo "🏥 Health : http://localhost:8080/api/v1/health"
echo ""
echo "🔐 Test credentials:"
echo " Email : test@veza.app"
echo " Username : testuser"
echo " Password : test123"
echo ""
echo "📋 View logs:"
echo " Backend : tail -f backend.log"
echo " Frontend : tail -f frontend.log"
echo ""
echo "🛑 Stop services:"
echo " pkill -f veza-api && pkill -f vite"
echo ""
echo "═══════════════════════════════════════════════════════════"