From 01b7698dbd53423865c46ebbeac1cc639e735c91 Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Mon, 22 Sep 2025 01:27:08 +0000 Subject: [PATCH] update submodule --- scripts/start.sh | 262 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 253 insertions(+), 9 deletions(-) diff --git a/scripts/start.sh b/scripts/start.sh index 37e9d3f..d303c5b 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,6 +1,6 @@ #!/bin/bash -# LeCoffre Node - Script de lancement simple -# Lance tous les services Docker Compose sans surveillance +# LeCoffre Node - Script de lancement séquentiel avec progression +# Lance les services dans l'ordre logique avec suivi de l'avancement set -e @@ -9,26 +9,270 @@ RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' +CYAN='\033[0;36m' NC='\033[0m' # No Color +# Configuration +START_TIME=$(date +%s) +MAX_WAIT=300 # 5 minutes max par service + +# Fonction pour afficher un message avec timestamp +print_message() { + echo -e "${BLUE}[$(date '+%H:%M:%S')]${NC} $1" +} + +# Fonction pour afficher la progression +show_progress() { + local current=$1 + local total=$2 + local service=$3 + local percent=$((current * 100 / total)) + echo -e "${CYAN}Progress: $current/$total ($percent%) - $service${NC}" +} + +# Fonction pour afficher la progression détaillée +show_detailed_progress() { + local service_name=$1 + + echo -e "${CYAN}=== Detailed Progress ===${NC}" + + # Tor Bootstrap + if docker ps --format '{{.Names}}' | grep -q "tor-proxy"; then + local bootstrap_log=$(docker logs tor-proxy --tail 10 2>/dev/null | grep 'Bootstrapped' | tail -1 || echo "") + if [ -n "$bootstrap_log" ]; then + local progress=$(echo "$bootstrap_log" | grep -o '[0-9]\+%' | tail -1 || echo "0%") + local stage=$(echo "$bootstrap_log" | grep -o '(.*)' | sed 's/[()]//g' || echo "starting") + echo -e " ${YELLOW}Tor Bootstrap: $progress - $stage${NC}" + else + echo -e " ${YELLOW}Tor Bootstrap: Starting...${NC}" + fi + else + echo -e " ${RED}Tor: Not running${NC}" + fi + + # Bitcoin Signet + if docker ps --format '{{.Names}}' | grep -q "bitcoin-signet"; then + local info=$(docker exec bitcoin-signet bitcoin-cli -signet -conf=/etc/bitcoin/bitcoin.conf getblockchaininfo 2>/dev/null || echo '{}') + local blocks=$(echo "$info" | jq -r '.blocks // 0' 2>/dev/null || echo "0") + local headers=$(echo "$info" | jq -r '.headers // 0' 2>/dev/null || echo "0") + local ibd=$(echo "$info" | jq -r '.initialblockdownload // false' 2>/dev/null || echo "true") + local verification_progress=$(echo "$info" | jq -r '.verificationprogress // 0' 2>/dev/null || echo "0") + + if [ "$ibd" = "false" ] || [ "$blocks" -eq "$headers" ]; then + echo -e " ${GREEN}Bitcoin Signet: Synced ($blocks blocks)${NC}" + else + local progress=$((blocks * 100 / headers)) + local ver_percent=$(echo "$verification_progress * 100" | bc -l | cut -d. -f1 2>/dev/null || echo "0") + echo -e " ${YELLOW}Bitcoin IBD: $blocks/$headers ($progress%) - Verification: $ver_percent%${NC}" + fi + else + echo -e " ${RED}Bitcoin Signet: Not running${NC}" + fi + + # BlindBit Oracle + if docker ps --format '{{.Names}}' | grep -q "blindbit-oracle"; then + local api_response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8000/tweaks/1 2>/dev/null || echo "000") + if [ "$api_response" = "200" ]; then + echo -e " ${GREEN}BlindBit Oracle: Ready${NC}" + else + local scan_logs=$(docker logs blindbit-oracle --tail 5 2>/dev/null | grep -E "(scanning|scan|blocks|tweaks|processing)" | tail -1 || echo "") + if [ -n "$scan_logs" ]; then + echo -e " ${YELLOW}BlindBit Scan: $scan_logs${NC}" + else + echo -e " ${YELLOW}BlindBit: Starting...${NC}" + fi + fi + else + echo -e " ${RED}BlindBit Oracle: Not running${NC}" + fi + + # SDK Relay + if docker ps --format '{{.Names}}' | grep -q "sdk_relay"; then + local ws_response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8091/ 2>/dev/null || echo "000") + if [ "$ws_response" = "200" ]; then + echo -e " ${GREEN}SDK Relay: Ready${NC}" + else + local relay_logs=$(docker logs sdk_relay --tail 5 2>/dev/null | grep -E "(IBD|blocks|headers|waiting|scanning|connecting)" | tail -1 || echo "") + if [ -n "$relay_logs" ]; then + echo -e " ${YELLOW}SDK Relay Sync: $relay_logs${NC}" + else + echo -e " ${YELLOW}SDK Relay: Starting...${NC}" + fi + fi + else + echo -e " ${RED}SDK Relay: Not running${NC}" + fi + + # SDK Signer + if docker ps --format '{{.Names}}' | grep -q "sdk_signer"; then + local ws_response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:9090/ 2>/dev/null || echo "000") + if [ "$ws_response" = "101" ] || [ "$ws_response" = "426" ]; then + echo -e " ${GREEN}SDK Signer: Ready${NC}" + else + local signer_logs=$(docker logs sdk_signer --tail 5 2>/dev/null | grep -E "(Disconnected|reconnect|error|connected|waiting|connecting)" | tail -1 || echo "") + if [ -n "$signer_logs" ]; then + echo -e " ${YELLOW}SDK Signer Conn: $signer_logs${NC}" + else + echo -e " ${YELLOW}SDK Signer: Starting...${NC}" + fi + fi + else + echo -e " ${RED}SDK Signer: Not running${NC}" + fi + + # URLs publiques HTTPS + echo -e "${CYAN}Public URLs Status:${NC}" + local urls=( + "https://dev4.4nkweb.com/status/:Status Page" + "https://dev4.4nkweb.com/grafana/:Grafana Dashboard" + "https://dev4.4nkweb.com/:Main Site" + "https://dev4.4nkweb.com/lecoffre/:LeCoffre App" + ) + + for url_entry in "${urls[@]}"; do + local url="${url_entry%%:*}" + local name="${url_entry##*:}" + local response=$(curl -s -o /dev/null -w '%{http_code}' "$url" 2>/dev/null || echo "000") + if [ "$response" = "200" ]; then + echo -e " ${GREEN}$name: Accessible (HTTP $response)${NC}" + else + echo -e " ${YELLOW}$name: Not accessible (HTTP $response)${NC}" + fi + done + + # URLs WebSocket publiques + echo -e "${CYAN}WebSocket URLs Status:${NC}" + local ws_urls=( + "wss://dev3.4nkweb.com/ws/:Bootstrap Relay" + "wss://dev3.4nkweb.com/ws/:Signer Service" + ) + + for ws_entry in "${ws_urls[@]}"; do + local ws_url="${ws_entry%%:*}" + local ws_name="${ws_entry##*:}" + # Test WebSocket avec timeout court + local ws_test=$(timeout 3 wscat -c "$ws_url" --no-color 2>/dev/null && echo "connected" || echo "failed") + if [ "$ws_test" = "connected" ]; then + echo -e " ${GREEN}$ws_name: Connected${NC}" + else + echo -e " ${YELLOW}$ws_name: Not connected${NC}" + fi + done + + echo -e "${CYAN}========================${NC}" +} + +# Fonction pour attendre qu'un service soit healthy +wait_for_healthy() { + local service_name=$1 + local max_wait=${2:-$MAX_WAIT} + local wait_time=0 + + print_message "Waiting for $service_name to be healthy..." + + while [ $wait_time -lt $max_wait ]; do + local status=$(docker inspect --format='{{.State.Health.Status}}' "$service_name" 2>/dev/null || echo "no-healthcheck") + local running=$(docker inspect --format='{{.State.Running}}' "$service_name" 2>/dev/null || echo "false") + + if [ "$running" = "true" ] && [ "$status" = "healthy" ]; then + echo -e "${GREEN}✓ $service_name is healthy${NC}" + return 0 + fi + + # Afficher la progression détaillée + show_detailed_progress "$service_name" + + sleep 5 + wait_time=$((wait_time + 5)) + done + + echo -e "${RED}✗ Timeout waiting for $service_name${NC}" + return 1 +} + +# Fonction pour démarrer un service +start_service() { + local service_name=$1 + local display_name=$2 + + print_message "Starting $display_name..." + docker compose --env-file .env.master up -d "$service_name" + + # Attendre que le conteneur soit créé + sleep 2 + + # Vérifier si le service a un healthcheck + local has_healthcheck=$(docker inspect --format='{{.Config.Healthcheck}}' "$service_name" 2>/dev/null | grep -q "Test" && echo "true" || echo "false") + + if [ "$has_healthcheck" = "true" ]; then + wait_for_healthy "$service_name" + else + # Pour les services sans healthcheck, attendre qu'ils soient running + local wait_time=0 + while [ $wait_time -lt 60 ]; do + local running=$(docker inspect --format='{{.State.Running}}' "$service_name" 2>/dev/null || echo "false") + if [ "$running" = "true" ]; then + echo -e "${GREEN}✓ $display_name is running${NC}" + break + fi + sleep 2 + wait_time=$((wait_time + 2)) + done + fi +} + echo -e "${BLUE}========================================${NC}" -echo -e "${BLUE} LeCoffre Node - Simple Startup${NC}" +echo -e "${BLUE} LeCoffre Node - Sequential Startup${NC}" echo -e "${BLUE}========================================${NC}" echo # Arrêter les services existants -echo -e "${YELLOW}Stopping existing services...${NC}" +print_message "Stopping existing services..." docker compose --env-file .env.master down --remove-orphans >/dev/null 2>&1 || true -# Démarrer tous les services -echo -e "${YELLOW}Starting all services...${NC}" -docker compose --env-file .env.master up -d +# Ordre de démarrage logique +services=( + "tor:Tor Proxy" + "bitcoin:Bitcoin Signet" + "blindbit:BlindBit Oracle" + "sdk_storage:SDK Storage" + "sdk_relay:SDK Relay" + "sdk_signer:SDK Signer" + "lecoffre-back:LeCoffre Backend" + "lecoffre-front:LeCoffre Frontend" + "ihm_client:IHM Client" + "grafana:Grafana" + "status-api:Status API" +) -echo -e "${GREEN}✅ All services started!${NC}" +total_services=${#services[@]} +current_service=0 + +# Démarrer les services dans l'ordre +for service in "${services[@]}"; do + current_service=$((current_service + 1)) + service_name="${service%%:*}" + display_name="${service##*:}" + + show_progress $current_service $total_services "$display_name" + start_service "$service_name" "$display_name" + echo +done + +# Afficher le statut final +echo -e "${GREEN}🎉 All services started successfully!${NC}" echo -echo -e "${BLUE}Services status:${NC}" +echo -e "${BLUE}Final status:${NC}" docker compose --env-file .env.master ps +# Calculer le temps total +end_time=$(date +%s) +total_time=$((end_time - START_TIME)) +minutes=$((total_time / 60)) +seconds=$((total_time % 60)) + +echo +echo -e "${GREEN}Total startup time: ${minutes}m ${seconds}s${NC}" echo echo -e "${BLUE}Useful commands:${NC}" echo -e " ${YELLOW}docker compose --env-file .env.master logs -f${NC} # Voir les logs"