From 50a6dd62ad05e2efb5c260a1a1544629a5263a4a Mon Sep 17 00:00:00 2001 From: Kieran O Mahony <32955813+kieranomahony98@users.noreply.github.com> Date: Mon, 21 Feb 2022 03:43:01 +0000 Subject: [PATCH] Issue 602 (#641) * check if running Signed-off-by: Kieran O Mahony * fix indent Signed-off-by: Kieran O Mahony better detection in create channel Signed-off-by: Kieran O Mahony bring network down first case Signed-off-by: Kieran O Mahony bring network down first case changed count of containers to 4 Signed-off-by: Kieran O Mahony add echo Signed-off-by: Kieran O Mahony typo Signed-off-by: Kieran O Mahony Co-authored-by: Kieran O Mahony --- test-network/network.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test-network/network.sh b/test-network/network.sh index 80df65b4..1bf091f4 100755 --- a/test-network/network.sh +++ b/test-network/network.sh @@ -267,9 +267,25 @@ function networkUp() { # call the script to create the channel, join the peers of org1 and org2, # and then update the anchor peers for each organization function createChannel() { - # Bring up the network if it is not already up. + # Bring up the network if it is not already up. + bringUpNetwork="false" - if [ ! -d "organizations/peerOrganizations" ]; then + if ! $CONTAINER_CLI info > /dev/null 2>&1 ; then + fatalln "$CONTAINER_CLI network is required to be running to create a channel" + fi + + # check if all containers are present + CONTAINERS=($($CONTAINER_CLI ps | grep hyperledger/ | awk '{print $2}')) + len=$(echo ${#CONTAINERS[@]}) + + if [[ $len -ge 4 ]] && [[ ! -d "organizations/peerOrganizations" ]]; then + echo "Bringing network down to sync certs with containers" + networkDown + fi + + [[ $len -lt 4 ]] || [[ ! -d "organizations/peerOrganizations" ]] && bringUpNetwork="true" || echo "Network Running Already" + + if [ $bringUpNetwork == "true" ]; then infoln "Bringing up network" networkUp fi