readiness.sh
Overview
`readiness.sh` is a lightweight shell script designed to check the synchronization status of a local Ethereum beacon node daemon (commonly referred to as `daemon-beacon`). Its primary purpose is to determine if the beacon node has fully synced with the Ethereum network, which is critical for ensuring readiness before the node can participate in or serve data reliably.
The script queries the beacon node's REST API endpoint, inspects the syncing status, and returns an appropriate exit code and message based on the node's synchronization state. This behavior makes it suitable for use as a readiness probe in container orchestration systems (e.g., Kubernetes), monitoring tools, or automation workflows that depend on the node being fully synced.
Detailed Explanation
Script Behavior
Fetch Syncing Status
The script sends a silent HTTP GET request to the local beacon node's sync status endpoint:http://localhost:5052/eth/v1/node/syncingIt captures the JSON response. If the request fails (e.g., service not reachable), the script exits immediately with code
1.Parse Syncing Flag
Usingjq, a lightweight JSON processor, the script extracts the boolean field.data.is_syncingfrom the JSON response.Check Sync Status
If
.data.is_syncingisfalse, it indicates the beacon node is fully synced:Prints:
"daemon-beacon is synced"Exits with status code
0(success).
Otherwise, it prints
"daemon-beacon is still syncing"and exits with status code1(failure).
Explanation of Script Components
This script is a simple linear flow without functions or classes. Below is a breakdown of the main steps and commands.
Step | Command/Concept | Purpose |
|---|---|---|
1 | `curl -sf http://localhost:5052/eth/v1/node/syncing` | Silent HTTP request to beacon node API endpoint |
2 | ` | |
3 | `jq -r '.data.is_syncing'` | Parse JSON field `is_syncing` from response |
4 | `if [[ $IS_SYNCING == false ]]` | Branch based on syncing status |
5 | `echo "daemon-beacon is synced"` and `exit 0` | Success message and exit code |
6 | `echo "daemon-beacon is still syncing"` and `exit 1` | Failure message and exit code |
Usage Examples
Basic usage in CLI or script
./readiness.sh
If the beacon node is synced:
daemon-beacon is syncedExit code:
0If the beacon node is still syncing:
daemon-beacon is still syncingExit code:
1
Integration with Kubernetes Readiness Probe
This script is well-suited for Kubernetes readiness probes. Example snippet in a Pod manifest:
readinessProbe:
exec:
command:
- /bin/bash
- -c
- /path/to/readiness.sh
initialDelaySeconds: 10
periodSeconds: 15
The container will be marked ready only once the script exits with `0`, i.e., after the beacon node finishes syncing.
Important Implementation Details
Reliance on Localhost API:
The script assumes the beacon node's REST API is exposed onlocalhostport5052. Adjust accordingly if the API is hosted elsewhere.Silent curl with Fail on Error:
curl -sfsuppresses progress output and fails silently on HTTP errors, preventing noisy logs and ensuring robust failure detection.JSON Parsing with jq:
Usingjqallows safe extraction of theis_syncingflag from the JSON response. The script expects the field.data.is_syncingto be present.Exit Codes:
The script uses standard Unix exit codes where0means success (ready) and1means not ready or error.
Interaction with Other System Components
Beacon Node Daemon:
This script depends directly on the beacon node's REST API endpoint to retrieve sync status.Monitoring and Orchestration Tools:
Typically called by external systems (e.g., Kubernetes, Prometheus exporters, or custom automation scripts) to determine if the node is ready for traffic.Logging and Alerting Systems:
The output messages can be logged or used as triggers for alerts regarding node synchronization status.Potential Extension:
Could be combined with liveness probes or other health checks for full node lifecycle management.
Visual Diagram
The following flowchart represents the workflow of `readiness.sh`:
flowchart TD
Start([Start])
CurlReq["Send HTTP GET request to\nhttp://localhost:5052/eth/v1/node/syncing"]
CurlFail{"Request Success?"}
ParseSync["Parse JSON response:\n.data.is_syncing"]
IsSyncing{"Is .data.is_syncing == false?"}
Synced["Print 'daemon-beacon is synced'\nExit with code 0"]
Syncing["Print 'daemon-beacon is still syncing'\nExit with code 1"]
CurlFailNo["Exit with code 1"]
Start --> CurlReq
CurlReq --> CurlFail
CurlFail -- No --> CurlFailNo
CurlFail -- Yes --> ParseSync
ParseSync --> IsSyncing
IsSyncing -- Yes --> Synced
IsSyncing -- No --> Syncing
Summary
readiness.shis a simple, effective script for checking Ethereum beacon node sync status.Uses REST API query and JSON parsing to determine readiness.
Returns standard exit codes suitable for integration with container orchestrators.
Minimal dependencies:
curlandjq.Critical component for operational readiness and automation in Ethereum node deployments.