startup-auto.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #!/bin/bash
  2. # WaouW v2.0 - Démarrage 100% Automatique
  3. # Ce script s'exécute au boot et gère tout automatiquement
  4. LOG_FILE="/var/log/waouw-startup.log"
  5. exec > >(tee -a "$LOG_FILE") 2>&1
  6. echo "=== WaouW v2.0 - Démarrage Automatique $(date) ==="
  7. # Fonction de logging
  8. log() {
  9. echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
  10. }
  11. # Attendre que le système soit prêt
  12. log "Attente initialisation système..."
  13. sleep 30
  14. # Installer Docker si nécessaire
  15. if ! command -v docker &> /dev/null; then
  16. log "Installation de Docker..."
  17. if curl -fsSL https://get.docker.com | sh; then
  18. log "Docker installé avec succès"
  19. systemctl enable docker
  20. systemctl start docker
  21. sleep 5
  22. else
  23. log "ERREUR: Échec installation Docker"
  24. exit 1
  25. fi
  26. fi
  27. # Aller dans le répertoire de déploiement
  28. cd /opt/waouw/DEPLOY || {
  29. log "ERREUR: Répertoire /opt/waouw/DEPLOY introuvable"
  30. exit 1
  31. }
  32. # Fonction de correction automatique
  33. auto_fix() {
  34. log "Application des corrections automatiques..."
  35. # 1. Corriger docker-compose vs docker compose
  36. if grep -q "docker-compose" auto-install.sh; then
  37. sed -i 's/docker-compose/docker compose/g' auto-install.sh
  38. log "Correction Docker Compose appliquée"
  39. fi
  40. # 2. Corriger les noms de services
  41. sed -i 's/waouw-backend/backend/g' auto-install.sh 2>/dev/null || true
  42. sed -i 's/waouw-ui/frontend/g' auto-install.sh 2>/dev/null || true
  43. # 3. Corriger Redis version conflict
  44. if [ -f "../BACKEND/requirements.txt" ]; then
  45. sed -i 's/redis==5.0.1/redis==4.5.4/' ../BACKEND/requirements.txt 2>/dev/null || true
  46. log "Version Redis corrigée"
  47. fi
  48. # 4. S'assurer que .env existe
  49. if [ ! -f "../.env" ]; then
  50. log "Création du fichier .env manquant..."
  51. cat > ../.env << 'EOF'
  52. WAOUW_DOMAIN=waouw.local
  53. ACME_EMAIL=ssl-agent@waouw.tech
  54. POSTGRES_PASSWORD=waouw123
  55. DATABASE_URL=postgresql://waouw:waouw123@postgres:5432/waouw
  56. JWT_SECRET_KEY=auto-secret-key-2024
  57. DEVICE_HMAC_SECRET=auto-device-secret-2024
  58. REDIS_URL=redis://redis:6379/0
  59. TZ=Europe/Paris
  60. EOF
  61. fi
  62. # 5. Corriger la configuration frontend pour accès direct
  63. if grep -q "7165:80" docker-compose.yml; then
  64. log "Correction configuration frontend pour accès direct..."
  65. sed -i '/ports:/,/7165:80/d' docker-compose.yml
  66. log "Configuration frontend corrigée"
  67. fi
  68. # 6. Vérifier la configuration Traefik
  69. if [ ! -d "/etc/waouw/traefik" ]; then
  70. mkdir -p /etc/waouw/traefik
  71. cat > /etc/waouw/traefik/traefik.yml << 'EOF'
  72. global:
  73. checkNewVersion: false
  74. sendAnonymousUsage: false
  75. log:
  76. level: INFO
  77. api:
  78. dashboard: true
  79. insecure: true
  80. entryPoints:
  81. web:
  82. address: ":80"
  83. websecure:
  84. address: ":443"
  85. providers:
  86. docker:
  87. endpoint: "unix:///var/run/docker.sock"
  88. exposedByDefault: false
  89. network: waouw_traefik
  90. file:
  91. directory: /config
  92. watch: true
  93. certificatesResolvers:
  94. letsencrypt:
  95. acme:
  96. email: admin@waouw.local
  97. storage: /certificates/acme.json
  98. httpChallenge:
  99. entryPoint: web
  100. EOF
  101. log "Configuration Traefik créée"
  102. fi
  103. }
  104. # Fonction de démarrage des services
  105. start_services() {
  106. log "Démarrage des services..."
  107. # PostgreSQL en premier
  108. log "Démarrage PostgreSQL..."
  109. docker compose up -d postgres
  110. sleep 15
  111. # Redis
  112. log "Démarrage Redis..."
  113. docker compose up -d redis
  114. sleep 10
  115. # Traefik
  116. log "Démarrage Traefik..."
  117. docker compose up -d traefik
  118. sleep 10 # Attendre que Traefik soit prêt
  119. # Backend
  120. log "Démarrage Backend..."
  121. docker compose up -d backend
  122. sleep 10
  123. }
  124. # Fonction de vérification
  125. verify_services() {
  126. log "Vérification des services..."
  127. # Attendre que tout soit stable
  128. sleep 30
  129. # Vérifier PostgreSQL
  130. if docker exec waouw_postgres pg_isready -U waouw >/dev/null 2>&1; then
  131. log "✅ PostgreSQL opérationnel"
  132. else
  133. log "❌ PostgreSQL problème"
  134. fi
  135. # Vérifier Redis
  136. if docker exec waouw_redis redis-cli ping | grep -q PONG; then
  137. log "✅ Redis opérationnel"
  138. else
  139. log "❌ Redis problème"
  140. fi
  141. # Vérifier Backend
  142. if curl -s http://localhost:8000/health >/dev/null 2>&1; then
  143. log "✅ Backend opérationnel"
  144. else
  145. log "❌ Backend problème"
  146. fi
  147. # Vérifier Traefik
  148. if curl -s -I http://localhost >/dev/null 2>&1; then
  149. log "✅ Traefik opérationnel"
  150. else
  151. log "❌ Traefik problème"
  152. fi
  153. # Test d'accès direct sur l'IP
  154. IP=$(hostname -I | awk '{print $1}')
  155. if curl -s --max-time 5 "http://$IP" >/dev/null 2>&1; then
  156. log "✅ Accès direct sur IP opérationnel: http://$IP"
  157. else
  158. log "❌ Accès direct sur IP problème"
  159. fi
  160. }
  161. # Fonction de feedback
  162. provide_feedback() {
  163. log "=== RAPPORT FINAL ==="
  164. log "WaouW v2.0 Status:"
  165. # État des conteneurs
  166. log "Conteneurs actifs:"
  167. docker ps --format "table {{.Names}}\t{{.Status}}" | while read line; do
  168. log " $line"
  169. done
  170. # Adresses d'accès
  171. IP=$(hostname -I | awk '{print $1}')
  172. log ""
  173. log "🌐 ACCÈS WAOUW:"
  174. log " Interface: http://$IP (accès direct)"
  175. log " Interface: http://waouw-pi.local (DNS)"
  176. log " API: http://$IP/api/health"
  177. log " API: http://waouw-pi.local/api/health"
  178. log " Login: admin / admin"
  179. # Informations système
  180. log ""
  181. log "📊 INFORMATIONS SYSTÈME:"
  182. log " IP: $(hostname -I | awk '{print $1}')"
  183. log " Utilisateur: waouw"
  184. log " Logs: /var/log/waouw-startup.log"
  185. log ""
  186. log "🎉 INSTALLATION TERMINÉE - WaouW v2.0 opérationnel !"
  187. }
  188. # Exécution principale
  189. main() {
  190. log "=== DÉMARRAGE WAOUW v2.0 ==="
  191. # Corrections automatiques
  192. auto_fix
  193. # Démarrage des services
  194. start_services
  195. # Vérifications
  196. verify_services
  197. # Feedback final
  198. provide_feedback
  199. log "=== FIN DU DÉMARRAGE AUTOMATIQUE ==="
  200. }
  201. # Lancer le processus automatique
  202. main