Last active
December 29, 2015 08:29
-
-
Save dobs/7644186 to your computer and use it in GitHub Desktop.
Example Unicorn config
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
rails_env = ENV['RAILS_ENV'] || 'production' | |
rails_root = `pwd`.gsub("\n", "") | |
rails_user = ENV['RAILS_USER'] || 'rails' | |
rails_group = ENV['RAILS_GROUP'] || 'group' | |
unless rails_env == 'production' | |
listen '127.0.0.1:8080' | |
else | |
listen "#{rails_root}/tmp/sockets/unicorn.sock", backlog: 64 | |
end | |
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 4) | |
timeout 15 | |
preload_app true | |
pid "#{rails_root}/tmp/pids/unicorn.pid" | |
stderr_path "#{rails_root}/log/unicorn.log" | |
stdout_path "#{rails_root}/log/unicorn.log" | |
user(rails_user, rails_group) if rails_env == 'production' | |
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) | |
before_fork do |server, worker| | |
ActiveRecord::Base.connection.disconnect! if defined? ActiveRecord::Base | |
old_pid = "#{rails_root}/tmp/pids/unicorn.pid.oldbin" | |
if File.exists?(old_pid) && server.pid != old_pid | |
begin | |
Process.kill("QUIT", File.read(old_pid).to_i) | |
rescue Errno::ENOENT, Errno::ESRCH | |
# It's already deeeeaaaaad... | |
end | |
end | |
end | |
after_fork do |server, worker| | |
ActiveRecord::Base.establish_connection if defined? ActiveRecord::Base | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment