[from now] 2014/10/23 20:35:31

diff --git a/Gemfile b/Gemfile
index a8b1309..15f6e66 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,10 +1,7 @@
 source 'https://rubygems.org'

-
 # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
 gem 'rails', '4.1.6'
-# Use sqlite3 as the database for Active Record
-gem 'sqlite3'
 # Use SCSS for stylesheets
 gem 'sass-rails', '~> 4.0.3'
 # Use Uglifier as compressor for JavaScript assets
@@ -30,7 +27,7 @@ gem 'spring',        group: :development
 # gem 'bcrypt', '~> 3.1.7'

 # Use unicorn as the app server
-# gem 'unicorn'
+gem 'unicorn'

 # Use Capistrano for deployment
 # gem 'capistrano-rails', group: :development
@@ -38,6 +35,16 @@ gem 'spring',        group: :development
 # Use debugger
 # gem 'debugger', group: [:development, :test]

+group :production do
+  gem 'rails_12factor'
+  gem 'pg'
+  gem 'therubyracer-heroku'
+end
+
+group :development, :test do
+  gem 'sqlite3'
+end
+
 group :doc do
   gem 'yard', require: false
 end
diff --git a/Gemfile.lock b/Gemfile.lock
index 92c14bf..34a0b8a 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -47,11 +47,13 @@ GEM
       railties (>= 3.0, < 5.0)
       thor (>= 0.14, < 2.0)
     json (1.8.1)
+    kgio (2.9.2)
     mail (2.6.1)
       mime-types (>= 1.16, < 3)
     mime-types (2.4.3)
     minitest (5.4.2)
     multi_json (1.10.1)
+    pg (0.17.1)
     rack (1.5.2)
     rack-test (0.6.2)
       rack (>= 1.0)
@@ -65,11 +67,17 @@ GEM
       bundler (>= 1.3.0, < 2.0)
       railties (= 4.1.6)
       sprockets-rails (~> 2.0)
+    rails_12factor (0.0.3)
+      rails_serve_static_assets
+      rails_stdout_logging
+    rails_serve_static_assets (0.0.2)
+    rails_stdout_logging (0.0.3)
     railties (4.1.6)
       actionpack (= 4.1.6)
       activesupport (= 4.1.6)
       rake (>= 0.8.7)
       thor (>= 0.18.1, < 2.0)
+    raindrops (0.13.0)
     rake (10.3.2)
     rdoc (4.1.2)
       json (~> 1.4)
@@ -93,6 +101,7 @@ GEM
       activesupport (>= 3.0)
       sprockets (>= 2.8, < 4.0)
     sqlite3 (1.3.9)
+    therubyracer-heroku (0.8.1.pre3)
     thor (0.19.1)
     thread_safe (0.3.4)
     tilt (1.4.1)
@@ -103,6 +112,10 @@ GEM
     uglifier (2.5.3)
       execjs (>= 0.3.0)
       json (>= 1.8.0)
+    unicorn (4.8.3)
+      kgio (~> 2.6)
+      rack
+      raindrops (~> 0.7)
     yard (0.8.7.4)

 PLATFORMS
@@ -112,11 +125,15 @@ DEPENDENCIES
   coffee-rails (~> 4.0.0)
   jbuilder (~> 2.0)
   jquery-rails
+  pg
   rails (= 4.1.6)
+  rails_12factor
   sass-rails (~> 4.0.3)
   sdoc (~> 0.4.0)
   spring
   sqlite3
+  therubyracer-heroku
   turbolinks
   uglifier (>= 1.3.0)
+  unicorn
   yard
diff --git a/Procfile b/Procfile
new file mode 100644
index 0000000..9c82374
--- /dev/null
+++ b/Procfile
@@ -0,0 +1 @@
+web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
diff --git a/config/unicorn.rb b/config/unicorn.rb
new file mode 100644
index 0000000..f6e59b8
--- /dev/null
+++ b/config/unicorn.rb
@@ -0,0 +1,22 @@
+worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
+timeout 15
+preload_app true
+
+before_fork do |server, worker|
+  Signal.trap 'TERM' do
+    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
+    Process.kill 'QUIT', Process.pid
+  end
+
+  defined?(ActiveRecord::Base) and
+    ActiveRecord::Base.connection.disconnect!
+end
+
+after_fork do |server, worker|
+  Signal.trap 'TERM' do
+    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
+  end
+
+  defined?(ActiveRecord::Base) and
+    ActiveRecord::Base.establish_connection
+end