From fb40fa1208c6d3b80423961f3198ad4fb5e73a5f Mon Sep 17 00:00:00 2001 From: CRF1408 <76657627+CRF1408@users.noreply.github.com> Date: Mon, 22 Dec 2025 17:42:27 +0100 Subject: [PATCH] add simple JSON-RPC healthcheck script Adds a tiny eth_blockNumber-based JSON-RPC healthcheck script for the Base op-geth node. --- geth/check_geth_rpc.sh | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 geth/check_geth_rpc.sh diff --git a/geth/check_geth_rpc.sh b/geth/check_geth_rpc.sh new file mode 100644 index 00000000..4943b314 --- /dev/null +++ b/geth/check_geth_rpc.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Simple JSON-RPC healthcheck for Base op-geth. +# +# Usage: +# BASE_GETH_RPC_URL=http://localhost:8545 ./geth/check_geth_rpc.sh +# +# The script calls `eth_blockNumber` and considers the node healthy +# if it returns a non-empty result. + +RPC_URL="${BASE_GETH_RPC_URL:-http://localhost:8545}" +TIMEOUT="${BASE_GETH_RPC_TIMEOUT:-3}" + +log_err() { + echo "[geth-health] $*" >&2 +} + +if ! command -v curl >/dev/null 2>&1; then + log_err "curl not found in PATH" + exit 1 +fi + +payload='{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}' + +response="$(curl -sS \ + --max-time "${TIMEOUT}" \ + -H "Content-Type: application/json" \ + -d "${payload}" \ + "${RPC_URL}" 2>/dev/null || true)" + +if [ -z "${response}" ]; then + log_err "empty response from ${RPC_URL}" + exit 1 +fi + +if ! echo "${response}" | grep -q '"result"'; then + log_err "eth_blockNumber did not return a result: ${response}" + exit 1 +fi + +echo "[geth-health] ok: JSON-RPC is responding at ${RPC_URL}" +exit 0