Skip to content

Instantly share code, notes, and snippets.

View czarneckid's full-sized avatar

David Czarnecki czarneckid

View GitHub Profile
@czarneckid
czarneckid / Zero downtime deploys with gunicorn.markdown
Last active August 31, 2016 17:42
Zero downtime deploys with gunicorn

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.
class Fish
def 🔪
puts "🍣"
end
end
🐟 = Fish.new
🐟.🔪
@czarneckid
czarneckid / redis_lua_eval.rb
Last active January 3, 2016 13:19
Redis, Lua and global functions Redis 2.8.3 redis-rb 3.0.6
require 'redis'
redis = Redis.new
redis.script(:flush)
redis.flushdb
hello_name_lua_script = <<-HELLO_NAME_LUA_SCRIPT
local function hello_name(name)
return("Hello " .. name)
end
{
"auto_complete": false,
"color_scheme": "Packages/Theme - itg.flat/itg.Monokai.tmTheme",
"detect_slow_plugins": false,
"file_exclude_patterns":
[
"*.pyc",
"*.pyo",
"*.exe",
"*.dll",
@czarneckid
czarneckid / Preferences.sublime-settings
Created December 16, 2013 17:51
Phoenix Dark with base16-bright theme
{
"auto_complete": false,
"color_scheme": "Packages/Base16 Color Schemes/base16-bright.dark.tmTheme",
"detect_slow_plugins": false,
"file_exclude_patterns":
[
"*.pyc",
"*.pyo",
"*.exe",
"*.dll",
@czarneckid
czarneckid / sample_controller.rb
Created December 5, 2013 21:59
UITextView and horizontal scrolling?
class SampleController < UIViewController
def viewDidLoad
super
self.view.backgroundColor = UIColor.whiteColor
@text_view = UITextView.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
@text_view.text = sample_text
@text_view.editable = false
@text_view.showsHorizontalScrollIndicator = true
@czarneckid
czarneckid / init.sls
Created October 10, 2013 00:25
SaltStack application runit configuration
# Setup the application's runit directory
/etc/sv/application:
file.directory:
- mode: 0755
- user: someuser
- group: someuser
- recurse:
- user
- group
- mode
@czarneckid
czarneckid / gist:6524608
Created September 11, 2013 14:41
Ruby Attr Antipattern timing
class Demo
def initialize(something)
@something = something
end
def based_on_something
@something * 2
end
end
@czarneckid
czarneckid / Rails 4 Upgrade Notes.md
Created August 28, 2013 05:05
Rails 4 Upgrade Notes

Rails 4 Upgrade Notes

I recently completed our upgrade to Rails 4. Below are various notes and links that may help you if you are upgrading your application to Rails 4. YMMV.

Overview

There is a good Rails Guide on upgrading, with a specific section on upgrading from Rails 3.2 to Rails 4.0. First, a bit about our specific application and the technologies used, pre-Rails 4 upgrade:

  • Rails 3.2.14
  • Ruby 2.0.0-p247

Zero downtime deploys with unicorn + nginx + runit + rvm + chef

Below are the actual files we use in one of our latest production applications at Agora Games to achieve zero downtime deploys with unicorn. You've probably already read the GitHub blog post on Unicorn and would like to try zero downtime deploys for your application. 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).

Other application notes:

  • Our application uses MongoDB, so we don't have database migrations to worry about as with MySQL or postgresql. That does not mean that we won't have to worry about issues with the database with indexes being built in MongoDB or what have you.
  • We use capistrano for deployment.

Salient points for each file: