Created
October 10, 2018 12:11
-
-
Save Bertrand/871bc3419abf5e6ec922e96392a8d262 to your computer and use it in GitHub Desktop.
scripts/setup.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mongodb1=`getent hosts ${MONGO1} | awk '{ print $1 }'` | |
mongodb2=`getent hosts ${MONGO2} | awk '{ print $1 }'` | |
mongodb3=`getent hosts ${MONGO3} | awk '{ print $1 }'` | |
port=${PORT:-27017} | |
echo "Waiting for startup.." | |
until mongo --host mongo:27017 --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do | |
printf '.' | |
sleep 1 | |
done | |
until mongo --host mongo2:27018 --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do | |
printf '.' | |
sleep 1 | |
done | |
until mongo --host mongo3:27019 --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do | |
printf '.' | |
sleep 1 | |
done | |
echo "Started.." | |
echo setup.sh time now: `date +"%T" ` | |
mongo --host ${mongodb1}:${port} <<EOF | |
var cfg = { | |
"_id": "${RS}", | |
"members": [ | |
{ | |
"_id": 0, | |
"host": "mongo:27017" | |
}, | |
{ | |
"_id": 1, | |
"host": "mongo2:27018" | |
}, | |
{ | |
"_id": 2, | |
"host": "mongo3:27019" | |
} | |
] | |
}; | |
rs.initiate(cfg, { force: true }); | |
rs.reconfig(cfg, { force: true }); | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment