- 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>
149 lines
4.5 KiB
Python
149 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Démarre simplement le serveur API local pour le développement.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
import subprocess
|
|
import requests
|
|
from pathlib import Path
|
|
|
|
def load_env_local():
|
|
"""Charge les variables d'environnement depuis .env.local"""
|
|
env_path = Path(".env.local")
|
|
if not env_path.exists():
|
|
print("❌ Fichier .env.local non trouvé")
|
|
return False
|
|
|
|
print(f"📁 Chargement de {env_path}")
|
|
with open(env_path, 'r') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if line and not line.startswith('#') and '=' in line:
|
|
key, value = line.split('=', 1)
|
|
os.environ[key.strip()] = value.strip()
|
|
return True
|
|
|
|
def find_free_port(start_port=8001):
|
|
"""Trouve un port libre"""
|
|
import socket
|
|
for port in range(start_port, start_port + 10):
|
|
try:
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
s.bind(('127.0.0.1', port))
|
|
return port
|
|
except OSError:
|
|
continue
|
|
return None
|
|
|
|
def create_dev_server_script(port):
|
|
"""Crée un script serveur temporaire avec le bon port"""
|
|
server_dir = Path("server")
|
|
original_script = server_dir / "api_upload.py"
|
|
|
|
if not original_script.exists():
|
|
print("❌ Fichier server/api_upload.py non trouvé")
|
|
return None
|
|
|
|
# Lire le script original
|
|
with open(original_script, 'r') as f:
|
|
content = f.read()
|
|
|
|
# Remplacer le port hardcodé
|
|
modified_content = content.replace(
|
|
'port=8000,',
|
|
f'port={port},'
|
|
)
|
|
|
|
# Créer un fichier temporaire
|
|
temp_script = server_dir / f"api_upload_dev_{port}.py"
|
|
with open(temp_script, 'w') as f:
|
|
f.write(modified_content)
|
|
|
|
return temp_script
|
|
|
|
def main():
|
|
"""Démarre le serveur de développement"""
|
|
print("🚀 === SERVEUR API DÉVELOPPEMENT ===")
|
|
|
|
# Charger les variables d'environnement
|
|
if not load_env_local():
|
|
return False
|
|
|
|
# Trouver un port libre
|
|
port = find_free_port(8001)
|
|
if not port:
|
|
print("❌ Aucun port libre trouvé")
|
|
return False
|
|
|
|
print(f"🌐 Port sélectionné: {port}")
|
|
|
|
# Créer le script serveur temporaire
|
|
temp_script = create_dev_server_script(port)
|
|
if not temp_script:
|
|
return False
|
|
|
|
# Vérifier l'environnement virtuel
|
|
venv_python = Path("venv_v3/bin/python3")
|
|
if not venv_python.exists():
|
|
print("❌ Environnement virtuel venv_v3 non trouvé")
|
|
return False
|
|
|
|
print(f"🚀 Démarrage du serveur sur le port {port}...")
|
|
print(f" URL: http://127.0.0.1:{port}")
|
|
print(f" Token: {os.environ.get('RPA_TOKEN_ADMIN', 'N/A')[:16]}...")
|
|
|
|
try:
|
|
# Démarrer le serveur
|
|
process = subprocess.Popen([
|
|
str(venv_python.absolute()), temp_script.name
|
|
], cwd="server", env=os.environ.copy())
|
|
|
|
print(f" PID: {process.pid}")
|
|
|
|
# Attendre un peu que le serveur démarre
|
|
print("⏳ Attente du démarrage...")
|
|
time.sleep(5)
|
|
|
|
# Test simple
|
|
try:
|
|
response = requests.get(f"http://127.0.0.1:{port}/health", timeout=2)
|
|
if response.status_code in [200, 401]:
|
|
print("✅ Serveur démarré et accessible!")
|
|
else:
|
|
print(f"⚠️ Serveur répond avec code {response.status_code}")
|
|
except:
|
|
print("⚠️ Serveur pas encore complètement prêt")
|
|
|
|
# Sauvegarder les informations
|
|
import json
|
|
info = {
|
|
"pid": process.pid,
|
|
"port": port,
|
|
"temp_script": str(temp_script),
|
|
"started_at": time.strftime("%Y-%m-%d %H:%M:%S")
|
|
}
|
|
|
|
with open("dev_server_info.json", "w") as f:
|
|
json.dump(info, f, indent=2)
|
|
|
|
print("\\n🎉 === SERVEUR PRÊT ===")
|
|
print(f"✅ URL: http://127.0.0.1:{port}")
|
|
print(f"✅ PID: {process.pid}")
|
|
print("✅ Informations sauvegardées dans dev_server_info.json")
|
|
print("\\n📝 UTILISATION:")
|
|
print("1. Démarrer l'agent v0: cd agent_v0 && python main.py")
|
|
print("2. Pour arrêter: python3 stop_dev_server.py")
|
|
|
|
# Le serveur continue à tourner en arrière-plan
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Erreur démarrage serveur: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
exit(0 if success else 1) |