startup.sh


Overview

`startup.sh` is a lightweight shell script designed to serve as a startup probe for a daemon process (likely an Ethereum-like node or similar blockchain service) running locally on port 8547. Its primary function is to determine whether the daemon is ready and responsive by sending a JSON-RPC request to retrieve the current block number.

The script also supports a mechanism to disable the startup probe via a specific file flag, allowing external control over the startup check behavior.


Detailed Breakdown

Purpose


Script Workflow

  1. Disable Check

    • Looks for the file /data/disable_startup.

    • If this file exists, the script prints "startup probe disabled" and exits with code 0.

    • This feature allows external systems (e.g., orchestrators, administrators) to bypass the readiness check when needed.

  2. Daemon Readiness Check

    • Sends a POST request using curl to http://localhost:8547 with the JSON-RPC payload:

      {"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}
      
    • This requests the current block number from the daemon, a standard method to verify if a blockchain node is operational.

    • The -s option runs curl silently, and -f causes it to fail on HTTP errors.

    • The content type header is set to application/json.

  3. Result Handling

    • If curl returns success (exit code 0), the script prints "daemon is responding" and exits with code 0.

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


Lines Explanation

Line(s)

Code

Explanation

1

`#!/bin/bash`

Shebang to run script in Bash shell.

3

`DISABLE_STARTUP_PROBE=/data/disable_startup`

Defines the path to the disable flag file.

5-8

Check if disable file exists: if yes, print message and exit 0.

Allows bypass of the startup probe.

10

`curl -sf -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:8547`

Sends JSON-RPC request to local daemon.

12-15

Checks curl exit status to determine daemon responsiveness, prints message and exits accordingly.

Provides readiness feedback.


Parameters and Return Values

This is a standalone script without input parameters or functions. Its "parameters" are implicit:

**Exit codes:**

Exit Code

Meaning

0

Startup probe disabled or daemon responding correctly.

1

Daemon not responding to the JSON-RPC request.


Usage Example

Assuming the daemon is running locally and listening on port 8547:

./startup.sh
daemon is responding
daemon is not responding
touch /data/disable_startup
./startup.sh

Output:

startup probe disabled

Important Implementation Details


Interaction with Other System Components


Visual Diagram

flowchart TD
    A[Start] --> B{Disable file exists?}
    B -- Yes --> C[Print "startup probe disabled"]
    C --> D[Exit 0]
    B -- No --> E[Send JSON-RPC request to daemon]
    E --> F{Request success?}
    F -- Yes --> G[Print "daemon is responding"]
    G --> D
    F -- No --> H[Print "daemon is not responding"]
    H --> I[Exit 1]

Summary

`startup.sh` is a minimal and efficient startup probe script that checks the health of a local daemon by sending a JSON-RPC request. It supports disabling via a file flag and exits with appropriate status codes suitable for integration with container orchestration readiness checks or monitoring workflows. Its simplicity and use of standard tools make it easy to maintain and adapt.