anchorage_layer_simple/data/start-docker-services.sh
ncantu 937646cc45 Daily backup to git cron, backup/restore scripts, docs
**Motivations:**
- Export Signet and mining wallet backups to git with only 2 versions kept
- Document and add backup/restore scripts for signet and mining wallet

**Correctifs:**
- Backup-to-git uses SSH URL for passwordless cron; copy timestamped files only; prune to 2 versions; remove *-latest from backup repo

**Evolutions:**
- data/backup-to-git-cron.sh: daily export to git.4nkweb.com/4nk/backup
- save-signet-datadir-backup.sh, restore-signet-from-backup.sh, export-mining-wallet.sh, import-mining-wallet.sh
- features/backup-to-git-daily-cron.md, docs/MAINTENANCE.md backup section
- .gitignore: data/backup-to-git.log

**Pages affectées:**
- .gitignore, data/backup-to-git-cron.sh, docs/MAINTENANCE.md, features/backup-to-git-daily-cron.md
- save-signet-datadir-backup.sh, restore-signet-from-backup.sh, export-mining-wallet.sh, import-mining-wallet.sh
- Plus autres fichiers modifiés ou non suivis déjà présents dans le working tree
2026-02-04 03:07:57 +01:00

75 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Start Docker services at boot (bitcoind and mempool).
# This script ensures bitcoind starts before mempool.
# Can be called from systemd service or cron @reboot.
# Log: data/start-docker-services.log
#
# Local only: no SSH, no remote commands.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
LOG_FILE="$SCRIPT_DIR/start-docker-services.log"
MEMPOOL_COMPOSE="${PROJECT_DIR}/mempool/docker-compose.signet.yml"
BITCOIND_CONTAINER="bitcoin-signet-instance"
log() { echo "$(date -Iseconds) $*" | tee -a "$LOG_FILE"; }
cd "$PROJECT_DIR" || exit 1
log "=== Start Docker services at boot ==="
# Check if docker is available
if ! command -v docker &>/dev/null; then
log "ERROR: docker command not found"
exit 1
fi
# 1. Start bitcoind container (must be first)
if docker ps -a -q -f "name=^${BITCOIND_CONTAINER}$" 2>/dev/null | grep -q .; then
if docker ps -q -f "name=^${BITCOIND_CONTAINER}$" 2>/dev/null | grep -q .; then
log "$BITCOIND_CONTAINER already running"
else
log "Starting $BITCOIND_CONTAINER..."
if docker start "$BITCOIND_CONTAINER" &>/dev/null; then
log " $BITCOIND_CONTAINER started"
# Wait for bitcoind RPC to be ready (max 120 seconds at boot)
max_wait=120
wait_count=0
while [ $wait_count -lt $max_wait ]; do
BITCOIN_DATADIR=$(docker exec "$BITCOIND_CONTAINER" printenv BITCOIN_DIR 2>/dev/null || echo "/root/.bitcoin")
if docker exec "$BITCOIND_CONTAINER" bitcoin-cli -datadir="$BITCOIN_DATADIR" getblockchaininfo &>/dev/null; then
log " $BITCOIND_CONTAINER RPC ready after ${wait_count}s"
break
fi
sleep 2
wait_count=$((wait_count + 2))
done
if [ $wait_count -ge $max_wait ]; then
log " WARN: $BITCOIND_CONTAINER RPC not ready after ${max_wait}s (may still be starting)"
fi
else
log " ERROR: Failed to start $BITCOIND_CONTAINER"
fi
fi
else
log "SKIP: $BITCOIND_CONTAINER container not found"
fi
# 2. Start mempool stack (after bitcoind)
if [ -f "$MEMPOOL_COMPOSE" ]; then
log "Starting mempool stack..."
mem_ok=1
(cd "${PROJECT_DIR}/mempool" && docker compose -f docker-compose.signet.yml up -d &>/dev/null) && mem_ok=0
[ "$mem_ok" -ne 0 ] && (cd "${PROJECT_DIR}/mempool" && docker-compose -f docker-compose.signet.yml up -d &>/dev/null) && mem_ok=0
if [ "$mem_ok" -eq 0 ]; then
log " mempool stack started"
else
log " ERROR: Failed to start mempool stack"
fi
else
log "SKIP: mempool compose not found"
fi
log "=== Done ==="
tail -n 100 "$LOG_FILE" > "$LOG_FILE.tmp" && mv "$LOG_FILE.tmp" "$LOG_FILE"