Created
May 1, 2026 03:40
-
-
Save dreaded369/01c58e4804aceb11ed4c1a82bd846cd0 to your computer and use it in GitHub Desktop.
Pulsechain GETH watchdog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Notes: | |
| # Figure out your restart command. The valuesbelow are mine and work for my docker compose setup. If've you installed native | |
| # or using vanilla docker yours might be different. | |
| # After saving the file locally run: chmod -x <path-to-file>/watchdog.sh | |
| # then run with <path-to-file>/watchdog.sh or if in the same folder then ./watchdog.sh | |
| # ========================================== | |
| # CONFIGURATION | |
| # ========================================== | |
| NODE_IP="192.168.50.103" # Update with your node's IP address, 127.0.0.1, 0.0.0.0, actual IP - whatever works for your setup | |
| NODE_PORT="8547" # default 8545 | |
| CHECK_INTERVAL=30 # Seconds between checks | |
| TIMEOUT_LIMIT=120 # Seconds to wait for increase before restart (2 minutes) | |
| # RESTART COMMAND | |
| # RESTART_CMD="sudo systemctl restart geth" | |
| # RESTART_CMD="docker restart geth" | |
| RESTART_CMD="cd /home/hamish/Docker/geth-prysm && docker-compose down && docker-compose up -d" # use the name of the service, not the value in the name: field | |
| # ========================================== | |
| # INTERNAL LOGIC | |
| # ========================================== | |
| last_height=0 | |
| last_change_time=$(date +%s) | |
| get_height() { | |
| local response=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' "http://$NODE_IP:$NODE_PORT") | |
| local hex=$(echo "$response" | grep -o '"result":"0x[0-9a-fA-F]*"' | sed 's/"result":"//;s/"//') | |
| [[ -z "$hex" ]] && echo 0 || echo $((hex)) | |
| } | |
| echo "Geth Watchdog Active: http://$NODE_IP:$NODE_PORT" | |
| while true; do | |
| height=$(get_height) | |
| now=$(date +%s) | |
| if [[ "$height" -gt "$last_height" ]]; then | |
| last_height=$height | |
| last_change_time=$now | |
| echo "[$(date +%T)] Height: $height" | |
| elif [[ $((now - last_change_time)) -ge "$TIMEOUT_LIMIT" ]]; then | |
| echo "[$(date +%T)] STALL DETECTED ($((now - last_change_time))s). Restarting..." | |
| eval "$RESTART_CMD" | |
| echo "[$(date +%T)] Restart triggered. Waiting 120s for node to initialize..." | |
| sleep 120 | |
| last_change_time=$(date +%s) | |
| last_height=0 | |
| else | |
| echo "[$(date +%T)] Stalled... $((now - last_change_time))s / $TIMEOUT_LIMIT s" | |
| fi | |
| sleep "$CHECK_INTERVAL" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment