Files
timmy-tower/infrastructure/ops.sh
alexpaynex 8acc30d41e Update node to use Bitcoin Knots for improved flexibility
Switch to the Bitcoin Knots Docker image and adjust data directory paths and healthcheck commands in docker-compose.yml, lnd-init.sh, ops.sh, and setup.sh.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 418bf6f8-212b-4bb0-a7a5-8231a061da4e
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 66d0db34-90d1-4f85-b27d-f9f747253c18
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9f85e954-647c-46a5-90a7-396e495a805a/418bf6f8-212b-4bb0-a7a5-8231a061da4e/sPDHkg8
Replit-Helium-Checkpoint-Created: true
2026-03-18 18:18:08 +00:00

129 lines
5.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# ============================================================
# Timmy Node — Day-to-day operations helper
# Usage: bash ops.sh <command>
# ============================================================
INFRA_DIR="/opt/timmy-node"
cd "$INFRA_DIR" 2>/dev/null || { echo "Run on the droplet, not locally"; exit 1; }
CYAN='\033[0;36m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
case "${1:-help}" in
status)
echo -e "\n${CYAN}── Docker services ──────────────────────────${NC}"
docker compose ps
echo -e "\n${CYAN}── Bitcoin sync ──────────────────────────────${NC}"
docker exec bitcoin bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo 2>/dev/null \
| jq '{blocks, headers, verificationprogress, size_on_disk}' \
|| echo "Bitcoin not ready"
echo -e "\n${CYAN}── LND state ─────────────────────────────────${NC}"
docker exec lnd lncli --network=mainnet getinfo 2>/dev/null \
| jq '{identity_pubkey, alias, num_peers, num_active_channels, synced_to_chain}' \
|| echo "LND not ready"
echo -e "\n${CYAN}── LND wallet balance ────────────────────────${NC}"
docker exec lnd lncli --network=mainnet walletbalance 2>/dev/null \
| jq '{confirmed_balance, unconfirmed_balance}' \
|| true
echo -e "\n${CYAN}── LND channel balance ───────────────────────${NC}"
docker exec lnd lncli --network=mainnet channelbalance 2>/dev/null \
| jq '{balance, pending_open_balance}' \
|| true
;;
sync)
watch -n 10 'docker exec bitcoin bitcoin-cli getblockchaininfo \
| jq "{blocks, verificationprogress, size_on_disk}"'
;;
logs)
SERVICE="${2:-}"
if [[ -z "$SERVICE" ]]; then
docker compose logs -f --tail=50
else
docker compose logs -f --tail=100 "$SERVICE"
fi
;;
restart)
SERVICE="${2:-}"
if [[ -z "$SERVICE" ]]; then
docker compose restart
else
docker compose restart "$SERVICE"
fi
;;
fund)
echo -e "${CYAN}Your on-chain deposit address (send BTC here to fund channels):${NC}"
docker exec lnd lncli --network=mainnet newaddress p2wkh | jq -r .address
;;
channels)
echo -e "\n${CYAN}── Active channels ───────────────────────────${NC}"
docker exec lnd lncli --network=mainnet listchannels 2>/dev/null \
| jq '.channels[] | {remote_pubkey, capacity, local_balance, remote_balance, active}'
echo -e "\n${CYAN}── Pending channels ──────────────────────────${NC}"
docker exec lnd lncli --network=mainnet pendingchannels 2>/dev/null \
| jq '{pending_open_channels: .pending_open_channels | length, pending_closing_channels: .pending_closing_channels | length}'
;;
open-channel)
echo -e "${CYAN}Open a channel — usage:${NC}"
echo " bash ops.sh open-channel <peer_pubkey>@<host>:<port> <amount_sats>"
if [[ -n "${2:-}" && -n "${3:-}" ]]; then
docker exec lnd lncli --network=mainnet connect "$2" 2>/dev/null || true
PUBKEY=$(echo "$2" | cut -d@ -f1)
docker exec lnd lncli --network=mainnet openchannel \
--node_key "$PUBKEY" \
--local_amt "$3" \
--push_amt 0
fi
;;
lnbits-key)
echo -e "${CYAN}LNbits API keys for Timmy wallet:${NC}"
grep "LNBITS" /root/node-credentials.txt 2>/dev/null || \
echo "Check /root/node-credentials.txt — or open LNbits dashboard"
TSHOST=$(tailscale status --json 2>/dev/null | jq -r '.Self.DNSName' | sed 's/\.$//')
echo -e "\nLNbits dashboard: ${GREEN}https://$TSHOST${NC}"
;;
update)
echo -e "${YELLOW}Pulling latest Docker images...${NC}"
docker compose pull
docker compose up -d
ok "Done"
;;
backup)
BACKUP_FILE="/root/lnd-backup-$(date +%Y%m%d-%H%M%S).tar.gz"
echo -e "${CYAN}Backing up LND channel state to $BACKUP_FILE${NC}"
tar -czf "$BACKUP_FILE" -C /data/lnd .
echo -e "${GREEN}Backup saved. Copy this file off the server:${NC}"
echo " scp root@<node>:$BACKUP_FILE ./lnd-backup.tar.gz"
;;
help|*)
echo -e "\n${CYAN}Timmy Node operations:${NC}"
echo ""
echo " bash ops.sh status — overview of all services + balances"
echo " bash ops.sh sync — watch Bitcoin chain sync progress"
echo " bash ops.sh logs [service] — tail logs (bitcoin | lnd | lnbits)"
echo " bash ops.sh restart [svc] — restart a service or all services"
echo " bash ops.sh fund — get on-chain deposit address"
echo " bash ops.sh channels — list open and pending channels"
echo " bash ops.sh open-channel — open a Lightning channel"
echo " bash ops.sh lnbits-key — show LNBITS_URL and API key for Replit"
echo " bash ops.sh update — pull latest Docker images"
echo " bash ops.sh backup — backup LND channel state"
echo ""
;;
esac