@@ -46,6 +46,24 @@ case "$LOG_LEVEL" in
4646 ;;
4747esac
4848
49+ wait_for_pid () {
50+ local pid=" $1 "
51+
52+ # Check if the process exists at all before waiting
53+ if [[ ! -e " /proc/$pid " ]]; then
54+ echo " Process $pid does not exist." >&2
55+ return 1
56+ fi
57+
58+ echo " Waiting for process $pid to exit..."
59+ while [[ -e " /proc/$pid " ]]; do
60+ sleep 1
61+ done
62+ echo " Process $pid has exited."
63+ }
64+
65+
66+
4967# Add pruning for base
5068if [[ " ${RETH_PRUNING_ARGS+x} " = x ]]; then
5169 echo " Adding pruning arguments: $RETH_PRUNING_ARGS "
@@ -71,7 +89,7 @@ if [[ "$RETH_HISTORICAL_PROOFS" == "true" && -n "$RETH_HISTORICAL_PROOFS_STORAGE
7189 # wait for json-rpc to return a block number greater than 0 (synced beyond genesis)
7290 while true ; do
7391 RESPONSE=$( curl -s -X POST -H " Content-Type: application/json" -d ' {"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' http://127.0.0.1:" $RPC_PORT " 2> /dev/null || true)
74-
92+
7593 if echo " $RESPONSE " | grep -q ' "number":"0x0"' ; then
7694 echo " waiting for reth node to sync beyond genesis block"
7795 elif echo " $RESPONSE " | grep -q ' "result"' ; then
@@ -80,7 +98,7 @@ if [[ "$RETH_HISTORICAL_PROOFS" == "true" && -n "$RETH_HISTORICAL_PROOFS_STORAGE
8098 else
8199 echo " waiting for reth node to start up"
82100 fi
83-
101+
84102 sleep 1
85103 MAX_WAIT=$(( MAX_WAIT - 1 ))
86104 if [ " $MAX_WAIT " -eq 0 ]; then
@@ -93,7 +111,7 @@ if [[ "$RETH_HISTORICAL_PROOFS" == "true" && -n "$RETH_HISTORICAL_PROOFS_STORAGE
93111 # shut down gracefully
94112 kill " $PID "
95113
96- (wait " $PID " && echo " reth node initialized" ) || echo " warning: reth node exited with code $? "
114+ (wait_for_pid " $PID " && echo " reth node initialized" ) || echo " warning: reth node exited with code $? "
97115
98116 ADDITIONAL_ARGS=" $ADDITIONAL_ARGS --proofs-history --proofs-history.storage-path=$RETH_HISTORICAL_PROOFS_STORAGE_PATH "
99117
0 commit comments