Created
September 23, 2016 06:07
-
-
Save lucj/34128d9cbf03d8941220a5664203083a to your computer and use it in GitHub Desktop.
configure-mongors.sh
This file contains 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
# Make sure 3 replicas available | |
for rs in rs1 rs2 rs3;do | |
mongo --host $rs --eval 'db' | |
if [ $? -ne 0 ]; then | |
exit 1 | |
fi | |
done | |
# Connect to rs1 and check is replicaset already configured with 3 nodes | |
status=$(mongo --host rs1 --quiet --eval 'rs.status().members.length') | |
if [ $? -ne 0 ]; then | |
# Replicaset not yet configured | |
mongo --host rs1 --eval 'rs.initiate()'; | |
mongo --host rs1 --eval 'rs.conf()'; | |
mongo --host rs1 --eval 'rs.add("rs2")'; | |
mongo --host rs1 --eval 'rs.add("rs3")'; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment