init.sh
Overview
`init.sh` is a shell script designed to initialize and manage the lifecycle of an `op-node` service within a container or Unix-like environment. The script automates the installation of necessary dependencies, configures the execution parameters for the `op-node`, and ensures graceful shutdown when termination signals are received.
This script is typically used as an entrypoint or startup script in containerized deployments or server setups where the `op-node` operates as a blockchain node component connecting to Layer 1 (L1) and Layer 2 (L2) Ethereum networks.
Detailed Explanation
Script Purpose
Install required utilities (
bash,curl,jq) via Alpine Linux'sapkpackage manager.Define runtime environment variables and configuration options.
Launch the
op-nodewith a comprehensive set of command-line flags to specify network, RPC endpoints, P2P bootnodes, and synchronization options.Manage the lifecycle of the
op-nodeprocess, enabling clean shutdown on receiving termination signals (TERM,INT).
Variables
Variable | Description |
|---|---|
`DATA_DIR` | Directory path configured as `/data` (though unused in current script). |
`PID` | Stores the Process ID of the running `op-node` instance. |
Functions
1. start()
Starts the `op-node` process with all required parameters.
Functionality
Runs
op-nodein the background with a detailed set of command-line options.Sets network to
base-mainnet.Configures RPC server to bind on all interfaces (
0.0.0.0) at port9545.Connects to configured Layer 1 RPC and beacon endpoints (
$L1_RPC_ENDPOINT,$L1_BEACON_ENDPOINT).Enables fetching all sidecars from the beacon.
Sets trust and RPC kind for L1 interaction (
trustrpcanddebug_geth).Configures Layer 2 connection over HTTP with JWT authentication.
Specifies the engine kind as
reth.Loads protocol versions for rollup.
Sets sync mode to execution-layer.
Configures verifier confirmations to 4.
Specifies a list of P2P bootnodes (enr records).
Sets user agent for P2P communications.
Runs the node in the background and stores its PID.
Parameters
None
Returns
None (runs process in background)
Usage Example
start
2. stop()
Gracefully stops the running `op-node` process.
Functionality
Logs a message indicating that it is sending a termination signal to the
op-nodeprocess.Sends the
killsignal to the process with PID stored inPID.Waits in a loop until the process fully exits.
Parameters
None
Returns
None
Usage Example
stop
Signal Handling
The script traps
TERMandINTsignals.Upon receiving these signals, it calls the
stopfunction to gracefully terminate theop-nodeprocess.
Execution Flow
Installs dependencies.
Defines environment variables.
Defines
startandstopfunctions.Sets up trap handlers for clean shutdown.
Calls
startto launch the node.Waits for the
op-nodeprocess to exit.
Important Implementation Details
The script uses
set -eto stop execution if any command fails, ensuring reliability.apk add bash curl jqinstalls essential utilities for extended shell scripting, HTTP requests, and JSON parsing — though these tools are not explicitly used in this script, their presence may be required by other scripts or components in the container.The
op-nodeis launched with a complex configuration specifying Layer 1/Layer 2 endpoints, sync mode, rollup protocol versions, and a predefined list of P2P bootnodes in ENR format.The script runs
op-nodein the background (&) and stores its PID for management.The
trapcommand ensures that when the container or environment sends termination signals, theop-nodeis stopped gracefully to prevent data corruption or incomplete shutdowns.
Interaction with Other System Components
L1_RPC_ENDPOINT and L1_BEACON_ENDPOINT: These environment variables must be set externally before running the script, pointing to the Layer 1 Ethereum RPC and beacon node endpoints respectively.
JWT Secret: Expects a JWT secret file at
/jwt.hexfor authenticating with the L2 engine.P2P Bootnodes: Contains hardcoded ENR addresses for peer discovery within the P2P network.
op-nodeBinary: This script assumes the existence of theop-nodeexecutable in the system's PATH. This binary is responsible for the actual blockchain node operations.Container or Host System: This script is commonly used as an entrypoint in containerized environments orchestrating the node lifecycle.
Visual Diagram
The following flowchart illustrates the main functions and signal handling workflow within `init.sh`:
flowchart TD
StartScript["Start Script Execution"]
InstallDeps["Install dependencies (bash, curl, jq)"]
DefineFuncs["Define start() and stop() functions"]
SetupTrap["Setup signal traps (TERM, INT)"]
CallStart["Call start() to launch op-node"]
WaitPID["Wait for op-node process (PID)"]
SignalReceived["Signal received (TERM/INT)"]
CallStop["Call stop() to kill op-node"]
WaitStop["Wait until op-node exits"]
ExitScript["Exit script"]
StartScript --> InstallDeps --> DefineFuncs --> SetupTrap --> CallStart --> WaitPID
WaitPID -->|SignalReceived| SignalReceived
SignalReceived --> CallStop --> WaitStop --> ExitScript
Summary
`init.sh` is a robust and minimal shell script designed to launch and manage an `op-node` instance with detailed configuration for Layer 1 and Layer 2 Ethereum networks. It ensures that dependencies are available, the node is started with consistent parameters, and handles graceful termination in response to system signals. This script plays a crucial role in the node lifecycle management within containerized or server environments.
Appendix: Environment Variables Expected
Variable | Description | Required | Example Value |
|---|---|---|---|
`L1_RPC_ENDPOINT` | URL of the Layer 1 Ethereum RPC endpoint | Yes | |
`L1_BEACON_ENDPOINT` | URL of the Layer 1 Beacon node endpoint | Yes | `https://beacon-node.example.com` |