#!/bin/sh set -e echo "🚀 DĂ©marrage de l'interface utilisateur 4NK..." # Variables d'environnement avec valeurs par dĂ©faut SDK_RELAY_WS_URL=${SDK_RELAY_WS_URL:-"ws://sdk_relay_1:8090"} SDK_RELAY_HTTP_URL=${SDK_RELAY_HTTP_URL:-"http://sdk_relay_1:8091"} BITCOIN_RPC_URL=${BITCOIN_RPC_URL:-"http://bitcoin:18443"} BLINDBIT_URL=${BLINDBIT_URL:-"http://blindbit:8000"} # Fonction pour attendre qu'un service soit disponible wait_for_service() { local service_name=$1 local service_url=$2 local max_attempts=30 local attempt=1 echo "⏳ Attente du service $service_name ($service_url)..." while [ $attempt -le $max_attempts ]; do if wget --quiet --tries=1 --timeout=5 --spider "$service_url" 2>/dev/null; then echo "✅ Service $service_name disponible" return 0 fi echo " Tentative $attempt/$max_attempts - Service $service_name non disponible" sleep 2 attempt=$((attempt + 1)) done echo "❌ Service $service_name non disponible aprĂšs $max_attempts tentatives" return 1 } # Fonction pour vĂ©rifier la connectivitĂ© WebSocket check_websocket() { local service_name=$1 local ws_url=$2 local max_attempts=10 local attempt=1 echo "🔌 VĂ©rification WebSocket $service_name ($ws_url)..." while [ $attempt -le $max_attempts ]; do if nc -z $(echo $ws_url | sed 's|ws://||' | sed 's|wss://||' | cut -d: -f1) $(echo $ws_url | cut -d: -f3) 2>/dev/null; then echo "✅ WebSocket $service_name accessible" return 0 fi echo " Tentative $attempt/$max_attempts - WebSocket $service_name non accessible" sleep 3 attempt=$((attempt + 1)) done echo "⚠ WebSocket $service_name non accessible (continuera sans)" return 0 } # VĂ©rification des services critiques echo "🔍 VĂ©rification des services 4NK_node..." # Attendre sdk_relay HTTP (critique) if ! wait_for_service "sdk_relay HTTP" "$SDK_RELAY_HTTP_URL/health"; then echo "❌ Service sdk_relay HTTP critique non disponible" exit 1 fi # VĂ©rifier sdk_relay WebSocket (optionnel) check_websocket "sdk_relay WebSocket" "$SDK_RELAY_WS_URL" # VĂ©rifier Bitcoin Core (optionnel) if ! wait_for_service "Bitcoin Core" "$BITCOIN_RPC_URL" 2>/dev/null; then echo "⚠ Bitcoin Core non disponible (optionnel)" fi # VĂ©rifier Blindbit (optionnel) if ! wait_for_service "Blindbit" "$BLINDBIT_URL" 2>/dev/null; then echo "⚠ Blindbit non disponible (optionnel)" fi # GĂ©nĂ©ration de la configuration dynamique echo "⚙ GĂ©nĂ©ration de la configuration dynamique..." # CrĂ©er un fichier de configuration JavaScript pour l'application cat > /usr/share/nginx/html/config.js << EOF window.ENV_CONFIG = { SDK_RELAY_WS_URL: '$SDK_RELAY_WS_URL', SDK_RELAY_HTTP_URL: '$SDK_RELAY_HTTP_URL', BITCOIN_RPC_URL: '$BITCOIN_RPC_URL', BLINDBIT_URL: '$BLINDBIT_URL', ENVIRONMENT: '4nk-node' }; EOF # DĂ©marrage de nginx echo "🌐 DĂ©marrage de nginx..." nginx -g "daemon off;" & # Attendre que nginx soit prĂȘt sleep 2 # VĂ©rifier que nginx fonctionne if ! wget --quiet --tries=1 --timeout=5 --spider http://localhost 2>/dev/null; then echo "❌ Nginx n'a pas dĂ©marrĂ© correctement" exit 1 fi echo "✅ Interface utilisateur 4NK dĂ©marrĂ©e avec succĂšs" echo " 📍 URL: http://localhost" echo " 🔌 WebSocket: $SDK_RELAY_WS_URL" echo " 🌐 API: $SDK_RELAY_HTTP_URL" # Maintenir le conteneur en vie while true; do sleep 30 # VĂ©rification pĂ©riodique de la santĂ© if ! wget --quiet --tries=1 --timeout=5 --spider http://localhost 2>/dev/null; then echo "❌ Nginx ne rĂ©pond plus, redĂ©marrage..." nginx -s reload fi done