#!/bin/bash echo "Checking replica set 1 status" until docker service ps mongo_primary1 --format '{{.CurrentState}}' do echo "Primary_1 Service not up yet" sleep 5; done & until docker service ps mongo_secondary1_1 --format '{{.CurrentState}}' do echo "secondary1_1 service not up yet" sleep 5; done until docker service ps mongo_secondary2_1 --format '{{.CurrentState}}' do echo "Secondary2_1 service not up yet" sleep 5; done sleep 2; echo "" echo "Primary 1 OK" echo "Secondary 1_1 OK" echo "Secondary 1_2 OK" echo "<-------------------------------->" sleep 2; #************************************************* # Second Replica set check #************************************************* echo "Checking replica set 2 status" until docker service ps mongo_primary2 --format '{{.CurrentState}}' do echo "Primary_2 Service not up yet" sleep 5; done & until docker service ps mongo_secondary2_1 --format '{{.CurrentState}}' do echo "secondary2_1 service not up yet" sleep 5; done until docker service ps mongo_secondary2_2 --format '{{.CurrentState}}' do echo "Secondary2_2 service not up yet" sleep 5; done sleep 2; echo "" echo "Primary 2 OK" echo "Secondary 2_1 OK" echo "Secondary 2_2 OK" echo "<-------------------------------->" sleep 2; #************************************************* # Third Replica set check #************************************************* echo "Checking replica set 3 status" until docker service ps mongo_primary3 --format '{{.CurrentState}}' do echo "Primary_3 Service not up yet" sleep 5; done & until docker service ps mongo_secondary3_1 --format '{{.CurrentState}}' do echo "secondary3_1 service not up yet" sleep 5; done until docker service ps mongo_secondary3_2 --format '{{.CurrentState}}' do echo "Secondary3_2 service not up yet" sleep 5; done sleep 2; echo "" echo "Primary 3 OK" echo "Secondary 3_1 OK" echo "Secondary 3_2 OK" echo "<-------------------------------->" sleep 2; #************************************************* # Fourth Replica set check #************************************************* echo "Checking replica set 4 status" until docker service ps mongo_primary4 --format '{{.CurrentState}}' do echo "Primary_4 Service not up yet" sleep 5; done & until docker service ps mongo_secondary4_1 --format '{{.CurrentState}}' do echo "secondary4_1 service not up yet" sleep 5; done until docker service ps mongo_secondary4_2 --format '{{.CurrentState}}' do echo "Secondary4_2 service not up yet" sleep 5; done sleep 2; echo "" echo "Primary 4 OK" echo "Secondary 4_1 OK" echo "Secondary 4_2 OK" echo "<-------------------------------->" sleep 2; #************************************************* # Check if databases are live #************************************************* echo "Checking Replica 1 Databases" until mongo --host 83.212.77.43:10001 --quiet --eval 'db' &> /dev/null && mongo --host 83.212.77.43:10002 --quiet --eval 'db' &> /dev/null && mongo --host 83.212.77.43:10003 --quiet --eval 'db' &> /dev/null do echo "Waiting for replica set 1 databases to come online" sleep 5; done echo " Replica set 1 databases up and running" echo "" echo "Checking Replica 2 Databases" until mongo --host 83.212.77.43:20001 --quiet --eval 'db' &> /dev/null && mongo --host 83.212.77.43:20002 --quiet --eval 'db' &> /dev/null && mongo --host 83.212.77.43:20003 --quiet --eval 'db' &> /dev/null do echo "Waiting for replica set 2 databases to come online" sleep 5; done echo " Replica set 2 databases up and running" echo "" echo "Checking Replica 3 Databases" until mongo --host 83.212.77.43:30001 --quiet --eval 'db' &> /dev/null && mongo --host 83.212.77.43:30002 --quiet --eval 'db' &> /dev/null && mongo --host 83.212.77.43:30003 --quiet --eval 'db' &> /dev/null do echo "Waiting for replica set 3 databases to come online" sleep 5; done echo " Replica set 3 databases up and running" echo "" echo "Checking Replica 4 Databases" until mongo --host 83.212.77.43:40001 --quiet --eval 'db' &> /dev/null && mongo --host 83.212.77.43:40002 --quiet --eval 'db' &> /dev/null && mongo --host 83.212.77.43:40003 --quiet --eval 'db' &> /dev/null do echo "Waiting for replica set 4 databases to come online" sleep 5; done echo " Replica set 4 databases up and running" sleep 2; #************************************************* # Connecting Secondary to Primary #************************************************* echo "All databases are up ....." echo "" echo "" echo "Connecting secondary replicas to primary..." mongo 83.212.77.43:10001 --quiet < rep_set1_members.js &> /dev/null mongo 83.212.77.43:10002 --quiet < slaveok.js &> /dev/null mongo 83.212.77.43:10003 --quiet < slaveok.js &> /dev/null sleep 2; echo "" echo "Replica set 1 OK" mongo 83.212.77.43:20001 --quiet < rep_set2_members.js &> /dev/null mongo 83.212.77.43:20002 --quiet < slaveok.js &> /dev/null mongo 83.212.77.43:20003 --quiet < slaveok.js &> /dev/null sleep 2; echo "" echo "Replica set 2 OK" mongo 83.212.77.43:30001 --quiet < rep_set3_members.js &> /dev/null mongo 83.212.77.43:30002 --quiet < slaveok.js &> /dev/null mongo 83.212.77.43:30003 < slaveok.js &> /dev/null sleep 2; echo "" echo "Replica set 3 OK" mongo 83.212.77.43:40001 --quiet < rep_set4_members.js &> /dev/null mongo 83.212.77.43:40002 --quiet < slaveok.js &> /dev/null mongo 83.212.77.43:40003 --quiet < slaveok.js &> /dev/null sleep 2; echo "" echo "Replica set 4 OK"