Created
July 24, 2013 23:34
-
-
Save bbg-deploy/6075612 to your computer and use it in GitHub Desktop.
example generic unicorn.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/unicorn.rb | |
worker_processes 4 | |
working_directory "/home/deploy/rails_apps/$app/current" | |
listen "/tmp/unicorn.sock", :backlog => 64 | |
timeout 30 | |
pid "/home/deploy/rails_apps/$app/shared/pids/unicorn.pid" | |
stderr_path "/home/deploy/rails_apps/$app/shared/log/unicorn.stderr.log" | |
stdout_path "/home/deploy/rails_apps/$app/shared/log/unicorn.stdout.log" | |
# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings | |
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow | |
GC.respond_to?(:copy_on_write_friendly=) and | |
GC.copy_on_write_friendly = true | |
before_fork do |server, worker| | |
# the following is highly recomended for Rails + "preload_app true" | |
# as there's no need for the master process to hold a connection | |
defined?(ActiveRecord::Base) and | |
ActiveRecord::Base.connection.disconnect! | |
old_pid = "#{server.config[:pid]}.oldbin" | |
# kill off the old master | |
if File.exists?(old_pid) && server.pid != old_pid | |
begin | |
Process.kill("QUIT", File.read(old_pid).to_i) | |
rescue Errno::ENOENT, Errno::ESRCH | |
# someone else did our job for us | |
end | |
end | |
end | |
after_fork do |server, worker| | |
# the following is *required* for Rails + "preload_app true", | |
defined?(ActiveRecord::Base) and | |
ActiveRecord::Base.establish_connection | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment