228 lines
8.5 KiB
Bash
Executable File
228 lines
8.5 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Script de surveillance en temps réel de la progression des services LeCoffre Node
|
||
# Affiche la progression des différents processus (IBD, scans, etc.) en continu
|
||
# Optimisé pour les processus longs (Tor: 15min, Bitcoin: 2h)
|
||
|
||
set -e
|
||
|
||
# Couleurs pour l'affichage
|
||
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 des intervalles de mise à jour
|
||
BITCOIN_UPDATE_INTERVAL=60 # Bitcoin: toutes les minutes
|
||
TOR_UPDATE_INTERVAL=30 # Tor: toutes les 30 secondes
|
||
OTHER_UPDATE_INTERVAL=15 # Autres services: toutes les 15 secondes
|
||
|
||
# Fonction pour effacer l'écran et afficher le header
|
||
clear_and_header() {
|
||
clear
|
||
echo -e "${BLUE}========================================${NC}"
|
||
echo -e "${BLUE} LeCoffre Node - Live Progress Monitor${NC}"
|
||
echo -e "${BLUE}========================================${NC}"
|
||
echo -e "${YELLOW}Last updated: $(date)${NC}"
|
||
echo
|
||
}
|
||
|
||
# Fonction pour afficher la progression Bitcoin
|
||
show_bitcoin_progress() {
|
||
local container_name="bitcoin-signet"
|
||
if docker ps --format "table {{.Names}}" | grep -q "$container_name"; then
|
||
echo -e "${CYAN}Bitcoin Progress:${NC}"
|
||
local info=$(docker exec "$container_name" bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getblockchaininfo 2>/dev/null || echo '{}')
|
||
local blocks=$(echo "$info" | jq -r '.blocks // 0')
|
||
local headers=$(echo "$info" | jq -r '.headers // 0')
|
||
local progress=0
|
||
|
||
if [ "$headers" -gt 0 ]; then
|
||
progress=$((blocks * 100 / headers))
|
||
fi
|
||
|
||
if [ "$blocks" -eq "$headers" ] && [ "$blocks" -gt 0 ]; then
|
||
echo -e " ${GREEN}✓ Bitcoin sync complete: $blocks blocks${NC}"
|
||
else
|
||
# Calculer le temps écoulé depuis le démarrage
|
||
local start_time=$(docker inspect --format='{{.State.StartedAt}}' "$container_name" 2>/dev/null | xargs -I {} date -d {} +%s 2>/dev/null || echo "0")
|
||
local current_time=$(date +%s)
|
||
local elapsed_time=$((current_time - start_time))
|
||
local elapsed_min=$((elapsed_time / 60))
|
||
local elapsed_hour=$((elapsed_min / 60))
|
||
|
||
local time_str=""
|
||
if [ $elapsed_hour -gt 0 ]; then
|
||
time_str="${elapsed_hour}h ${elapsed_min}m"
|
||
else
|
||
time_str="${elapsed_min}m"
|
||
fi
|
||
|
||
echo -e " ${YELLOW}⏳ Bitcoin IBD: $blocks/$headers blocks ($(($headers - $blocks)) remaining) - $progress% (${time_str} elapsed)${NC}"
|
||
|
||
# Afficher une barre de progression
|
||
local bar_length=50
|
||
local filled_length=$((progress * bar_length / 100))
|
||
local bar=""
|
||
for ((i=0; i<filled_length; i++)); do bar+="█"; done
|
||
for ((i=filled_length; i<bar_length; i++)); do bar+="░"; done
|
||
echo -e " ${YELLOW}[$bar] $progress%${NC}"
|
||
fi
|
||
echo
|
||
fi
|
||
}
|
||
|
||
# Fonction pour afficher la progression Tor
|
||
show_tor_progress() {
|
||
local container_name="tor-proxy"
|
||
if docker ps --format "table {{.Names}}" | grep -q "$container_name"; then
|
||
echo -e "${CYAN}Tor Progress:${NC}"
|
||
local bootstrap_log=$(docker logs "$container_name" --tail 20 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%")
|
||
if echo "$bootstrap_log" | grep -q "100%"; then
|
||
echo -e " ${GREEN}✓ Tor ready: Bootstrap complete (100%)${NC}"
|
||
else
|
||
echo -e " ${YELLOW}⏳ Tor bootstrapping: $progress${NC}"
|
||
fi
|
||
else
|
||
echo -e " ${YELLOW}⏳ Tor starting: Bootstrap not yet started${NC}"
|
||
fi
|
||
echo
|
||
fi
|
||
}
|
||
|
||
# Fonction pour afficher la progression SDK Relay
|
||
show_sdk_relay_progress() {
|
||
local container_name="sdk_relay"
|
||
if docker ps --format "table {{.Names}}" | grep -q "$container_name"; then
|
||
echo -e "${CYAN}SDK Relay Progress:${NC}"
|
||
local logs=$(docker logs "$container_name" --tail 3 2>/dev/null | grep -E "(waiting for|blocks to download|IBD)" | tail -1 || echo "")
|
||
if [ -n "$logs" ]; then
|
||
echo -e " ${YELLOW}⏳ SDK Relay IBD: $logs${NC}"
|
||
else
|
||
local response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8091/ 2>/dev/null || echo "000")
|
||
if [ "$response" = "200" ]; then
|
||
echo -e " ${GREEN}✓ SDK Relay ready: WebSocket server responding${NC}"
|
||
else
|
||
echo -e " ${YELLOW}⏳ SDK Relay starting: WebSocket server not yet ready${NC}"
|
||
fi
|
||
fi
|
||
echo
|
||
fi
|
||
}
|
||
|
||
# Fonction pour afficher le statut des services
|
||
show_services_status() {
|
||
echo -e "${PURPLE}Services Status:${NC}"
|
||
|
||
# Services critiques
|
||
local services=("tor-proxy:Tor Proxy" "bitcoin-signet:Bitcoin Signet" "blindbit-oracle:BlindBit Oracle" "sdk_storage:SDK Storage" "sdk_relay:SDK Relay" "sdk_signer:SDK Signer" "ihm_client:IHM Client")
|
||
|
||
for service in "${services[@]}"; do
|
||
local container_name="${service%%:*}"
|
||
local display_name="${service##*:}"
|
||
local status=$(docker inspect --format='{{.State.Health.Status}}' "$container_name" 2>/dev/null || echo "no-healthcheck")
|
||
local running=$(docker inspect --format='{{.State.Running}}' "$container_name" 2>/dev/null || echo "false")
|
||
|
||
if [ "$running" = "true" ]; then
|
||
case "$status" in
|
||
"healthy")
|
||
echo -e " ${GREEN}✓${NC} $display_name: ${GREEN}Ready${NC}"
|
||
;;
|
||
"unhealthy")
|
||
echo -e " ${YELLOW}⚠${NC} $display_name: ${YELLOW}Processing${NC}"
|
||
;;
|
||
"starting")
|
||
echo -e " ${YELLOW}⏳${NC} $display_name: ${YELLOW}Starting${NC}"
|
||
;;
|
||
"no-healthcheck")
|
||
echo -e " ${BLUE}ℹ${NC} $display_name: ${BLUE}Running${NC}"
|
||
;;
|
||
esac
|
||
else
|
||
echo -e " ${RED}✗${NC} $display_name: ${RED}Stopped${NC}"
|
||
fi
|
||
done
|
||
echo
|
||
}
|
||
|
||
# Fonction pour afficher les services en attente
|
||
show_waiting_services() {
|
||
echo -e "${PURPLE}Services Waiting for Dependencies:${NC}"
|
||
|
||
# Vérifier les services LeCoffre
|
||
local lecoffre_back=$(docker inspect --format='{{.State.Running}}' "lecoffre-back" 2>/dev/null || echo "false")
|
||
local lecoffre_front=$(docker inspect --format='{{.State.Running}}' "lecoffre-front" 2>/dev/null || echo "false")
|
||
|
||
if [ "$lecoffre_back" = "false" ]; then
|
||
echo -e " ${YELLOW}⏳ LeCoffre Backend: Waiting for SDK Relay${NC}"
|
||
fi
|
||
|
||
if [ "$lecoffre_front" = "false" ]; then
|
||
echo -e " ${YELLOW}⏳ LeCoffre Frontend: Waiting for LeCoffre Backend${NC}"
|
||
fi
|
||
|
||
echo
|
||
}
|
||
|
||
# Fonction principale
|
||
main() {
|
||
local current_time=$(date +%s)
|
||
local bitcoin_should_update=$((current_time - last_bitcoin_update >= BITCOIN_UPDATE_INTERVAL))
|
||
local tor_should_update=$((current_time - last_tor_update >= TOR_UPDATE_INTERVAL))
|
||
local other_should_update=$((current_time - last_other_update >= OTHER_UPDATE_INTERVAL))
|
||
|
||
clear_and_header
|
||
|
||
# Afficher la progression Bitcoin (toutes les minutes)
|
||
if [ $bitcoin_should_update -eq 1 ]; then
|
||
show_bitcoin_progress
|
||
last_bitcoin_update=$current_time
|
||
fi
|
||
|
||
# Afficher la progression Tor (toutes les 30 secondes)
|
||
if [ $tor_should_update -eq 1 ]; then
|
||
show_tor_progress
|
||
last_tor_update=$current_time
|
||
fi
|
||
|
||
# Afficher la progression SDK Relay (toutes les 15 secondes)
|
||
if [ $other_should_update -eq 1 ]; then
|
||
show_sdk_relay_progress
|
||
last_other_update=$current_time
|
||
fi
|
||
|
||
# Toujours afficher le statut des services
|
||
show_services_status
|
||
show_waiting_services
|
||
|
||
echo -e "${BLUE}========================================${NC}"
|
||
echo -e "${BLUE} Press Ctrl+C to stop monitoring${NC}"
|
||
echo -e "${BLUE} Bitcoin: ${BITCOIN_UPDATE_INTERVAL}s | Tor: ${TOR_UPDATE_INTERVAL}s | Others: ${OTHER_UPDATE_INTERVAL}s${NC}"
|
||
echo -e "${BLUE}========================================${NC}"
|
||
}
|
||
|
||
# Fonction de nettoyage
|
||
cleanup() {
|
||
echo -e "\n${YELLOW}Monitoring stopped.${NC}"
|
||
exit 0
|
||
}
|
||
|
||
# Gestion des signaux
|
||
trap cleanup SIGINT SIGTERM
|
||
|
||
# Initialiser les timestamps
|
||
last_bitcoin_update=0
|
||
last_tor_update=0
|
||
last_other_update=0
|
||
|
||
# Boucle principale
|
||
while true; do
|
||
main
|
||
sleep 15 # Rafraîchissement général toutes les 15 secondes
|
||
done
|