startup.sh


Overview

`startup.sh` is a lightweight shell script designed to verify if a daemon (likely an Ethereum client or similar JSON-RPC server) is actively listening for network connections on the local machine. This script primarily serves as a startup probe to check the readiness of the daemon by querying its JSON-RPC endpoint. It helps orchestrators or monitoring systems determine if the service is operational before proceeding with dependent processes.

The script also supports disabling the startup probe check via the presence of a specific file, allowing manual or automated override of the readiness detection.


Detailed Explanation

Script Workflow

  1. Disable Probe Check (DISABLE_STARTUP_PROBE)
    The script first checks for the existence of the file /data/disable_startup. If this file exists, the startup probe is disabled, the script outputs a message, and exits successfully (exit 0). This mechanism provides a simple toggle to bypass the readiness check.

  2. Check Daemon Listening Status (net_listening)
    If the probe is not disabled, the script sends a JSON-RPC request to http://localhost:8545, invoking the net_listening method, which returns whether the daemon is currently listening on the network.

  3. Parse and React to Response

    • If the curl command fails (e.g., daemon not reachable), the script exits with status 1 indicating failure.

    • If the response indicates the daemon is listening (true), the script prints confirmation and exits with status 0.

    • Otherwise, it prints that the daemon is not listening and exits with status 1.


Variables and Constants

Variable

Description

DISABLE_STARTUP_PROBE

Path to the file that disables the startup check if present (`/data/disable_startup`).

`NET_LISTENING`

Stores the JSON-RPC response from the daemon querying `net_listening`.

`LISTENING`

Parsed boolean value extracted from `NET_LISTENING` indicating if daemon is listening.


Commands and Tools Used


Usage Example

# Run the startup probe script
./startup.sh

# Expected outputs:
# If /data/disable_startup exists
# startup probe disabled

# If daemon is listening
# daemon is listening

# If daemon is not listening or unreachable
# daemon is not listening

This script is typically used as a readiness probe in container orchestration platforms (e.g., Kubernetes) or in system init scripts to ensure that the daemon is ready before starting dependent services.


Important Implementation Details


Interaction with Other System Components


Mermaid Flowchart Diagram

flowchart TD
    A[Start] --> B{File /data/disable_startup exists?}
    B -- Yes --> C[Print "startup probe disabled"]
    C --> D[Exit 0]

    B -- No --> E[Send JSON-RPC POST to localhost:8545]
    E --> F{curl successful?}
    F -- No --> G[Exit 1]

    F -- Yes --> H[Parse JSON response to get .result]
    H --> I{Is .result == true?}
    I -- Yes --> J[Print "daemon is listening"]
    J --> D

    I -- No --> K[Print "daemon is not listening"]
    K --> G

Summary

`startup.sh` is a concise and effective shell script that acts as a startup readiness probe by querying a local daemon's JSON-RPC interface to confirm if it is actively listening on the network. It supports a simple disable switch and cleanly reports status, making it well-suited for integration in service orchestration and monitoring workflows.