Created
December 1, 2014 19:27
-
-
Save 8vius/6f724ccd940704568a86 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
env = ENV["RAILS_ENV"] || "development" | |
app_dir = "yummmie" | |
worker_processes 4 | |
# listen on both a Unix domain socket and a TCP port, | |
# we use a shorter backlog for quicker failover when busy | |
listen "/tmp/unicorn.#{app_dir}.socket", :backlog => 64 | |
# Preload our app for more speed | |
preload_app true | |
# nuke workers after 30 seconds instead of 60 seconds (the default) | |
timeout 60 | |
# Help ensure your application will always spawn in the symlinked | |
# "current" directory that Capistrano sets up. | |
working_directory "/home/deploy/apps/#{app_dir}/current" | |
# feel free to point this anywhere accessible on the filesystem | |
user 'deploy', 'deploy' | |
shared_path = "/home/deploy/apps/#{app_dir}/shared" | |
stderr_path "#{shared_path}/log/unicorn.stderr.log" | |
stdout_path "#{shared_path}/log/unicorn.stdout.log" | |
pid "#{shared_path}/tmp/pids/unicorn.pid" | |
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 | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.connection.disconnect! | |
end | |
# Before forking, kill the master process that belongs to the .oldbin PID. | |
# This enables 0 downtime deploys. | |
old_pid = "#{shared_path}/tmp/pids/unicorn.pid.oldbin" | |
if File.exists?(old_pid) && server.pid != old_pid | |
begin | |
Process.kill("USR2", 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", | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.establish_connection | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment