startup.sh


Overview

`startup.sh` is a lightweight shell script designed to act as a startup health probe for a service running locally on the machine. Its primary function is to determine whether the service should be considered "ready" by checking for a disabling flag file and then probing the service's HTTP status endpoint. This script is typically used in containerized or orchestrated environments (e.g., Kubernetes) as a startup probe to delay traffic routing to the service until it confirms readiness.


Detailed Explanation

Script Functionality


Script Breakdown

#!/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:27147/status && exit 0 || exit 1

Parameters and Return Values

This script does not take any command-line parameters and returns exit codes to indicate readiness:

Exit Code

Meaning

0

Startup probe passed (service ready or probe disabled)

1

Startup probe failed (service not ready)


Usage Example

This script is typically invoked by the system or orchestration platform as a startup probe.

./startup.sh
startup probe disabled

Implementation Details and Algorithms


Interaction with Other System Components


Summary Diagram

The following flowchart illustrates the logic flow of the `startup.sh` script:

flowchart TD
    A[Start] --> B{Is /root/disable_startup file present?}
    B -- Yes --> C[Print "startup probe disabled"]
    C --> D[Exit 0]
    B -- No --> E[Send HTTP GET to http://localhost:27147/status]
    E --> F{Request successful?}
    F -- Yes --> D
    F -- No --> G[Exit 1]

Conclusion

`startup.sh` is a minimal yet effective startup readiness probe script that balances simplicity and functionality. It allows easy disabling of the probe for maintenance or troubleshooting and performs a straightforward health check by querying a local service endpoint. Its design facilitates smooth integration with container orchestration systems to ensure that services only receive traffic when fully ready.