Skip to content

Instantly share code, notes, and snippets.

Zero downtime deploys with gunicorn

Below are the actual files we use in one of our latest applications at Agora Games to achieve zero downtime deploys with gunicorn. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Salient points for each file:

  • gunicorn.py: The pre_fork function looks for gunicorn's old PID file in the proper file and sends the proper QUIT signal to the old process once the new process is running.
  • sv-gunicorn-run.jinja: This is the runit template we use in our Salt-managed infrastructure for handling the application process management. You could just as easily convert this to a non-templatized version.
#!/bin/bash
#
# This file is managed by Chef, using the <%= node.name %> cookbook.
# Editing this file by hand is highly discouraged!
#
# Copyright (c) 2014 Jean Mertz <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal

Zero downtime deploys with gunicorn

Below are the actual files we use in one of our latest applications at Agora Games to achieve zero downtime deploys with gunicorn. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Salient points for each file:

  • gunicorn.py: The pre_fork function looks for gunicorn's old PID file in the proper file and sends the proper QUIT signal to the old process once the new process is running.
  • sv-gunicorn-run.jinja: This is the runit template we use in our Salt-managed infrastructure for handling the application process management. You could just as easily convert this to a non-templatized version.
@inthecloud247
inthecloud247 / init.sls
Last active August 29, 2015 14:10 — forked from czarneckid/init.sls
# Setup the application's runit directory
/etc/sv/application:
file.directory:
- mode: 0755
- user: someuser
- group: someuser
- recurse:
- user
- group
- mode
#/bin/bash
archive=$1
if [ -z "$archive" ]; then
echo "No archive provided."
echo "Usage: $0 archive.tar"
exit
fi
#!/bin/sh
echo Install all AppStore Apps at first!
# no solution to automate AppStore installs
read -p "Press any key to continue... " -n1 -s
echo '\n'
# install wallpaper cli
sudo gem install desktop
echo Install Homebrew, Postgres, wget and cask
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
lang en_US
langsupport en_US
keyboard us
timezone Etc/UTC
text
install
skipx
halt
# Ridiculous URL... I know...
sudo apt-get update
sudo apt-get install -y libssl1.0.0 openssl
# Confirm Build Date is at least Aril 7th 2014
openssl version -a | grep built
# Restart all services listed by this command:
sudo lsof -n | grep ssl | grep DEL
FROM google/cloud-sdk
RUN apt-get update && apt-get install -y --no-install-recommends curl sshpass netcat-traditional
RUN curl https://get.docker.io/builds/Linux/x86_64/docker-latest -o /bin/docker && chmod +x /bin/docker
RUN curl http://stedolan.github.io/jq/download/linux64/jq -o /bin/jq && chmod +x /bin/jq
ADD gce2docker-fork.sh /
EXPOSE 44243
ENV DOCKER_HOST :44243
ENTRYPOINT ["/gce2docker-fork.sh"]
#!/usr/bin/python
# vim:ts=2:sw=2:expandtab
"""
A Python library to perform low-level Linode API functions.
Copyright (c) 2010 Timothy J Fontaine <[email protected]>
Copyright (c) 2010 Josh Wright <[email protected]>
Copyright (c) 2010 Ryan Tucker <[email protected]>
Copyright (c) 2008 James C Sinclair <[email protected]>