Skip to content

Instantly share code, notes, and snippets.

@dukebody
Created October 28, 2015 11:14
Show Gist options
  • Save dukebody/dc64c128c823f5349254 to your computer and use it in GitHub Desktop.
Save dukebody/dc64c128c823f5349254 to your computer and use it in GitHub Desktop.
Fabric task to restart gunicorn without downtime, killing workers sequentially, sleeping in between to let new ones get ready.
@task
def reloadapp(sleep=5):
"""
Reloads lead-ratings app and the celery workers.
"""
supervisorctl = os.path.join(env.venv_path, 'bin', 'supervisorctl')
# kill all gunicorn master children, sleeping in between
master_pid = run('sudo %s pid app' % supervisorctl)
children = run('pgrep -P %s' % master_pid).split('\r\n')
for child in children:
time.sleep(sleep)
run('kill %s' % child)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment