Skip to content

Instantly share code, notes, and snippets.

@lucj
Created September 23, 2016 06:07
Show Gist options
  • Save lucj/34128d9cbf03d8941220a5664203083a to your computer and use it in GitHub Desktop.
Save lucj/34128d9cbf03d8941220a5664203083a to your computer and use it in GitHub Desktop.
configure-mongors.sh
# 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