anchorage_layer_simple/data/check-services-status.sh
ncantu e0ce7a9d83 Optimize sync-utxos RPC calls and document bitcoind crash issues
**Motivations:**
- Prevent bitcoind crashes caused by heavy RPC calls without timeout
- Document bitcoind crash and wallet loading stuck issues
- Clean up obsolete files (configure-nginx-proxy.sh, userwallet components, website-skeleton, old fixKnowledge docs)

**Root causes:**
- RPC calls without timeout causing bitcoind crashes
- No pre-check of bitcoind health before heavy operations
- Large wallet (315MB) causing long loading times and potential hangs
- Missing retry mechanism for transient errors

**Correctifs:**
- Add timeouts on RPC calls (5 minutes for listunspent, 10 seconds for healthcheck)
- Add bitcoind health check before synchronization
- Implement retry with exponential backoff
- Reduce maximumCount limit from 9999999 to 500000 UTXOs
- Improve cron script with pre-checks and better error handling
- Add container status verification before script execution

**Evolutions:**
- New check-services-status.sh script for service diagnostics
- Documentation of crash issues in fixKnowledge
- Improved logging with timestamps
- Better error messages and handling

**Pages affectées:**
- data/sync-utxos-spent-status.mjs
- data/sync-utxos-cron.sh
- data/restart-services-cron.sh
- data/check-services-status.sh (new)
- fixKnowledge/sync-utxos-rpc-optimization.md (new)
- fixKnowledge/signet-bitcoind-crash-mining-stopped.md (new)
- fixKnowledge/signet-bitcoind-crash-wallet-loading-stuck.md (new)
- Removed obsolete files: configure-nginx-proxy.sh, userwallet components, website-skeleton files, old fixKnowledge docs

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 08:18:26 +01:00

82 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# Check status of Docker services (bitcoind signet, mempool) and mining.
# Local only: no SSH. Run on the machine where Docker runs.
# Usage: ./data/check-services-status.sh
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
BITCOIND_CONTAINER="bitcoin-signet-instance"
DATADIR="/root/.bitcoin"
echo "=== État des services (${BITCOIND_CONTAINER}, mempool) ==="
echo ""
# Docker containers
echo "--- Conteneurs Docker ---"
docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null || echo "Docker non disponible ou erreur"
echo ""
# Bitcoind
if docker ps -q -f "name=^${BITCOIND_CONTAINER}$" 2>/dev/null | grep -q .; then
echo "--- Bitcoind (${BITCOIND_CONTAINER}) ---"
BITCOIN_DIR=$(docker exec "$BITCOIND_CONTAINER" printenv BITCOIN_DIR 2>/dev/null || echo "$DATADIR")
if docker exec "$BITCOIND_CONTAINER" bitcoin-cli -datadir="$BITCOIN_DIR" getblockchaininfo &>/dev/null; then
BCI=$(docker exec "$BITCOIND_CONTAINER" bitcoin-cli -datadir="$BITCOIN_DIR" getblockchaininfo 2>/dev/null)
BLOCKS=$(echo "$BCI" | jq -r '.blocks // "?"')
CHAIN=$(echo "$BCI" | jq -r '.chain // "?"')
HEADERS=$(echo "$BCI" | jq -r '.headers // "?"')
echo " RPC: OK"
echo " Chaîne: $CHAIN | Blocs: $BLOCKS | Headers: $HEADERS"
if [ "$BLOCKS" != "?" ]; then
TIP_TIME=$(docker exec "$BITCOIND_CONTAINER" bitcoin-cli -datadir="$BITCOIN_DIR" getblock "$(docker exec "$BITCOIND_CONTAINER" bitcoin-cli -datadir="$BITCOIN_DIR" getblockhash "$BLOCKS" 2>/dev/null)" 2>/dev/null | jq -r '.time // 0')
if [ -n "$TIP_TIME" ] && [ "$TIP_TIME" != "0" ]; then
echo " Dernier bloc (time): $TIP_TIME ($(date -d "@${TIP_TIME}" 2>/dev/null || echo "N/A"))"
fi
fi
else
echo " RPC: HORS SERVICE (bitcoind ne répond pas)"
RPC_ERROR=$(docker exec "$BITCOIND_CONTAINER" bitcoin-cli -datadir="$BITCOIN_DIR" getblockchaininfo 2>&1 || true)
if echo "$RPC_ERROR" | grep -q "Loading wallet"; then
echo " ⚠️ Bitcoind est bloqué en chargement de wallet"
echo " Cause probable: wallet volumineux ou corrompu"
echo " Solution: Attendre quelques minutes ou redémarrer: docker restart ${BITCOIND_CONTAINER}"
elif echo "$RPC_ERROR" | grep -q "Could not connect"; then
echo " ⚠️ Bitcoind ne répond pas du tout"
echo " Cause probable: bitcoind a planté dans le conteneur"
echo " Solution: Redémarrer le conteneur: docker restart ${BITCOIND_CONTAINER}"
else
echo " Erreur RPC: $RPC_ERROR"
echo " Solution: Redémarrer le conteneur: docker restart ${BITCOIND_CONTAINER}"
fi
fi
echo ""
echo " Processus dans le conteneur:"
docker exec "$BITCOIND_CONTAINER" ps aux 2>/dev/null | head -20 || true
# Vérifier si bitcoind est présent dans les processus
if ! docker exec "$BITCOIND_CONTAINER" ps aux 2>/dev/null | grep -q "[b]itcoind"; then
echo " ⚠️ ATTENTION: Le processus bitcoind n'est pas présent dans le conteneur"
echo " Le conteneur est actif mais bitcoind a planté"
echo " Solution immédiate: docker restart ${BITCOIND_CONTAINER}"
fi
echo ""
echo " Dernières lignes debug.log:"
docker exec "$BITCOIND_CONTAINER" tail -3 "${BITCOIN_DIR}/signet/debug.log" 2>/dev/null || true
else
echo "--- Bitcoind: conteneur ${BITCOIND_CONTAINER} non trouvé ou arrêté ---"
fi
echo ""
# Mempool stack
echo "--- Mempool (docker-compose.signet.yml) ---"
if [ -f "${PROJECT_DIR}/mempool/docker-compose.signet.yml" ]; then
(cd "${PROJECT_DIR}/mempool" && docker compose -f docker-compose.signet.yml ps 2>/dev/null) || \
(cd "${PROJECT_DIR}/mempool" && docker-compose -f docker-compose.signet.yml ps 2>/dev/null) || true
else
echo " Fichier compose non trouvé"
fi
echo ""
echo "=== Fin du rapport ==="