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
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 code0(success), effectively skipping the health check.This mechanism allows operators to temporarily disable startup probes without modifying the script or deployment configuration.
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:8547usingcurl. 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,
-fmakescurlfail silently on server errors, and -d sends the request payload.If the
curlcommand succeeds (exit code 0), it means the daemon responded correctly, so the script prints"daemon is responding"and exits with0.If
curlfails, the script prints"daemon is not responding"and exits with1.
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
No parameters or arguments are accepted by this script.
Environment / File Dependencies:
/data/disable_startup— presence disables the startup probe.The daemon must be running locally and listening on port
8547for JSON-RPC HTTP requests.
Exit Codes:
0: Startup probe disabled or daemon is responsive.1: Daemon is not responding.
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
JSON-RPC Request:
The JSON payload sent:
{ "jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1 }This is a standard request to query the current block number from an Ethereum-compatible node. The choice of this method indicates the daemon likely implements Ethereum JSON-RPC API.
Health Check Semantics:
The script uses an HTTP POST to verify the daemon's responsiveness rather than just checking if the port is open.
Using
curl -fensures HTTP errors (like 500 or 404) cause failure, which is more accurate than just checking network connectivity.The disable file mechanism provides a simple toggle for health check behavior.
Interaction with Other System Components
Daemon Service:
The script interacts directly with the daemon service via HTTP on localhost port 8547. The daemon must support JSON-RPC over HTTP.
Container Orchestration / Monitoring:
This script is likely invoked as a startup or readiness probe by a container orchestrator (e.g., Kubernetes). Its exit code informs the orchestrator if the service is ready to accept traffic.
Configuration Management:
The presence of
/data/disable_startupsuggests some external process or volume mounts can control the startup probe's behavior dynamically.
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.