refactor: startup (#56)

* refactor: polling chainid instead of sleeptime

* feat: add check for queen container running
This commit is contained in:
nugaon 2021-10-26 09:58:00 +02:00 committed by GitHub
parent 568f17465c
commit 7fb69c9b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -48,9 +48,17 @@ queen_failure() {
exit 1
}
check_queen_is_running() {
QUEEN_RUNNING=$(docker container inspect -f "{{.State.Running}}" $QUEEN_CONTAINER_NAME)
if [ "$QUEEN_RUNNING" == 'false' ] ; then
echo "Queen container has been stopped... stop environment start process..."
queen_failure
fi
}
fetch_queen_underlay_addr() {
if [[ -n "$QUEEN_UNDERLAY_ADDRESS" ]] ; then return; fi
check_queen_is_running
ELAPSED_TIME=0
WAITING_TIME=5
# Wait 2 mins for queen start
@ -271,6 +279,7 @@ ELAPSED_TIME=0
WAITING_TIME=2
TIMEOUT=$((2*30*WAITING_TIME))
while (( TIMEOUT > ELAPSED_TIME )) ; do
check_queen_is_running
COUNT=$(count_connected_peers)
[[ $COUNT < $WORKERS ]] || break
echo "Only $COUNT peers have been connected to the Queen Bee node yet. Waiting until $WORKERS"

View File

@ -113,7 +113,12 @@ else
fi
# Wait for blockchain service initializes
sleep 5
while : ; do
CHAINID=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"eth_chainId","id":1}' http://localhost:9545 | grep "0xfb4")
[[ "$CHAINID" != '{"id":1,"jsonrpc":"2.0","result":"0xfb4"}' ]] || break
echo "waiting for blockchain service is up..."
sleep 3
done
# Build up bee.sh parameters
BEE_SH_ARGUMENTS="--workers=$WORKERS --own-image --port-maps=$PORT_MAPS --hostname=$HOSTNAME"