Skip to content

Instantly share code, notes, and snippets.

@strikeout
Created October 8, 2015 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strikeout/353bcc6a10d2320d50c4 to your computer and use it in GitHub Desktop.
Save strikeout/353bcc6a10d2320d50c4 to your computer and use it in GitHub Desktop.
Adds own host to a mongo replica-set. Runs on server-startup
#!/usr/bin/env bash
#get own hostname
ME=$(hostname);
# find replica-set master, we think its the first in the array
MASTER=`mongo --quiet --eval "cfg=rs.config(); print( cfg.members[0].host );"`
# connect to master, add ME
mongo --host $MASTER --eval "print( rs.add('"$ME"') );"
# make ME queryable
mongo --eval "rs.slaveOk();"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment