Skip to content

Instantly share code, notes, and snippets.

@danivovich
Created March 12, 2013 00:23
Show Gist options
  • Save danivovich/5139211 to your computer and use it in GitHub Desktop.
Save danivovich/5139211 to your computer and use it in GitHub Desktop.
Graceful restarts with code reloading on Capistrano style deployed Python applications
import os
import signal
bind = "127.0.0.1:8888"
errorlog = "%s/log/gunicorn.log" % (os.getcwd())
workers = 4
keepalive = 5
preload_app = True
def on_starting(server):
server.START_CTX['cwd'] = "/var/webapps/application/current"
def when_ready(server):
server.log.info("Master ready in %s" % os.getcwd())
# Quit the old unicorn process
old_pid = "/var/webapps/application/shared/pids/gunicorn.pid.oldbin"
if os.path.isfile(old_pid):
try:
pid = open(old_pid).read().split()[0]
os.kill(int(pid), signal.SIGQUIT)
except Exception as e:
server.log.exception("Error cleaning up %s" % e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment