Skip to content

Commit

Permalink
use unicorn over thin
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj Singh committed Dec 9, 2014
1 parent bef21c3 commit e6aed88
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ gem 'pg'
# for building JSON
gem 'jbuilder', '~> 1.2'

# ruby web server
gem 'thin'
# HTTP server for Rack applications
gem 'unicorn'

# without this in development webrick is used
gem "unicorn-rails"

# for authentication
gem 'devise', '3.2.3'
Expand Down
18 changes: 11 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.8.0)
daemons (1.1.9)
delayed_job (4.0.2)
activesupport (>= 3.0, < 4.2)
delayed_job_active_record (4.0.1)
Expand All @@ -100,7 +99,6 @@ GEM
email_validator (1.4.0)
activemodel
erubis (2.7.0)
eventmachine (1.0.3)
execjs (2.2.1)
formtastic (2.3.0.rc3)
actionpack (>= 3.0)
Expand Down Expand Up @@ -136,6 +134,7 @@ GEM
kaminari (0.16.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
kgio (2.9.2)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
Expand Down Expand Up @@ -177,6 +176,7 @@ GEM
activesupport (= 4.1.8)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
raindrops (0.13.0)
rake (10.3.2)
ransack (1.2.3)
actionpack (>= 3.0)
Expand Down Expand Up @@ -210,10 +210,6 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
thin (1.6.2)
daemons (>= 1.0.9)
eventmachine (>= 1.0.0)
rack (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
Expand All @@ -227,6 +223,13 @@ GEM
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
unicorn (4.8.2)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
unicorn-rails (2.2.0)
rack
unicorn
warden (1.2.3)
rack (>= 1.0)

Expand Down Expand Up @@ -258,6 +261,7 @@ DEPENDENCIES
simplecov
spring
sprockets-rails (~> 2.0)
thin
twitter-bootstrap-rails
uglifier (>= 1.0.3)
unicorn
unicorn-rails
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
27 changes: 27 additions & 0 deletions config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# this template has been picked up from
# https://devcenter.heroku.com/articles/rails-unicorn

worker_processes Integer(ENV["WEB_CONCURRENCY"] || 2)

# 30 seconds is the timeout for heroku. If it is not
# deployed on heroku then it can be bumped up.
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 send QUIT'
end

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

0 comments on commit e6aed88

Please sign in to comment.