From 8151b5597eaf79f3013d1f3bda841d4e7a7daf4b Mon Sep 17 00:00:00 2001 From: Vojtech Simetka Date: Wed, 22 Sep 2021 16:16:25 +0200 Subject: [PATCH] feat: configurable hostname to which blockchain and bee nodes are bound (#53) * feat: configurable hostname to which blockchan and bee nodes are bound * chore: enable debug for script * fix: revert awk * chore: debug more * Revert "chore: enable debug for script" This reverts commit c86a2ce359003b8aea1581011d82002e18152ccc. * Revert "chore: debug more" This reverts commit 516f389a1fceb4ca9831c1f07e7a53e897b34b3d. Co-authored-by: Ivan Vandot --- scripts/bee.sh | 18 ++++++++++++------ scripts/environment.sh | 12 +++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/scripts/bee.sh b/scripts/bee.sh index 75c6fe0..87aac8d 100755 --- a/scripts/bee.sh +++ b/scripts/bee.sh @@ -21,6 +21,7 @@ PARAMETERS: --own-image If passed, the used Docker image names will be identical as the name of the workers. --version=x.y.z used version of Bee client. --detach It will not log the output of Queen node at the end of the process. + --hostname=string Interface to which should the nodes be bound (default 127.0.0.0). USAGE exit 1 } @@ -55,7 +56,7 @@ fetch_queen_underlay_addr() { # Wait 2 mins for queen start TIMEOUT=$((2*12*WAITING_TIME)) while (( TIMEOUT > ELAPSED_TIME )) ; do - QUEEN_UNDERLAY_ADDRESS=$(curl -s localhost:1635/addresses | python -mjson.tool | grep "/ip4/" | awk '!/127.0.0.1/' | sed 's/,$//' | xargs) + QUEEN_UNDERLAY_ADDRESS=$(curl -s "$HOSTNAME:1635/addresses" | python -mjson.tool | grep "/ip4/" | awk "!/127.0.0.1/" | sed 's/,$//' | xargs) if [[ -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then echo "Waiting for the Queen initialization..." ELAPSED_TIME=$((ELAPSED_TIME+WAITING_TIME)) @@ -65,7 +66,7 @@ fetch_queen_underlay_addr() { break; fi done - + if (( TIMEOUT == ELAPSED_TIME )) ; then queen_failure fi @@ -77,8 +78,8 @@ log_queen() { } count_connected_peers() { - COUNT=$( (curl -s http://localhost:1635/peers | python -c 'import json,sys; obj=json.load(sys.stdin); print (len(obj["peers"]));') || echo 0 ) - + COUNT=$( (curl -s "http://$HOSTNAME:1635/peers" | python -c 'import json,sys; obj=json.load(sys.stdin); print (len(obj["peers"]));') || echo 0 ) + echo "$COUNT" } @@ -108,6 +109,7 @@ SWAP_FACTORY_ADDRESS="0x5b1869D9A4C187F2EAa108f3062412ecf0526b24" POSTAGE_STAMP_ADDRESS="0xCfEB869F69431e42cdB54A4F4f105C19C080A601" PRICE_ORACLE_ADDRESS="0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B" INIT_ROOT_DATA_DIR="$MY_PATH/bee-data-dirs" +HOSTNAME="127.0.0.1" # Decide script action case "$1" in @@ -155,6 +157,10 @@ do LOG=false shift 1 ;; + --hostname=*) + HOSTNAME="${1#*=}" + shift 1 + ;; --help) usage ;; @@ -180,7 +186,7 @@ if [ -z "$QUEEN_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then EXTRA_QUEEN_PARAMS="-v $INIT_ROOT_DATA_DIR/$QUEEN_CONTAINER_NAME:/home/bee/.bee" fi if [ "$PORT_MAPS" -ge 1 ] ; then - EXTRA_QUEEN_PARAMS="$EXTRA_QUEEN_PARAMS -p 127.0.0.1:1633-1635:1633-1635" + EXTRA_QUEEN_PARAMS="$EXTRA_QUEEN_PARAMS -p $HOSTNAME:1633-1635:1633-1635" fi echo "start Bee Queen process" @@ -229,7 +235,7 @@ for i in $(seq 1 1 "$WORKERS"); do if [ $PORT_MAPS -gt $i ] ; then PORT_START=$((1633+(10000*i))) PORT_END=$((PORT_START + 2)) - EXTRA_WORKER_PARAMS="$EXTRA_WORKER_PARAMS -p 127.0.0.1:$PORT_START-$PORT_END:1633-1635" + EXTRA_WORKER_PARAMS="$EXTRA_WORKER_PARAMS -p $HOSTNAME:$PORT_START-$PORT_END:1633-1635" fi # run docker container diff --git a/scripts/environment.sh b/scripts/environment.sh index 26f0125..777c653 100755 --- a/scripts/environment.sh +++ b/scripts/environment.sh @@ -15,6 +15,7 @@ PARAMETERS: 2. 11633:11635 3. 21633:21635 (...) number represents the nodes number to map from. Default is 2. + --hostname=string Interface to which should the nodes be bound (default 127.0.0.0). USAGE exit 1 } @@ -44,6 +45,7 @@ LOG=true SWARM_BLOCKCHAIN_NAME="$BEE_ENV_PREFIX-blockchain" SWARM_NETWORK="$BEE_ENV_PREFIX-network" PORT_MAPS=2 +HOSTNAME="127.0.0.1" # Decide script action case "$1" in @@ -80,6 +82,10 @@ do LOG=false shift 1 ;; + --hostname=*) + HOSTNAME="${1#*=}" + shift 1 + ;; --help) usage ;; @@ -97,7 +103,7 @@ echo "Create Docker network..." echo "Start Blockchain node..." BLOCKCHAIN_CONTAINER=$(docker container ls -qaf name=$SWARM_BLOCKCHAIN_NAME) if [ -z "$BLOCKCHAIN_CONTAINER" ] ; then - BLOCKCHAIN_ARGUMENTS="--name $SWARM_BLOCKCHAIN_NAME --network $SWARM_NETWORK -p 127.0.0.1:9545:9545 -d" + BLOCKCHAIN_ARGUMENTS="--name $SWARM_BLOCKCHAIN_NAME --network $SWARM_NETWORK -p $HOSTNAME:9545:9545 -d" if $EPHEMERAL ; then BLOCKCHAIN_ARGUMENTS="$BLOCKCHAIN_ARGUMENTS --rm" fi @@ -110,7 +116,7 @@ fi sleep 5 # Build up bee.sh parameters -BEE_SH_ARGUMENTS="--workers=$WORKERS --own-image --port-maps=$PORT_MAPS" +BEE_SH_ARGUMENTS="--workers=$WORKERS --own-image --port-maps=$PORT_MAPS --hostname=$HOSTNAME" if $EPHEMERAL ; then BEE_SH_ARGUMENTS="$BEE_SH_ARGUMENTS --ephemeral" fi @@ -122,7 +128,7 @@ fi echo "Start Bee nodes..." "$MY_PATH/bee.sh" start $BEE_SH_ARGUMENTS -# If the code run reach this point without detach flag, +# If the code run reach this point without detach flag, # then the user interrupted the log process in the bee.sh if $LOG ; then docker stop $SWARM_BLOCKCHAIN_NAME