readiness.sh


Overview

`readiness.sh` is a lightweight shell script designed to serve as a **readiness probe** for a Blockbook-based blockchain indexer service. Its primary function is to determine if the Blockbook indexer is fully synchronized with the blockchain and hence ready to serve accurate data to clients.

This script is typically used in containerized environments (e.g., Kubernetes) where it runs repeatedly to inform the orchestration system whether the indexer instance should receive traffic. If the indexer is still syncing, the script signals that the pod is not ready, preventing premature routing of requests.


Functionality Summary


Detailed Breakdown

Constants

Name

Description

`DISABLE_READINESS_PROBE`

Path to a sentinel file (`/data/disable_readiness`) used to disable the readiness check explicitly.


Script Logic

1. Check for Probe Disablement

if [[ -f "$DISABLE_READINESS_PROBE" ]]; then
  echo "readiness probe disabled"
  exit 0
fi

2. Query Blockbook API for Status

STATUS=$(curl -sf http://localhost:8001/api/v2) || exit 1

3. Extract Synchronization Status

IN_SYNC=$(echo $STATUS | jq -r '.blockbook.inSync')
{
  "blockbook": {
    "inSync": true,
    ...
  }
}

4. Decision and Exit

if [[ $IN_SYNC == "true" ]]; then
    echo "blockbook is synced"
    exit 0
fi

echo "blockbook is still syncing"
exit 1

Usage Example

Assuming this script is run by Kubernetes as a readiness probe, the configuration might look like:

readinessProbe:
  exec:
    command:
      - /bin/bash
      - /path/to/readiness.sh
  initialDelaySeconds: 10
  periodSeconds: 10

Implementation Details and Algorithms


Interactions with Other System Components


Visual Diagram

flowchart TD
    Start[Start Readiness Probe]
    CheckDisable[Check if disable readiness file exists (/data/disable_readiness)]
    Disabled[Probe Disabled - Exit 0]
    QueryAPI[Query Blockbook API /api/v2 via curl]
    ParseSync[Parse .blockbook.inSync Flag using jq]
    InSyncTrue{Is inSync == true?}
    Ready[Indexer Ready - Exit 0]
    NotReady[Indexer Syncing or Error - Exit 1]

    Start --> CheckDisable
    CheckDisable -->|Exists| Disabled
    CheckDisable -->|Not exists| QueryAPI
    QueryAPI -->|Success| ParseSync
    QueryAPI -->|Fail| NotReady
    ParseSync --> InSyncTrue
    InSyncTrue -->|Yes| Ready
    InSyncTrue -->|No| NotReady

**Diagram Explanation:**


Summary

`readiness.sh` is a concise, reliable readiness probe script that integrates with Kubernetes or similar platforms to verify whether a Blockbook blockchain indexer is fully synchronized and ready to handle requests. It balances simplicity with operational flexibility by including a disable flag mechanism, leveraging the Blockbook API, and using standard Unix tooling for JSON parsing and HTTP requests.

This script plays a crucial role in ensuring that only fully synced indexer pods receive traffic, thereby maintaining data consistency and application stability.


End of Documentation for readiness.sh