readiness.sh


Overview

`readiness.sh` is a lightweight Bash script designed to perform a readiness check for a service named **midgard** running locally on port 8080. It verifies whether the service's health endpoint reports that the system is "in sync," indicating readiness to handle requests. The script is intended to be used as a readiness probe in container orchestration platforms (like Kubernetes), or as a simple health check utility in deployment pipelines or monitoring systems.


Detailed Explanation

Script Purpose


Script Breakdown

#!/bin/bash
HEALTH=$(curl -sf http://localhost:8080/v2/health) || exit 1
IN_SYNC=$(echo $HEALTH | jq -r '.inSync')
if [[ $IN_SYNC == true ]]; then
  echo "midgard is synced"
  exit 0
fi
echo "midgard is still syncing"
exit 1

Parameters and Environment


Usage Example

Run the script as a standalone command:

./readiness.sh

Possible outputs and exit codes:

Output

Exit Code

Meaning

`midgard is synced`

0

Service is ready and in sync.

`midgard is still syncing`

1

Service is not ready yet.

(no output, immediate exit)

1

Health endpoint unreachable or error.

This makes the script suitable for integration as a readiness probe in orchestration systems:

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

Implementation Details / Algorithms


Interaction With Other System Components

The script acts as a bridge between midgard's internal health status and external systems that need to make decisions about routing traffic or triggering alerts.


Flowchart Representing Script Workflow

flowchart TD
    A[Start] --> B{Run curl request<br>to /v2/health}
    B -- Success --> C[Parse JSON with jq<br>extract 'inSync']
    B -- Failure --> G[Exit 1: Health check failed]
    C --> D{Is inSync == true?}
    D -- Yes --> E[Print "midgard is synced"<br>Exit 0]
    D -- No --> F[Print "midgard is still syncing"<br>Exit 1]

Summary

`readiness.sh` is a simple, effective readiness probe script for the midgard service. It performs an HTTP health check, parses JSON output to verify service synchronization status, and returns appropriate exit codes to signal readiness. Its minimal dependencies and clear logic make it ideal for integration into automated deployment and monitoring pipelines.