startup.sh


Overview

`startup.sh` is a lightweight Bash script designed to verify the startup status of a local service called `op-node`. It acts as a startup probe that can be used in containerized or orchestrated environments (e.g., Kubernetes) to determine if the `op-node` service is operational and ready to serve requests.

The script performs the following key functions:

This enables external orchestration tools to make informed decisions about the health and readiness of the `op-node` service.


Detailed Explanation

Constants and Variables


Script Logic and Steps

1. Check if startup probe is disabled

if [[ -f "$DISABLE_STARTUP_PROBE" ]]; then
  echo "startup probe disabled"
  exit 0
fi

2. Query the op-node service for version

VERSION=$(curl -sf -d '{"jsonrpc":"2.0","method":"optimism_version","params":[],"id":1}' -H 'Content-Type: application/json' http://localhost:9545) || exit 1

3. Parse the JSON response to extract the version result

RESULT=$(echo $VERSION | jq -r '.result')

4. Check if the version result is non-empty and determine service status

if [[ result != "" ]]; then
  echo "op-node started"
  exit 0
fi

echo "op-node not started"
exit 1

Usage Example

Run the script directly in the environment where the `op-node` service is running locally on port `9545`:

./startup.sh
op-node started
startup probe disabled

or

op-node not started

Exit codes:


Implementation Details and Algorithms


Interaction with Other System Components


Recommended Fix

To correct the bug in the script, change:

if [[ result != "" ]]; then

to

if [[ "$RESULT" != "" ]]; then

This ensures the check evaluates the actual variable content.


Flowchart Diagram

flowchart TD
    Start([Start]) --> CheckDisable{Is /data/disable_startup present?}
    CheckDisable -- Yes --> PrintDisabled["Print 'startup probe disabled'"] --> ExitSuccess[Exit 0]
    CheckDisable -- No --> SendRequest["Send JSON-RPC request to localhost:9545"]
    SendRequest -- Fail --> ExitFail[Exit 1]
    SendRequest -- Success --> ParseResponse["Parse JSON response with jq"]
    ParseResponse --> CheckResult{Is result non-empty?}
    CheckResult -- Yes --> PrintStarted["Print 'op-node started'"] --> ExitSuccess
    CheckResult -- No --> PrintNotStarted["Print 'op-node not started'"] --> ExitFail

Summary

`startup.sh` is a concise startup readiness probe script for the `op-node` service. It conditionally disables itself, performs a JSON-RPC version query to verify service readiness, and exits with appropriate codes for use in automated orchestration. The script contains a minor bug in variable usage, which should be corrected for reliable operation. Its simple but effective design integrates tightly with container health checking mechanisms, ensuring robust startup validation.