#!/bin/bash # start_all.sh # Démarre l'API et le Dashboard en mode développement set -e echo "========================================" echo "RPA Vision V3 - Démarrage Complet" echo "========================================" echo "" # Détecter le répertoire du projet SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" echo "📁 Répertoire projet: $PROJECT_DIR" echo "" # Vérifier l'environnement virtuel if [ ! -d "$PROJECT_DIR/venv_v3" ]; then echo "❌ Environnement virtuel non trouvé: $PROJECT_DIR/venv_v3" echo " Créez-le avec: python3 -m venv venv_v3" exit 1 fi # Activer l'environnement virtuel source "$PROJECT_DIR/venv_v3/bin/activate" # Fiche #23 - Anti-oubli tokens (DEV) chmod +x "$SCRIPT_DIR/bootstrap_local_env.sh" 2>/dev/null || true "$SCRIPT_DIR/bootstrap_local_env.sh" >/dev/null || true # Vérifier les dépendances echo "📦 Vérification des dépendances..." # Installer les dépendances serveur si nécessaire if ! python -c "import fastapi" 2>/dev/null; then echo "Installation des dépendances serveur..." pip install -r "$SCRIPT_DIR/requirements_server.txt" fi if ! python -c "import flask" 2>/dev/null; then echo "Installation des dépendances dashboard..." pip install -r "$PROJECT_DIR/web_dashboard/requirements.txt" fi echo "✅ Dépendances OK" echo "" # Créer les répertoires nécessaires mkdir -p "$PROJECT_DIR/data/training/uploads" mkdir -p "$PROJECT_DIR/data/training/sessions" mkdir -p "$PROJECT_DIR/logs" # Configuration (bootstrap_local_env.sh charge déjà les variables) export ENCRYPTION_PASSWORD="${ENCRYPTION_PASSWORD:-rpa_vision_v3_default_key}" # Fonction pour arrêter proprement cleanup() { echo "" echo "🛑 Arrêt des services..." kill $API_PID 2>/dev/null || true kill $DASHBOARD_PID 2>/dev/null || true exit 0 } trap cleanup SIGINT SIGTERM # Démarrer l'API echo "🚀 Démarrage de l'API (port 8000)..." cd "$SCRIPT_DIR" python api_upload.py > "$PROJECT_DIR/logs/api.log" 2>&1 & API_PID=$! # Attendre que l'API démarre sleep 2 if ! kill -0 $API_PID 2>/dev/null; then echo "❌ Erreur démarrage API" cat "$PROJECT_DIR/logs/api.log" exit 1 fi echo "✅ API démarrée (PID: $API_PID)" echo "" # Démarrer le Dashboard echo "🚀 Démarrage du Dashboard (port 5001)..." cd "$PROJECT_DIR/web_dashboard" python app.py > "$PROJECT_DIR/logs/dashboard.log" 2>&1 & DASHBOARD_PID=$! # Attendre que le Dashboard démarre sleep 2 if ! kill -0 $DASHBOARD_PID 2>/dev/null; then echo "❌ Erreur démarrage Dashboard" cat "$PROJECT_DIR/logs/dashboard.log" kill $API_PID 2>/dev/null || true exit 1 fi echo "✅ Dashboard démarré (PID: $DASHBOARD_PID)" echo "" # Afficher les informations echo "========================================" echo "✅ Services démarrés!" echo "========================================" echo "" echo "🌐 URLs:" echo " API: http://localhost:8000" echo " Dashboard: http://localhost:5001/?token=${RPA_TOKEN_READONLY:-}" echo "" echo "📝 Logs:" echo " API: tail -f $PROJECT_DIR/logs/api.log" echo " Dashboard: tail -f $PROJECT_DIR/logs/dashboard.log" echo "" echo "🔑 Encryption password: ${ENCRYPTION_PASSWORD:0:3}***" echo "" echo "📊 Test API:" echo " curl -H \"Authorization: Bearer ${RPA_TOKEN_READONLY:-}\" http://localhost:8000/api/traces/status" echo "" echo "🛑 Appuyez sur Ctrl+C pour arrêter" echo "" # Attendre wait