Skip to content

Commit

Permalink
Use Unicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Pundsack committed Feb 8, 2014
1 parent 225851a commit 4ded88f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ruby '2.1.0'
gem 'rails', '4.0.2'

gem 'rails_12factor', group: :production
gem 'unicorn'

# Use postgresql as the database for Active Record
gem 'pg'
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ GEM
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
kgio (2.9.1)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
Expand Down Expand Up @@ -75,6 +76,7 @@ GEM
activesupport (= 4.0.2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
raindrops (0.12.0)
rake (10.1.1)
rdoc (4.1.1)
json (~> 1.4)
Expand Down Expand Up @@ -108,6 +110,10 @@ GEM
uglifier (2.4.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
unicorn (4.8.2)
kgio (~> 2.6)
rack
raindrops (~> 0.7)

PLATFORMS
ruby
Expand All @@ -123,3 +129,4 @@ DEPENDENCIES
sdoc
turbolinks
uglifier (>= 1.3.0)
unicorn
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
25 changes: 25 additions & 0 deletions config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# config/unicorn.rb
worker_processes 3
timeout 30
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 sent QUIT'
end

defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end

0 comments on commit 4ded88f

Please sign in to comment.