startup.sh


Overview

`startup.sh` is a lightweight Bash script designed to perform a simple startup health check for a local service running on the host machine. Its primary function is to verify the availability of a service listening at `http://localhost:26657` by querying its `/status` endpoint. The script includes a conditional mechanism to disable the startup probe if a specific file (`/root/disable_startup`) exists, which allows for manual override or temporary bypass of the health check.

This script is typically used as a startup probe in containerized environments (e.g., Kubernetes) or init scripts to ensure that dependent services are available before proceeding with further application initialization or readiness signaling.


Script Breakdown and Explanation

#!/bin/bash

DISABLE_STARTUP_PROBE=/root/disable_startup

if [[ -f "$DISABLE_STARTUP_PROBE" ]]; then
  echo "startup probe disabled"
  exit 0
fi

curl -sf http://localhost:26657/status && exit 0 || exit 1

1. Shebang

#!/bin/bash

2. Variable Declaration

DISABLE_STARTUP_PROBE=/root/disable_startup

3. Disable Probe Check

if [[ -f "$DISABLE_STARTUP_PROBE" ]]; then
  echo "startup probe disabled"
  exit 0
fi

4. Health Check Using curl

curl -sf http://localhost:26657/status && exit 0 || exit 1

This simple mechanism provides a binary health indication that can be used by orchestrators or monitoring systems.


Usage Example

To use this script as a startup health check, you might:

  1. Copy startup.sh into your container image or host system.

  2. Set executable permissions:

    chmod +x startup.sh
    
  3. Execute the script manually or configure it to run via container startup probes or init systems:

    ./startup.sh
    
  4. If you want to disable the health check temporarily:

    touch /root/disable_startup
    ./startup.sh
    # Output: startup probe disabled
    

Important Implementation Details


Interaction with Other System Components


Mermaid Flowchart Diagram

flowchart TD
    A[Start: Execute startup.sh] --> B{Check if /root/disable_startup exists}
    B -- Yes --> C[Print "startup probe disabled"]
    C --> D[Exit with 0 (success)]
    B -- No --> E[Execute curl -sf http://localhost:26657/status]
    E -- Success --> F[Exit with 0 (success)]
    E -- Failure --> G[Exit with 1 (failure)]

Summary

This script serves as a minimal but effective readiness or startup probe for a local service. It integrates smoothly into containerized environments or startup sequences, offering a simple disable mechanism and straightforward health check logic. Its compact design and clear exit codes make it ideal for automation and system orchestration workflows.