#!/bin/bash # 🚀 RPA Vision V3 - Lanceur Complet # Auteur : Dom, Alice Kiro # Date : 22 dĂ©cembre 2024 set -e # Couleurs pour l'affichage RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' NC='\033[0m' # No Color # Configuration MAIN_DIR=$(pwd) VWB_DIR="$MAIN_DIR/visual_workflow_builder" LOGS_DIR="$MAIN_DIR/logs" # Fonction d'affichage print_header() { echo -e "${PURPLE}" echo "╔════════════════════════════════════════════════════════════╗" echo "║ 🚀 RPA Vision V3 - Lanceur Complet 🚀 ║" echo "║ Tous les services en une seule commande ║" echo "║ đŸ§č Nettoyage automatique + Backend + Frontend ║" echo "╚════════════════════════════════════════════════════════════╝" echo -e "${NC}" } # Fonction de nettoyage des processus existants cleanup_existing_processes() { echo -e "${BLUE}[0/6] Nettoyage des processus existants...${NC}" local processes_killed=0 # Fonction pour tuer un processus sur un port spĂ©cifique kill_process_on_port() { local port=$1 local service_name=$2 local pid=$(lsof -ti:$port 2>/dev/null) if [ ! -z "$pid" ]; then echo -e "${YELLOW}🔍 Processus trouvĂ© sur le port $port (PID: $pid) - $service_name${NC}" kill -9 $pid 2>/dev/null || true sleep 1 # VĂ©rifier si le processus est vraiment arrĂȘtĂ© if ! kill -0 $pid 2>/dev/null; then echo -e "${GREEN}✓ Processus $service_name arrĂȘtĂ© (port $port)${NC}" processes_killed=$((processes_killed + 1)) else echo -e "${RED}⚠ Impossible d'arrĂȘter le processus sur le port $port${NC}" fi fi } # Tuer les processus sur les ports utilisĂ©s kill_process_on_port 3000 "React Dev Server" kill_process_on_port 5001 "Flask Dashboard" kill_process_on_port 5002 "VWB Backend" kill_process_on_port 8000 "API REST" # Tuer les processus webpack spĂ©cifiques (cause des problĂšmes TypeScript) local webpack_pids=$(pgrep -f "webpack.*serve\|webpack-dev-server\|react-scripts.*start" 2>/dev/null || true) if [ ! -z "$webpack_pids" ]; then echo -e "${YELLOW}🔍 Processus webpack trouvĂ©s: $webpack_pids${NC}" echo "$webpack_pids" | xargs -r kill -9 2>/dev/null || true processes_killed=$((processes_killed + 1)) echo -e "${GREEN}✓ Processus webpack arrĂȘtĂ©s${NC}" fi # Tuer les processus Python spĂ©cifiques local python_pids=$(pgrep -f "python.*app\.py\|python.*server\|python.*dashboard" 2>/dev/null || true) if [ ! -z "$python_pids" ]; then echo -e "${YELLOW}🔍 Processus Python trouvĂ©s: $python_pids${NC}" echo "$python_pids" | xargs -r kill -9 2>/dev/null || true processes_killed=$((processes_killed + 1)) echo -e "${GREEN}✓ Processus Python arrĂȘtĂ©s${NC}" fi # Tuer les processus Node.js spĂ©cifiques local node_pids=$(pgrep -f "node.*start\|npm.*start" 2>/dev/null || true) if [ ! -z "$node_pids" ]; then echo -e "${YELLOW}🔍 Processus Node.js trouvĂ©s: $node_pids${NC}" echo "$node_pids" | xargs -r kill -9 2>/dev/null || true processes_killed=$((processes_killed + 1)) echo -e "${GREEN}✓ Processus Node.js arrĂȘtĂ©s${NC}" fi if [ $processes_killed -gt 0 ]; then echo -e "${GREEN}✓ $processes_killed type(s) de processus nettoyĂ©s${NC}" echo -e "${CYAN}⏳ Attente de 3 secondes pour la libĂ©ration des ports...${NC}" sleep 3 # VĂ©rifier que les ports sont bien libĂ©rĂ©s echo -e "${CYAN}🔍 VĂ©rification de la libĂ©ration des ports...${NC}" for port in 3000 5001 5002 8000; do if lsof -ti:$port >/dev/null 2>&1; then echo -e "${RED}⚠ Le port $port est encore occupĂ©${NC}" else echo -e "${GREEN}✓ Port $port libĂ©rĂ©${NC}" fi done else echo -e "${GREEN}✓ Aucun processus existant Ă  nettoyer${NC}" fi } # Fonction de nettoyage (pour Ctrl+C) cleanup() { echo -e "\n${YELLOW}🛑 ArrĂȘt de tous les services...${NC}" # ArrĂȘter tous les processus en arriĂšre-plan jobs -p | xargs -r kill 2>/dev/null || true # ArrĂȘter les services spĂ©cifiques pkill -f "python.*server" 2>/dev/null || true pkill -f "python.*dashboard" 2>/dev/null || true pkill -f "npm.*start" 2>/dev/null || true pkill -f "node.*server" 2>/dev/null || true pkill -f "webpack.*serve" 2>/dev/null || true echo -e "${GREEN}✓ Tous les services arrĂȘtĂ©s${NC}" exit 0 } # Capturer Ctrl+C trap cleanup SIGINT SIGTERM # Fonction de vĂ©rification des prĂ©requis check_prerequisites() { echo -e "${BLUE}[1/7] VĂ©rification des prĂ©requis...${NC}" # VĂ©rifier Python if ! command -v python3 &> /dev/null; then echo -e "${RED}❌ Python3 non trouvĂ©${NC}" exit 1 fi # VĂ©rifier Node.js if ! command -v node &> /dev/null; then echo -e "${RED}❌ Node.js non trouvĂ©${NC}" exit 1 fi # VĂ©rifier npm if ! command -v npm &> /dev/null; then echo -e "${RED}❌ npm non trouvĂ©${NC}" exit 1 fi # VĂ©rifier l'environnement virtuel if [ ! -d "venv_v3" ]; then echo -e "${RED}❌ Environnement virtuel venv_v3 non trouvĂ©${NC}" exit 1 fi echo -e "${GREEN}✓ Tous les prĂ©requis sont satisfaits${NC}" } # Fonction de prĂ©paration des rĂ©pertoires prepare_directories() { echo -e "${BLUE}[2/7] PrĂ©paration des rĂ©pertoires...${NC}" # CrĂ©er le rĂ©pertoire de logs mkdir -p "$LOGS_DIR" # VĂ©rifier le Visual Workflow Builder if [ ! -d "$VWB_DIR" ]; then echo -e "${RED}❌ Visual Workflow Builder non trouvĂ© dans $VWB_DIR${NC}" exit 1 fi echo -e "${GREEN}✓ RĂ©pertoires prĂ©parĂ©s${NC}" } # Fonction de dĂ©marrage du backend principal start_main_backend() { echo -e "${BLUE}[3/7] DĂ©marrage du backend principal...${NC}" cd "$MAIN_DIR" source venv_v3/bin/activate # Lancer l'API et le dashboard ./run.sh --all > "$LOGS_DIR/main_backend.log" 2>&1 & MAIN_PID=$! # Attendre que les services dĂ©marrent echo -e "${YELLOW}⏳ Attente du dĂ©marrage des services principaux...${NC}" sleep 8 # VĂ©rifier que les services sont dĂ©marrĂ©s if curl -s http://localhost:8000/health > /dev/null 2>&1; then echo -e "${GREEN}✓ API principale dĂ©marrĂ©e (port 8000)${NC}" else echo -e "${YELLOW}⚠ API principale en cours de dĂ©marrage...${NC}" fi if curl -s http://localhost:5001 > /dev/null 2>&1; then echo -e "${GREEN}✓ Dashboard dĂ©marrĂ© (port 5001)${NC}" else echo -e "${YELLOW}⚠ Dashboard en cours de dĂ©marrage...${NC}" fi } # Fonction de dĂ©marrage du Visual Workflow Builder start_visual_workflow_builder() { echo -e "${BLUE}[4/7] DĂ©marrage du Visual Workflow Builder...${NC}" cd "$VWB_DIR" # VĂ©rifier si les dĂ©pendances sont installĂ©es if [ ! -d "frontend/node_modules" ]; then echo -e "${YELLOW}📩 Installation des dĂ©pendances frontend...${NC}" cd frontend npm install > "$LOGS_DIR/npm_install.log" 2>&1 cd .. fi # DĂ©marrer le backend VWB echo -e "${CYAN}🔧 DĂ©marrage du backend VWB...${NC}" source ../venv_v3/bin/activate python backend/app.py > "$LOGS_DIR/vwb_backend.log" 2>&1 & VWB_BACKEND_PID=$! # Attendre un peu sleep 3 # DĂ©marrer le frontend VWB echo -e "${CYAN}🎹 DĂ©marrage du frontend VWB...${NC}" cd frontend npm start > "$LOGS_DIR/vwb_frontend.log" 2>&1 & VWB_FRONTEND_PID=$! cd "$MAIN_DIR" echo -e "${GREEN}✓ Visual Workflow Builder en cours de dĂ©marrage${NC}" } # Fonction de dĂ©marrage du monitoring des logs start_log_monitoring() { echo -e "${BLUE}[5/7] DĂ©marrage du monitoring des logs...${NC}" # CrĂ©er un script de monitoring des logs cat > "$LOGS_DIR/monitor_logs.sh" << 'EOF' #!/bin/bash echo "🔍 Monitoring des logs RPA Vision V3" echo "======================================" echo "" # Fonction pour afficher les logs avec couleurs show_logs() { local service=$1 local logfile=$2 local color=$3 if [ -f "$logfile" ]; then echo -e "${color}=== $service ===${NC}" tail -n 5 "$logfile" 2>/dev/null || echo "Pas encore de logs" echo "" fi } while true; do clear echo "🔍 Monitoring des logs RPA Vision V3 - $(date)" echo "======================================" echo "" show_logs "API Principale" "main_backend.log" "\033[0;32m" show_logs "VWB Backend" "vwb_backend.log" "\033[0;34m" show_logs "VWB Frontend" "vwb_frontend.log" "\033[0;36m" echo "Appuyez sur Ctrl+C pour arrĂȘter le monitoring" sleep 5 done EOF chmod +x "$LOGS_DIR/monitor_logs.sh" echo -e "${GREEN}✓ Script de monitoring créé${NC}" } # Fonction d'affichage du statut final show_final_status() { echo -e "${BLUE}[6/7] Statut final des services...${NC}" echo "" echo -e "${PURPLE}🌐 Services Web Disponibles:${NC}" echo -e "${GREEN} ‱ API REST: http://localhost:8000${NC}" echo -e "${GREEN} ‱ Dashboard Web: http://localhost:5001${NC}" echo -e "${GREEN} ‱ Visual Workflow Builder: http://localhost:3000${NC}" echo -e "${GREEN} ‱ VWB Backend: http://localhost:5002${NC}" echo "" echo -e "${PURPLE}📊 Monitoring et Logs:${NC}" echo -e "${CYAN} ‱ Logs principaux: tail -f $LOGS_DIR/main_backend.log${NC}" echo -e "${CYAN} ‱ Logs VWB Backend: tail -f $LOGS_DIR/vwb_backend.log${NC}" echo -e "${CYAN} ‱ Logs VWB Frontend: tail -f $LOGS_DIR/vwb_frontend.log${NC}" echo -e "${CYAN} ‱ Monitoring interactif: $LOGS_DIR/monitor_logs.sh${NC}" echo "" echo -e "${PURPLE}🔧 Commandes Utiles:${NC}" echo -e "${YELLOW} ‱ Voir tous les logs: tail -f $LOGS_DIR/*.log${NC}" echo -e "${YELLOW} ‱ Tester l'API: curl http://localhost:8000/health${NC}" echo -e "${YELLOW} ‱ ArrĂȘter tout: Ctrl+C dans ce terminal${NC}" echo "" echo -e "${GREEN}🎉 Tous les services sont dĂ©marrĂ©s !${NC}" echo -e "${BLUE}đŸ“± Ouvrez votre navigateur sur les URLs ci-dessus${NC}" } # Fonction de vĂ©rification finale des services verify_services() { echo -e "${BLUE}[7/7] VĂ©rification finale des services...${NC}" local all_services_ok=true # VĂ©rifier l'API REST if curl -s http://localhost:8000/health > /dev/null 2>&1; then echo -e "${GREEN}✓ API REST opĂ©rationnelle (port 8000)${NC}" else echo -e "${RED}❌ API REST non accessible (port 8000)${NC}" all_services_ok=false fi # VĂ©rifier le Dashboard if curl -s http://localhost:5001 > /dev/null 2>&1; then echo -e "${GREEN}✓ Dashboard opĂ©rationnel (port 5001)${NC}" else echo -e "${RED}❌ Dashboard non accessible (port 5001)${NC}" all_services_ok=false fi # VĂ©rifier le VWB Backend if curl -s http://localhost:5002/health > /dev/null 2>&1; then echo -e "${GREEN}✓ VWB Backend opĂ©rationnel (port 5002)${NC}" else echo -e "${YELLOW}⚠ VWB Backend en cours de dĂ©marrage (port 5002)${NC}" fi # VĂ©rifier le VWB Frontend (React) if curl -s http://localhost:3000 > /dev/null 2>&1; then echo -e "${GREEN}✓ VWB Frontend opĂ©rationnel (port 3000)${NC}" else echo -e "${YELLOW}⚠ VWB Frontend en cours de dĂ©marrage (port 3000)${NC}" fi if [ "$all_services_ok" = true ]; then echo -e "${GREEN}🎉 Tous les services critiques sont opĂ©rationnels !${NC}" else echo -e "${YELLOW}⚠ Certains services sont encore en cours de dĂ©marrage${NC}" echo -e "${CYAN}💡 Attendez quelques secondes et vĂ©rifiez manuellement les URLs${NC}" fi } # Fonction principale main() { print_header cleanup_existing_processes check_prerequisites prepare_directories start_main_backend start_visual_workflow_builder start_log_monitoring show_final_status verify_services echo -e "\n${YELLOW}⏳ Services en cours d'exĂ©cution... Appuyez sur Ctrl+C pour tout arrĂȘter${NC}" echo -e "${CYAN}💡 Tip: Ouvrez un autre terminal pour utiliser les commandes de monitoring${NC}" # Attendre indĂ©finiment while true; do sleep 1 done } # Lancer le script principal main "$@"