Skip to content

Commit

Permalink
chore(Dockerfile): add health-check shell script (#1432)
Browse files Browse the repository at this point in the history
* ci: add health-check shell script
* ci: remove blank line

---------
Co-authored-by: Flouse <1297478+Flouse@users.noreply.github.com>
  • Loading branch information
Simon-Tl authored Sep 18, 2023
1 parent d2f54f0 commit e719adb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN set -eux; \
cmake \
clang \
llvm \
jq \
gcc; \
rm -rf /var/lib/apt/lists/*

Expand Down
36 changes: 36 additions & 0 deletions devtools/docker/health_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
block_number() {
block=$(curl -s 'http://127.0.0.1:8000' \
--header 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0", "method":"eth_blockNumber", "params": [], "id":42}' | jq '.result' |xargs printf %d 0xF)
echo $block
}

block_stats() {
current_block=$(block_number)
start_time=$(date +%s)
wait_seconds=60

while true; do
latest_block=$(block_number)
if [ $current_block -lt $latest_block ]
then
return 0
fi

current_time=$(date +%s)
elapsed_seconds=$((current_time - start_time))
if [ $elapsed_seconds -ge $wait_seconds ]
then
break
fi

sleep 1
done

echo "block does not grow in one minute, please check"
return 1
}


block_stats

0 comments on commit e719adb

Please sign in to comment.