#!/bin/bash # Script de monitoring de la progression des services LeCoffre Node # Affiche la progression des différents processus (IBD, scans, etc.) 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 # Fonction pour afficher un header print_header() { echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} LeCoffre Node - Monitoring Progress${NC}" echo -e "${BLUE}========================================${NC}" echo } # Fonction pour afficher le statut d'un service print_service_status() { local service_name="$1" local container_name="$2" 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} $service_name: ${GREEN}Ready${NC}" ;; "unhealthy") echo -e " ${YELLOW}⚠${NC} $service_name: ${YELLOW}Starting/Processing${NC}" ;; "starting") echo -e " ${YELLOW}⏳${NC} $service_name: ${YELLOW}Starting${NC}" ;; "no-healthcheck") echo -e " ${BLUE}ℹ${NC} $service_name: ${BLUE}Running (no healthcheck)${NC}" ;; esac else echo -e " ${RED}✗${NC} $service_name: ${RED}Stopped${NC}" 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 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 echo -e " ${YELLOW}⏳ Bitcoin IBD: $blocks/$headers blocks ($(($headers - $blocks)) remaining) - $progress%${NC}" fi echo fi } # Fonction pour afficher la progression BlindBit show_blindbit_progress() { local container_name="blindbit-oracle" if docker ps --format "table {{.Names}}" | grep -q "$container_name"; then echo -e "${CYAN}BlindBit Progress:${NC}" local response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8000/tweaks/1 2>/dev/null || echo "000") case "$response" in "200") echo -e " ${GREEN}✓ BlindBit ready: Oracle service responding${NC}" ;; "000") echo -e " ${YELLOW}⏳ BlindBit starting: Oracle service not yet ready${NC}" ;; *) echo -e " ${YELLOW}⏳ BlindBit scanning: Oracle responding with code $response${NC}" ;; esac 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 5 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 la progression des autres services show_other_services_progress() { echo -e "${CYAN}Other Services Progress:${NC}" # SDK Storage local storage_response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8081/health 2>/dev/null || echo "000") if [ "$storage_response" = "200" ]; then echo -e " ${GREEN}✓ SDK Storage ready: API responding${NC}" else echo -e " ${YELLOW}⏳ SDK Storage starting: API not yet ready${NC}" fi # SDK Signer local signer_response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:3001/ 2>/dev/null || echo "000") if [ "$signer_response" = "101" ] || [ "$signer_response" = "426" ]; then echo -e " ${GREEN}✓ SDK Signer ready: WebSocket server responding${NC}" else echo -e " ${YELLOW}⏳ SDK Signer starting: WebSocket server not yet ready${NC}" fi # IHM Client local ihm_response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:3003/ 2>/dev/null || echo "000") if [ "$ihm_response" = "200" ]; then echo -e " ${GREEN}✓ IHM Client ready: Vite dev server responding${NC}" else echo -e " ${YELLOW}⏳ IHM Client starting: Vite dev server not yet ready${NC}" fi # Grafana local grafana_response=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:3005/api/health 2>/dev/null || echo "000") if [ "$grafana_response" = "200" ]; then echo -e " ${GREEN}✓ Grafana ready: Dashboard service responding${NC}" else echo -e " ${YELLOW}⏳ Grafana starting: Dashboard service not yet ready${NC}" fi echo } # Fonction principale main() { print_header echo -e "${PURPLE}Service Status:${NC}" print_service_status "Tor Proxy" "tor-proxy" print_service_status "Bitcoin Signet" "bitcoin-signet" print_service_status "BlindBit Oracle" "blindbit-oracle" print_service_status "SDK Storage" "sdk_storage" print_service_status "SDK Relay" "sdk_relay" print_service_status "SDK Signer" "sdk_signer" print_service_status "LeCoffre Backend" "lecoffre-back" print_service_status "LeCoffre Frontend" "lecoffre-front" print_service_status "IHM Client" "ihm_client" print_service_status "Grafana" "grafana" print_service_status "Loki" "loki" print_service_status "Promtail" "promtail" print_service_status "Status API" "status-api" echo show_tor_progress show_bitcoin_progress show_blindbit_progress show_sdk_relay_progress show_other_services_progress echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} Use 'docker logs ' for detailed logs${NC}" echo -e "${BLUE}========================================${NC}" } # Exécution main "$@"