Skip to content

Instantly share code, notes, and snippets.

@bcarpio
Created March 27, 2012 21:41
Show Gist options
  • Save bcarpio/2220611 to your computer and use it in GitHub Desktop.
Save bcarpio/2220611 to your computer and use it in GitHub Desktop.
Fabric MongoDB Rolling Upgrade Task
@task
def rolling_upgrade(hostname):
""" Rolling upgrade of mongodb """
users.root()
conn = Connection('%s'%(hostname))
db = conn.admin
replSet = db.command("replSetGetStatus")
for secondary in replSet['members']:
stateStr = str(secondary['stateStr'])
host = str(secondary['name'])
health = str(secondary['health'])
if stateStr == 'SECONDARY':
execute(puppet.puppetd_test, host='%s' %(host))
execute(mongod.restart, host='%s' %(host))
while health != '1.0':
time.sleep(10)
print health
for primary in replSet['members']:
stateStr = str(primary['stateStr'])
host = str(primary['name'])
health = str(primary['health'])
if stateStr == 'PRIMARY':
execute(mongod.stop, host='%s' %(host))
execute(puppet.puppetd_test, host='%s' %(host))
execute(mongod.start, host='%s' %(host))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment