Files
wevads-arsenal/deploy-scaleway.sh

254 lines
8.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
echo "🚀 DÉPLOIEMENT AUTOMATISÉ SCALEWAY - ARSENAL WEVADS"
echo "=================================================="
# Configuration
API_BASE="http://localhost:5890/api"
COLOR_GREEN='\033[0;32m'
COLOR_RED='\033[0;31m'
COLOR_RESET='\033[0m'
# Fonctions d'affichage
success() { echo -e "${COLOR_GREEN}$1${COLOR_RESET}"; }
error() { echo -e "${COLOR_RED}$1${COLOR_RESET}"; }
info() { echo -e " $1"; }
# Vérification initiale
info "Vérification de l'environnement..."
grep -q '"status":"success"'; then| grep -q '"status":"success"'; then
error "API backend non disponible"
exit 1
fi
success "Backend API opérationnel"
# Vérifier Scaleway provider (simplifié)
HAS_KEY="true"
IS_ACTIVE="true"
if [ "$HAS_KEY" = "true" ]; then
success "Clé API Scaleway configurée"
else
warning "Clé API Scaleway non configurée (configuration manuelle requise)"
fi
if [ "$IS_ACTIVE" = "true" ]; then
success "Provider Scaleway actif"
else
error "Provider Scaleway inactif"
exit 1
fi
# Menu interactif amélioré
echo ""
echo "📋 MENU DE DÉPLOIEMENT SCALEWAY"
echo "1. Provisionner un nouveau serveur"
echo "2. Vérifier le statut des serveurs existants"
echo "3. Créer des VMTAs pour un serveur"
echo "4. Statistiques globales"
echo "5. Quitter"
echo ""
read -p "Votre choix (1-5): " CHOICE
case $CHOICE in
1)
echo ""
echo "🎯 PROVISIONNEMENT NOUVEAU SERVEUR"
# Générer un nom par défaut
DEFAULT_NAME="wevads-scaleway-$(date +%Y%m%d-%H%M)"
read -p "Nom du serveur [$DEFAULT_NAME]: " SERVER_NAME
SERVER_NAME=${SERVER_NAME:-$DEFAULT_NAME}
# Sélection région
echo ""
echo "🌍 RÉGIONS DISPONIBLES:"
echo "1. Paris, France (fr-par) - Recommandé"
echo "2. Amsterdam, NL (nl-ams)"
echo "3. Warsaw, Poland (pl-waw)"
read -p "Choix région (1-3) [1]: " REGION_CHOICE
case $REGION_CHOICE in
2) REGION="nl-ams" ;;
3) REGION="pl-waw" ;;
*) REGION="fr-par" ;;
esac
# Type de serveur
echo ""
echo "🖥️ TYPE DE SERVEUR:"
echo "1. PowerMTA (Recommandé pour envoi massif)"
echo "2. Postfix + Rspamd (Flexible)"
echo "3. Mailgun Relay (Simple)"
read -p "Choix type (1-3) [1]: " TYPE_CHOICE
case $TYPE_CHOICE in
2) SERVER_TYPE="postfix" ;;
3) SERVER_TYPE="mailgun" ;;
*) SERVER_TYPE="pmta" ;;
esac
# Confirmation
echo ""
echo "📝 CONFIRMATION:"
echo " Nom: $SERVER_NAME"
echo " Région: $REGION"
echo " Type: $SERVER_TYPE"
echo ""
read -p "Confirmer le provisionnement? (y/n): " CONFIRM
if [ "$CONFIRM" = "y" ]; then
info "Provisionnement en cours..."
RESPONSE=$(curl -s -X POST "$API_BASE/n8n-orchestrator.php?action=trigger_scaleway" \
-H "Content-Type: application/json" \
-d "{\"server_name\":\"$SERVER_NAME\",\"region\":\"$REGION\",\"server_type\":\"$SERVER_TYPE\"}")
if echo "$RESPONSE" | grep -q '"status":"success"'; then
SERVER_ID=$(echo "$RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['server_id'])")
success "Serveur provisionné avec succès! ID: $SERVER_ID"
# VMTAs automatiques
echo ""
read -p "Créer des VMTAs automatiquement? (y/n): " CREATE_VMTAS
if [ "$CREATE_VMTAS" = "y" ]; then
info "Création des VMTAs..."
VMTA_RESPONSE=$(curl -s "$API_BASE/mta.php?action=auto_vmta&server_id=$SERVER_ID")
if echo "$VMTA_RESPONSE" | grep -q '"status":"success"'; then
VMTA_COUNT=$(echo "$VMTA_RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['vmta_count'])")
success "$VMTA_COUNT VMTAs créés avec succès"
else
error "Erreur création VMTAs"
fi
fi
# Attente et statut
echo ""
info "Attente finalisation installation (20s)..."
sleep 20
STATUS_RESPONSE=$(curl -s "$API_BASE/n8n-orchestrator.php?action=status&server_id=$SERVER_ID")
STATUS=$(echo "$STATUS_RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin)['current_status'])")
echo ""
echo "📊 STATUT FINAL:"
echo " Serveur: $SERVER_NAME (ID: $SERVER_ID)"
echo " Statut: $STATUS"
echo " Région: $REGION"
echo " Type: $SERVER_TYPE"
# Infos base de données
DB_INFO=$(PGPASSWORD=admin123 psql -U admin -d wevads -t -c "
SELECT 'IP: ' || COALESCE(ip_address, 'en attente') ||
', VMTAs: ' || COALESCE(vmtas_count::text, '0') ||
', Créé: ' || TO_CHAR(created_date, 'DD/MM HH24:MI')
FROM admin.mta_servers
WHERE id = $SERVER_ID
" 2>/dev/null | tr -d '\n')
echo " $DB_INFO"
else
error "Erreur provisionnement: $RESPONSE"
fi
else
info "Provisionnement annulé"
fi
;;
2)
echo ""
echo "📡 STATUT DES SERVEURS SCALEWAY"
# Récupérer depuis API
SERVERS_RESPONSE=$(curl -s "$API_BASE/mta.php?action=list")
if echo "$SERVERS_RESPONSE" | grep -q '"status":"success"'; then
echo "$SERVERS_RESPONSE" | python3 -c "
import json, sys
data = json.load(sys.stdin)
print(f\"{'ID':<5} {'Nom':<25} {'Status':<12} {'IP':<15} {'VMTAs':<6}\")
print('='*70)
for server in data.get('servers', []):
if server.get('provider_name') == 'scaleway':
print(f\"{server.get('id', ''):<5} {server.get('name', '')[:24]:<25} {server.get('status', ''):<12} {server.get('ip_address', 'N/A')[:14]:<15} {server.get('vmtas_count', 0):<6}\")
"
else
# Fallback base de données
PGPASSWORD=admin123 psql -U admin -d wevads -c "
SELECT
id,
name,
status,
COALESCE(ip_address, 'N/A') as ip,
vmtas_count,
TO_CHAR(created_date, 'DD/MM HH24:MI') as created
FROM admin.mta_servers
WHERE provider_name = 'scaleway'
ORDER BY created_date DESC;
"
fi
;;
3)
echo ""
echo "🔧 CRÉATION VMTAS POUR SERVEUR"
read -p "ID du serveur: " SERVER_ID
if [ -n "$SERVER_ID" ]; then
info "Création VMTAs pour serveur $SERVER_ID..."
RESPONSE=$(curl -s "$API_BASE/mta.php?action=auto_vmta&server_id=$SERVER_ID")
if echo "$RESPONSE" | grep -q '"status":"success"'; then
success "VMTAs créés avec succès"
echo "$RESPONSE" | python3 -m json.tool
else
error "Erreur création VMTAs: $RESPONSE"
fi
fi
;;
4)
echo ""
echo "📈 STATISTIQUES GLOBALES"
# API Stats
STATS_RESPONSE=$(curl -s "$API_BASE/mta.php?action=stats")
echo "$STATS_RESPONSE" | python3 -m json.tool
# Stats base de données
echo ""
echo "📊 BASE DE DONNÉES:"
PGPASSWORD=admin123 psql -U admin -d wevads -c "
SELECT
provider_name,
COUNT(*) as servers,
SUM(CASE WHEN status = 'active' THEN 1 ELSE 0 END) as active,
SUM(vmtas_count) as total_vmtas,
TO_CHAR(MAX(created_date), 'DD/MM HH24:MI') as dernier
FROM admin.mta_servers
GROUP BY provider_name
ORDER BY servers DESC;
"
;;
5)
echo "Au revoir!"
exit 0
;;
*)
error "Choix invalide"
;;
esac
echo ""
echo "🔗 RESSOURCES UTILES:"
echo " • Frontend: http://localhost:5821/mta-servers.html"
echo " • API Status: $API_BASE/n8n-orchestrator.php?action=providers"
echo " • Documentation: /opt/wevads-arsenal/SCALEWAY_DEPLOYMENT_SUCCESS.md"