veza/scripts/start-veza-complete.sh
2025-12-03 22:56:50 +01:00

256 lines
No EOL
7.1 KiB
Bash

#!/bin/bash
# 🎵 Veza Platform - Script de démarrage complet
# Version 2.0.0
set -e
# Couleurs pour les messages
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
BACKEND_PORT=8080
FRONTEND_PORT=5173
DESKTOP_PORT=5177
echo -e "${PURPLE}🎵 Veza Platform - Démarrage complet${NC}"
echo -e "${CYAN}================================${NC}"
echo ""
# Fonction pour vérifier si un port est utilisé
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null ; then
echo -e "${YELLOW}⚠️ Le port $port est déjà utilisé${NC}"
return 1
fi
return 0
}
# Fonction pour arrêter les processus existants
cleanup() {
echo -e "${YELLOW}🧹 Nettoyage des processus existants...${NC}"
pkill -f "go run.*simple-server" 2>/dev/null || true
pkill -f "vite" 2>/dev/null || true
pkill -f "electron" 2>/dev/null || true
sleep 2
}
# Fonction pour vérifier les dépendances
check_dependencies() {
echo -e "${BLUE}🔍 Vérification des dépendances...${NC}"
# Vérifier Go
if ! command -v go &> /dev/null; then
echo -e "${RED}❌ Go n'est pas installé${NC}"
exit 1
fi
# Vérifier Node.js
if ! command -v node &> /dev/null; then
echo -e "${RED}❌ Node.js n'est pas installé${NC}"
exit 1
fi
# Vérifier npm
if ! command -v npm &> /dev/null; then
echo -e "${RED}❌ npm n'est pas installé${NC}"
exit 1
fi
echo -e "${GREEN}✅ Toutes les dépendances sont installées${NC}"
}
# Fonction pour démarrer le backend
start_backend() {
echo -e "${BLUE}🚀 Démarrage du Backend API...${NC}"
if ! check_port $BACKEND_PORT; then
echo -e "${YELLOW}⚠️ Tentative d'arrêt du processus sur le port $BACKEND_PORT${NC}"
lsof -ti:$BACKEND_PORT | xargs kill -9 2>/dev/null || true
sleep 2
fi
cd veza-backend-api
nohup go run simple-server.go > ../logs/backend.log 2>&1 &
BACKEND_PID=$!
echo $BACKEND_PID > ../logs/backend.pid
# Attendre que le backend démarre
echo -e "${YELLOW}⏳ Attente du démarrage du backend...${NC}"
for i in {1..30}; do
if curl -s http://localhost:$BACKEND_PORT/health > /dev/null 2>&1; then
echo -e "${GREEN}✅ Backend API démarré sur http://localhost:$BACKEND_PORT${NC}"
break
fi
if [ $i -eq 30 ]; then
echo -e "${RED}❌ Échec du démarrage du backend${NC}"
exit 1
fi
sleep 1
done
cd ..
}
# Fonction pour démarrer le frontend
start_frontend() {
echo -e "${BLUE}🌐 Démarrage du Frontend...${NC}"
if ! check_port $FRONTEND_PORT; then
echo -e "${YELLOW}⚠️ Tentative d'arrêt du processus sur le port $FRONTEND_PORT${NC}"
lsof -ti:$FRONTEND_PORT | xargs kill -9 2>/dev/null || true
sleep 2
fi
cd veza-frontend
# Installer les dépendances si nécessaire
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}📦 Installation des dépendances frontend...${NC}"
npm install
fi
nohup npm run dev > ../logs/frontend.log 2>&1 &
FRONTEND_PID=$!
echo $FRONTEND_PID > ../logs/frontend.pid
# Attendre que le frontend démarre
echo -e "${YELLOW}⏳ Attente du démarrage du frontend...${NC}"
for i in {1..30}; do
if curl -s http://localhost:$FRONTEND_PORT > /dev/null 2>&1; then
echo -e "${GREEN}✅ Frontend démarré sur http://localhost:$FRONTEND_PORT${NC}"
break
fi
if [ $i -eq 30 ]; then
echo -e "${RED}❌ Échec du démarrage du frontend${NC}"
exit 1
fi
sleep 1
done
cd ..
}
# Fonction pour démarrer l'application desktop
start_desktop() {
echo -e "${BLUE}🖥️ Démarrage de l'application Desktop...${NC}"
cd veza-desktop
# Installer les dépendances si nécessaire
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}📦 Installation des dépendances desktop...${NC}"
npm install
fi
# Démarrer l'application desktop
nohup npm start > ../logs/desktop.log 2>&1 &
DESKTOP_PID=$!
echo $DESKTOP_PID > ../logs/desktop.pid
echo -e "${GREEN}✅ Application Desktop démarrée${NC}"
cd ..
}
# Fonction pour afficher le statut
show_status() {
echo ""
echo -e "${PURPLE}📊 Statut des services:${NC}"
echo -e "${CYAN}================================${NC}"
# Backend
if curl -s http://localhost:$BACKEND_PORT/health > /dev/null 2>&1; then
echo -e "${GREEN}✅ Backend API: http://localhost:$BACKEND_PORT${NC}"
else
echo -e "${RED}❌ Backend API: Non disponible${NC}"
fi
# Frontend
if curl -s http://localhost:$FRONTEND_PORT > /dev/null 2>&1; then
echo -e "${GREEN}✅ Frontend Web: http://localhost:$FRONTEND_PORT${NC}"
else
echo -e "${RED}❌ Frontend Web: Non disponible${NC}"
fi
# Desktop
if [ -f "logs/desktop.pid" ] && ps -p $(cat logs/desktop.pid) > /dev/null 2>&1; then
echo -e "${GREEN}✅ Application Desktop: En cours d'exécution${NC}"
else
echo -e "${YELLOW}⚠️ Application Desktop: Non démarrée${NC}"
fi
echo ""
echo -e "${PURPLE}🎯 URLs d'accès:${NC}"
echo -e "${CYAN}================================${NC}"
echo -e "${BLUE}🌐 Application Web:${NC} http://localhost:$FRONTEND_PORT"
echo -e "${BLUE}🔌 API Backend:${NC} http://localhost:$BACKEND_PORT"
echo -e "${BLUE}📊 Health Check:${NC} http://localhost:$BACKEND_PORT/health"
echo ""
echo -e "${GREEN}🎉 Veza Platform est prêt !${NC}"
echo -e "${YELLOW}💡 Utilisez Ctrl+C pour arrêter tous les services${NC}"
}
# Fonction de nettoyage à la sortie
cleanup_on_exit() {
echo ""
echo -e "${YELLOW}🔄 Arrêt des services...${NC}"
# Arrêter les processus
if [ -f "logs/backend.pid" ]; then
kill $(cat logs/backend.pid) 2>/dev/null || true
rm -f logs/backend.pid
fi
if [ -f "logs/frontend.pid" ]; then
kill $(cat logs/frontend.pid) 2>/dev/null || true
rm -f logs/frontend.pid
fi
if [ -f "logs/desktop.pid" ]; then
kill $(cat logs/desktop.pid) 2>/dev/null || true
rm -f logs/desktop.pid
fi
echo -e "${GREEN}✅ Services arrêtés${NC}"
exit 0
}
# Configuration du trap pour le nettoyage
trap cleanup_on_exit INT TERM
# Créer le dossier logs s'il n'existe pas
mkdir -p logs
# Démarrage principal
main() {
echo -e "${PURPLE}🎵 Veza Platform - Démarrage complet${NC}"
echo -e "${CYAN}================================${NC}"
echo ""
# Vérifier les dépendances
check_dependencies
# Nettoyer les processus existants
cleanup
# Démarrer les services
start_backend
start_frontend
start_desktop
# Afficher le statut
show_status
# Attendre indéfiniment
while true; do
sleep 10
done
}
# Exécuter le script principal
main "$@"