Created
March 12, 2013 00:23
-
-
Save danivovich/5139211 to your computer and use it in GitHub Desktop.
Graceful restarts with code reloading on Capistrano style deployed Python applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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