Skip to content

Commit

Permalink
Usando unicorn como server
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Bueno committed Jun 24, 2013
1 parent 123c7ff commit c783c32
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -25,3 +25,6 @@ gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'


gem 'unicorn'
7 changes: 7 additions & 0 deletions Gemfile.lock
Expand Up @@ -46,6 +46,7 @@ GEM
jquery-rails (3.0.1)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
kgio (2.8.0)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
Expand All @@ -69,6 +70,7 @@ GEM
activesupport (= 4.0.0.rc2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
raindrops (0.11.0)
rake (10.0.4)
sass (3.2.9)
sass-rails (4.0.0.rc2)
Expand Down Expand Up @@ -106,6 +108,10 @@ GEM
uglifier (2.1.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
unicorn (4.6.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)

PLATFORMS
ruby
Expand All @@ -119,3 +125,4 @@ DEPENDENCIES
slim-rails
turbolinks
uglifier (>= 1.3.0)
unicorn
1 change: 1 addition & 0 deletions Procfile
@@ -0,0 +1 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
23 changes: 23 additions & 0 deletions config/unicorn.rb
@@ -0,0 +1,23 @@
# config/unicorn.rb
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

0 comments on commit c783c32

Please sign in to comment.