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
Check if the daemon process is responsive by sending a JSON-RPC request.
Exit with a status code indicating the daemon’s readiness.
Allow disabling the startup probe by presence of a specific file.
Script Workflow
Disable Check
Looks for the file
/data/disable_startup.If this file exists, the script prints
"startup probe disabled"and exits with code0.This feature allows external systems (e.g., orchestrators, administrators) to bypass the readiness check when needed.
Daemon Readiness Check
Sends a POST request using
curltohttp://localhost:8547with 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
-soption runs curl silently, and-fcauses it to fail on HTTP errors.The content type header is set to
application/json.
Result Handling
If
curlreturns success (exit code 0), the script prints"daemon is responding"and exits with code0.If
curlfails, it prints"daemon is not responding"and exits with code1.
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:
Presence of
/data/disable_startupfile: controls probe disabling.Daemon listening on
http://localhost:8547: target endpoint.
**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
If daemon is ready, output:
daemon is responding
If daemon is not ready:
daemon is not responding
To disable the startup probe:
touch /data/disable_startup
./startup.sh
Output:
startup probe disabled
Important Implementation Details
Use of JSON-RPC call
eth_blockNumber:This method is a common JSON-RPC call for Ethereum nodes to get the most recent block number.
It is a lightweight and effective way to check if the node is alive and syncing or ready.
Use of
curlwith flags-sand-f:-s: silent mode to suppress progress meter and errors.-f: fail silently on HTTP errors (4xx or 5xx).This ensures that the script can rely on the exit status to determine success/failure without parsing output.
File-based disable flag:
This allows external systems to control the startup check dynamically without modifying the script.
Interaction with Other System Components
Daemon Process:
This script expects a daemon (likely a blockchain node) to be running locally and exposing a JSON-RPC interface on port 8547.
The script’s readiness check depends entirely on this service.
Container Orchestration / Monitoring Tools:
Can be used as a readiness probe in Kubernetes or other container management solutions.
The presence of the disable file can be controlled by higher-level automation to manage probe behavior.
File System:
Reads
/data/disable_startupto determine if the probe should be skipped.
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.