255 lines
8.3 KiB
Bash
Executable File
255 lines
8.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script pour afficher les logs des services avec la progression
|
|
# Affiche les logs en temps réel avec des informations de progression
|
|
|
|
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 l'aide
|
|
show_help() {
|
|
echo -e "${BLUE}Usage: $0 [service_name] [options]${NC}"
|
|
echo
|
|
echo -e "${PURPLE}Services disponibles:${NC}"
|
|
echo -e " ${CYAN}bitcoin${NC} - Bitcoin Signet (affiche la progression IBD)"
|
|
echo -e " ${CYAN}blindbit${NC} - BlindBit Oracle (affiche la progression du scan)"
|
|
echo -e " ${CYAN}sdk_relay${NC} - SDK Relay (affiche la progression du scan)"
|
|
echo -e " ${CYAN}sdk_storage${NC} - SDK Storage"
|
|
echo -e " ${CYAN}sdk_signer${NC} - SDK Signer"
|
|
echo -e " ${CYAN}lecoffre-back${NC} - LeCoffre Backend"
|
|
echo -e " ${CYAN}lecoffre-front${NC} - LeCoffre Frontend"
|
|
echo -e " ${CYAN}ihm_client${NC} - IHM Client"
|
|
echo -e " ${CYAN}grafana${NC} - Grafana"
|
|
echo -e " ${CYAN}loki${NC} - Loki"
|
|
echo -e " ${CYAN}promtail${NC} - Promtail"
|
|
echo -e " ${CYAN}status-api${NC} - Status API"
|
|
echo
|
|
echo -e "${PURPLE}Options:${NC}"
|
|
echo -e " ${CYAN}-f, --follow${NC} - Suivre les logs en temps réel (défaut)"
|
|
echo -e " ${CYAN}-n, --lines N${NC} - Afficher les N dernières lignes (défaut: 50)"
|
|
echo -e " ${CYAN}-p, --progress${NC} - Afficher la progression en plus des logs"
|
|
echo -e " ${CYAN}-h, --help${NC} - Afficher cette aide"
|
|
echo
|
|
echo -e "${PURPLE}Exemples:${NC}"
|
|
echo -e " ${CYAN}$0 bitcoin -p${NC} - Logs Bitcoin avec progression IBD"
|
|
echo -e " ${CYAN}$0 sdk_relay -n 100${NC} - 100 dernières lignes du SDK Relay"
|
|
echo -e " ${CYAN}$0 blindbit -f -p${NC} - Logs BlindBit en temps réel avec progression"
|
|
}
|
|
|
|
# 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
|
|
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
|
|
|
|
echo -e "${CYAN}Bitcoin Progress: $blocks/$headers blocks ($(($headers - $blocks)) remaining) - $progress%${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}"
|
|
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
|
|
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 Progress: Oracle service ready${NC}"
|
|
;;
|
|
"000")
|
|
echo -e "${YELLOW}BlindBit Progress: Oracle service starting${NC}"
|
|
;;
|
|
*)
|
|
echo -e "${YELLOW}BlindBit Progress: Oracle scanning (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
|
|
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 Progress: $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 Progress: WebSocket server ready${NC}"
|
|
else
|
|
echo -e "${YELLOW}SDK Relay Progress: WebSocket server starting${NC}"
|
|
fi
|
|
fi
|
|
echo
|
|
fi
|
|
}
|
|
|
|
# Fonction pour afficher les logs avec progression
|
|
show_logs_with_progress() {
|
|
local service_name="$1"
|
|
local container_name="$2"
|
|
local lines="${3:-50}"
|
|
local follow="${4:-true}"
|
|
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "${BLUE} Logs for $service_name${NC}"
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo
|
|
|
|
# Afficher la progression selon le service
|
|
case "$service_name" in
|
|
"bitcoin")
|
|
show_bitcoin_progress
|
|
;;
|
|
"blindbit")
|
|
show_blindbit_progress
|
|
;;
|
|
"sdk_relay")
|
|
show_sdk_relay_progress
|
|
;;
|
|
esac
|
|
|
|
echo -e "${PURPLE}Recent logs:${NC}"
|
|
echo
|
|
|
|
if [ "$follow" = "true" ]; then
|
|
docker logs -f --tail "$lines" "$container_name" 2>/dev/null || echo -e "${RED}Service $service_name not found or not running${NC}"
|
|
else
|
|
docker logs --tail "$lines" "$container_name" 2>/dev/null || echo -e "${RED}Service $container_name not found or not running${NC}"
|
|
fi
|
|
}
|
|
|
|
# Fonction principale
|
|
main() {
|
|
local service_name=""
|
|
local container_name=""
|
|
local lines=50
|
|
local follow=true
|
|
local show_progress=false
|
|
|
|
# Parser les arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-f|--follow)
|
|
follow=true
|
|
shift
|
|
;;
|
|
-n|--lines)
|
|
lines="$2"
|
|
shift 2
|
|
;;
|
|
-p|--progress)
|
|
show_progress=true
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
-*)
|
|
echo -e "${RED}Unknown option: $1${NC}"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
*)
|
|
service_name="$1"
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Déterminer le nom du conteneur
|
|
case "$service_name" in
|
|
"bitcoin")
|
|
container_name="bitcoin-signet"
|
|
;;
|
|
"blindbit")
|
|
container_name="blindbit-oracle"
|
|
;;
|
|
"sdk_relay")
|
|
container_name="sdk_relay"
|
|
;;
|
|
"sdk_storage")
|
|
container_name="sdk_storage"
|
|
;;
|
|
"sdk_signer")
|
|
container_name="sdk_signer"
|
|
;;
|
|
"lecoffre-back")
|
|
container_name="lecoffre-back"
|
|
;;
|
|
"lecoffre-front")
|
|
container_name="lecoffre-front"
|
|
;;
|
|
"ihm_client")
|
|
container_name="ihm_client"
|
|
;;
|
|
"grafana")
|
|
container_name="grafana"
|
|
;;
|
|
"loki")
|
|
container_name="loki"
|
|
;;
|
|
"promtail")
|
|
container_name="promtail"
|
|
;;
|
|
"status-api")
|
|
container_name="status-api"
|
|
;;
|
|
"")
|
|
echo -e "${RED}Please specify a service name${NC}"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
*)
|
|
echo -e "${RED}Unknown service: $service_name${NC}"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Afficher les logs
|
|
if [ "$show_progress" = "true" ]; then
|
|
show_logs_with_progress "$service_name" "$container_name" "$lines" "$follow"
|
|
else
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "${BLUE} Logs for $service_name${NC}"
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo
|
|
|
|
if [ "$follow" = "true" ]; then
|
|
docker logs -f --tail "$lines" "$container_name" 2>/dev/null || echo -e "${RED}Service $service_name not found or not running${NC}"
|
|
else
|
|
docker logs --tail "$lines" "$container_name" 2>/dev/null || echo -e "${RED}Service $service_name not found or not running${NC}"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Exécution
|
|
main "$@"
|