- Frontend v4 accessible sur réseau local (192.168.1.40) - Ports ouverts: 3002 (frontend), 5001 (backend), 5004 (dashboard) - Ollama GPU fonctionnel - Self-healing interactif - Dashboard confiance Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
306 lines
9.4 KiB
Python
Executable File
306 lines
9.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Script de correction complète du système RPA Vision V3
|
|
Résout les problèmes identifiés :
|
|
- Processus GPU en boucle
|
|
- Conflits de ports
|
|
- Scripts de lancement incohérents
|
|
- Problèmes de sécurité
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import signal
|
|
import time
|
|
import psutil
|
|
from pathlib import Path
|
|
|
|
def print_header(title):
|
|
print(f"\n{'='*60}")
|
|
print(f"🔧 {title}")
|
|
print(f"{'='*60}")
|
|
|
|
def kill_rpa_processes():
|
|
"""Arrête tous les processus RPA Vision V3."""
|
|
print_header("NETTOYAGE DES PROCESSUS")
|
|
|
|
killed_count = 0
|
|
|
|
# Processus à arrêter
|
|
patterns = [
|
|
"server/api_upload.py",
|
|
"web_dashboard/app.py",
|
|
"server/worker_daemon.py",
|
|
"monitoring_server.py",
|
|
"agent_v0/main.py"
|
|
]
|
|
|
|
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
|
try:
|
|
cmdline = ' '.join(proc.info['cmdline'] or [])
|
|
|
|
for pattern in patterns:
|
|
if pattern in cmdline and 'rpa_vision_v3' in cmdline:
|
|
print(f"🔍 Processus trouvé: PID {proc.info['pid']} - {pattern}")
|
|
try:
|
|
proc.terminate()
|
|
proc.wait(timeout=5)
|
|
print(f"✅ Processus {proc.info['pid']} arrêté")
|
|
killed_count += 1
|
|
except (psutil.NoSuchProcess, psutil.TimeoutExpired):
|
|
try:
|
|
proc.kill()
|
|
print(f"🔥 Processus {proc.info['pid']} forcé")
|
|
killed_count += 1
|
|
except psutil.NoSuchProcess:
|
|
pass
|
|
break
|
|
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
|
continue
|
|
|
|
# Libérer les ports spécifiques
|
|
ports = [8000, 5001, 5002, 5003, 3000]
|
|
for port in ports:
|
|
try:
|
|
result = subprocess.run(['lsof', '-ti', f':{port}'],
|
|
capture_output=True, text=True)
|
|
if result.stdout.strip():
|
|
pids = result.stdout.strip().split('\n')
|
|
for pid in pids:
|
|
try:
|
|
os.kill(int(pid), signal.SIGTERM)
|
|
print(f"🔌 Port {port} libéré (PID {pid})")
|
|
killed_count += 1
|
|
except (ProcessLookupError, ValueError):
|
|
pass
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
if killed_count > 0:
|
|
print(f"✅ {killed_count} processus nettoyés")
|
|
time.sleep(3) # Attendre la libération des ressources
|
|
else:
|
|
print("✅ Aucun processus RPA à nettoyer")
|
|
|
|
def fix_env_config():
|
|
"""Corrige la configuration d'environnement."""
|
|
print_header("CORRECTION CONFIGURATION")
|
|
|
|
env_path = Path(".env.local")
|
|
|
|
if env_path.exists():
|
|
# Lire la config actuelle
|
|
with open(env_path, 'r') as f:
|
|
content = f.read()
|
|
|
|
# Corrections nécessaires
|
|
fixes = [
|
|
("RPA_AUTH_DISABLED=true", "RPA_AUTH_DISABLED=false"),
|
|
("RPA_AUTH_REQUIRED=false", "RPA_AUTH_REQUIRED=true"),
|
|
]
|
|
|
|
modified = False
|
|
for old, new in fixes:
|
|
if old in content:
|
|
content = content.replace(old, new)
|
|
modified = True
|
|
print(f"🔧 Corrigé: {old} → {new}")
|
|
|
|
if modified:
|
|
with open(env_path, 'w') as f:
|
|
f.write(content)
|
|
print("✅ Configuration .env.local corrigée")
|
|
else:
|
|
print("✅ Configuration .env.local OK")
|
|
else:
|
|
print("⚠️ Fichier .env.local non trouvé")
|
|
|
|
def fix_faiss_manager():
|
|
"""Corrige le problème FAISSManager dimension."""
|
|
print_header("CORRECTION FAISS MANAGER")
|
|
|
|
faiss_path = Path("core/embedding/faiss_manager.py")
|
|
if faiss_path.exists():
|
|
with open(faiss_path, 'r') as f:
|
|
content = f.read()
|
|
|
|
# Corriger l'initialisation FAISSManager
|
|
if "FAISSManager(dimensions=" in content:
|
|
content = content.replace("FAISSManager(dimensions=", "FAISSManager(dimension=")
|
|
with open(faiss_path, 'w') as f:
|
|
f.write(content)
|
|
print("✅ FAISSManager corrigé (dimensions → dimension)")
|
|
else:
|
|
print("✅ FAISSManager OK")
|
|
else:
|
|
print("⚠️ FAISSManager non trouvé")
|
|
|
|
def create_unified_launcher():
|
|
"""Crée un lanceur unifié et cohérent."""
|
|
print_header("CRÉATION LANCEUR UNIFIÉ")
|
|
|
|
launcher_content = '''#!/bin/bash
|
|
# RPA Vision V3 - Lanceur Unifié Corrigé
|
|
# Date: 6 janvier 2026
|
|
|
|
set -e
|
|
|
|
RED='\\033[0;31m'
|
|
GREEN='\\033[0;32m'
|
|
YELLOW='\\033[1;33m'
|
|
BLUE='\\033[0;34m'
|
|
PURPLE='\\033[0;35m'
|
|
NC='\\033[0m'
|
|
|
|
echo -e "${PURPLE}🎼 RPA Vision V3 - Lanceur Unifié Corrigé${NC}"
|
|
echo ""
|
|
|
|
# Nettoyage préventif
|
|
echo -e "${BLUE}[1/5] Nettoyage préventif...${NC}"
|
|
pkill -f "python.*server\\|python.*dashboard\\|python.*api_upload" 2>/dev/null || true
|
|
sleep 2
|
|
|
|
# Vérification environnement
|
|
echo -e "${BLUE}[2/5] Vérification environnement...${NC}"
|
|
if [ ! -d "venv_v3" ]; then
|
|
echo -e "${RED}❌ venv_v3 non trouvé${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
source venv_v3/bin/activate
|
|
|
|
# Correction des problèmes identifiés
|
|
echo -e "${BLUE}[3/5] Application des corrections...${NC}"
|
|
python3 fix_system_complete.py --fix-only 2>/dev/null || true
|
|
|
|
# Choix du mode
|
|
MODE="${1:-gui}"
|
|
|
|
echo -e "${BLUE}[4/5] Lancement mode: $MODE${NC}"
|
|
|
|
case $MODE in
|
|
--server|server)
|
|
echo -e "${GREEN}🌐 Lancement API Server (port 8000)${NC}"
|
|
python3 server/api_upload.py
|
|
;;
|
|
--dashboard|dashboard)
|
|
echo -e "${PURPLE}📊 Lancement Dashboard (port 5001)${NC}"
|
|
python3 web_dashboard/app.py
|
|
;;
|
|
--agent|agent)
|
|
echo -e "${CYAN}📹 Lancement Agent V0${NC}"
|
|
cd agent_v0
|
|
../venv_v3/bin/python3 main.py
|
|
cd ..
|
|
;;
|
|
--all|all)
|
|
echo -e "${GREEN}🚀 Lancement complet${NC}"
|
|
python3 server/api_upload.py &
|
|
sleep 3
|
|
python3 web_dashboard/app.py &
|
|
sleep 2
|
|
echo -e "${GREEN}✅ Services démarrés${NC}"
|
|
echo "API: http://localhost:8000"
|
|
echo "Dashboard: http://localhost:5001"
|
|
wait
|
|
;;
|
|
--gui|gui|*)
|
|
echo -e "${CYAN}🖥️ Lancement GUI${NC}"
|
|
python3 run_gui.py
|
|
;;
|
|
esac
|
|
|
|
echo -e "${BLUE}[5/5] Terminé${NC}"
|
|
'''
|
|
|
|
with open("launch_fixed.sh", 'w') as f:
|
|
f.write(launcher_content)
|
|
|
|
os.chmod("launch_fixed.sh", 0o755)
|
|
print("✅ Lanceur unifié créé: launch_fixed.sh")
|
|
|
|
def verify_system():
|
|
"""Vérifie l'état du système après corrections."""
|
|
print_header("VÉRIFICATION SYSTÈME")
|
|
|
|
checks = [
|
|
("Environnement virtuel", Path("venv_v3").exists()),
|
|
("Configuration .env.local", Path(".env.local").exists()),
|
|
("Module server", Path("server/api_upload.py").exists()),
|
|
("Module dashboard", Path("web_dashboard/app.py").exists()),
|
|
("Module agent_v0", Path("agent_v0/main.py").exists()),
|
|
("Répertoire data", Path("data").exists()),
|
|
("Répertoire logs", Path("logs").exists()),
|
|
]
|
|
|
|
all_ok = True
|
|
for name, status in checks:
|
|
if status:
|
|
print(f"✅ {name}")
|
|
else:
|
|
print(f"❌ {name}")
|
|
all_ok = False
|
|
|
|
# Vérifier les ports libres
|
|
ports_status = []
|
|
for port in [8000, 5001, 5002, 5003]:
|
|
try:
|
|
result = subprocess.run(['lsof', '-ti', f':{port}'],
|
|
capture_output=True, text=True)
|
|
if result.stdout.strip():
|
|
ports_status.append(f"❌ Port {port} occupé")
|
|
all_ok = False
|
|
else:
|
|
ports_status.append(f"✅ Port {port} libre")
|
|
except FileNotFoundError:
|
|
ports_status.append(f"✅ Port {port} libre (lsof n/a)")
|
|
|
|
for status in ports_status:
|
|
print(status)
|
|
|
|
if all_ok:
|
|
print(f"\n🎉 SYSTÈME PRÊT !")
|
|
print(f"\nCommandes disponibles:")
|
|
print("./launch_fixed.sh --server # API seule")
|
|
print("./launch_fixed.sh --dashboard # Dashboard seul")
|
|
print("./launch_fixed.sh --agent # Agent V0")
|
|
print("./launch_fixed.sh --all # Tous les services")
|
|
print("./launch_fixed.sh --gui # Interface GUI (défaut)")
|
|
else:
|
|
print(f"\n⚠️ Certains problèmes persistent")
|
|
|
|
return all_ok
|
|
|
|
def main():
|
|
if len(sys.argv) > 1 and sys.argv[1] == "--fix-only":
|
|
# Mode correction silencieuse (appelé par le lanceur)
|
|
fix_env_config()
|
|
fix_faiss_manager()
|
|
return
|
|
|
|
print("🔧 RPA Vision V3 - Correction Complète du Système")
|
|
print("=" * 60)
|
|
|
|
try:
|
|
kill_rpa_processes()
|
|
fix_env_config()
|
|
fix_faiss_manager()
|
|
create_unified_launcher()
|
|
|
|
if verify_system():
|
|
print(f"\n✅ CORRECTION TERMINÉE AVEC SUCCÈS !")
|
|
print(f"\nPour tester le système :")
|
|
print(f" ./launch_fixed.sh --server")
|
|
else:
|
|
print(f"\n⚠️ CORRECTION PARTIELLE - Vérifiez les erreurs ci-dessus")
|
|
|
|
except KeyboardInterrupt:
|
|
print(f"\n🛑 Correction interrompue")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print(f"\n❌ Erreur lors de la correction: {e}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main() |