feat(dev): add start_recovery.sh with port checks

Created start_recovery.sh script with port availability checks
before starting services, preventing conflicts and startup failures.

Features:
- check_port() function validates ports 8080 and 5173
- Shows which process is using a port if occupied
- Provides clear instructions to kill processes
- Exits early if ports unavailable (fail-fast)
- Includes health endpoint URL in success message

Benefits:
- Prevents "address already in use" errors
- Clear error messages with remediation steps
- No silent failures or zombie processes
- Matches user's workflow (./start_recovery.sh)

Usage:
  ./start_recovery.sh

If ports in use:
  kill $(lsof -t -i:8080 -i:5173)

Impact: Eliminates port conflict issues in development.

Fixes: P2.4 from audit AUDIT_TEMP_29_01_2026.md
This commit is contained in:
senke 2026-01-29 23:24:03 +01:00
parent 2628391e69
commit 0f5e5fcdd3

107
start_recovery.sh Executable file
View file

@ -0,0 +1,107 @@
#!/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..."
cd ..
nohup ./veza-backend-api/bin/veza-api > backend.log 2>&1 &
echo $! > backend.pid
echo "✅ Backend started (PID: $(cat backend.pid))"
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 "═══════════════════════════════════════════════════════════"