startup.sh


Overview

`startup.sh` is a lightweight shell script intended to act as a health check or startup probe for a daemon service running on the local machine. Its main purpose is to verify whether the daemon is operational and responsive on a specific JSON-RPC HTTP endpoint (`http://localhost:8547`). It also respects a "disable" flag that allows bypassing the check.

This script is typically used in containerized environments or service orchestration platforms (e.g., Kubernetes) to determine if the daemon process has started correctly and is ready to serve requests. It exits with a status code indicating success or failure of the check, enabling automated systems to react accordingly.


Detailed Explanation

Script Logic and Workflow

  1. Disable Probe Check:

    The script first checks for the presence of a file /data/disable_startup.

    • If this file exists, the script prints "startup probe disabled" and exits with a status code 0 (success), effectively skipping the health check.

    • This mechanism allows operators to temporarily disable startup probes without modifying the script or deployment configuration.

  2. Daemon Responsiveness Check:

    If the disable file is not present, the script sends a JSON-RPC request to the daemon's HTTP endpoint at http://localhost:8547 using curl. The request is a POST with JSON body querying the latest block number (eth_blockNumber), which is a common Ethereum JSON-RPC method.

    • The -s flag silences progress, -f makes curl fail silently on server errors, and -d sends the request payload.

    • If the curl command succeeds (exit code 0), it means the daemon responded correctly, so the script prints "daemon is responding" and exits with 0.

    • If curl fails, the script prints "daemon is not responding" and exits with 1.


No Classes or Functions

Since this is a shell script, it does not define any classes or functions. The logic is sequential and uses basic shell commands and conditional statements.


Parameters and Usage


Usage Example

# Run the startup probe script manually
./startup.sh

# Possible outputs:
# startup probe disabled
# daemon is responding
# daemon is not responding

# Exit code can be checked:
echo $?

Important Implementation Details


Interaction with Other System Components


Visual Diagram: Workflow of startup.sh

flowchart TD
    A[Start] --> B{Check /data/disable_startup file}
    B -- Yes --> C[Print "startup probe disabled"]
    C --> D[Exit 0]
    B -- No --> E[Send JSON-RPC POST to localhost:8547]
    E --> F{curl exit status}
    F -- 0 (Success) --> G[Print "daemon is responding"]
    G --> D
    F -- Non-zero (Failure) --> H[Print "daemon is not responding"]
    H --> I[Exit 1]

Summary

The `startup.sh` script is a focused utility that performs a simple yet effective health check against a local daemon exposing an Ethereum JSON-RPC endpoint. It supports a disable toggle, uses a concrete JSON-RPC method to verify daemon responsiveness, and returns appropriate exit codes for integration with monitoring or orchestration systems. Its simplicity and directness make it an ideal lightweight probe script in containerized or microservice environments.