Created
October 10, 2013 17:19
-
-
Save bobbywilson0/6922153 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
worker_processes 5 | |
user "deploy" | |
working_directory "/srv/www/meetfm/current" | |
listen "/srv/www/meetfm/shared/sockets/unicorn.sock", :backlog => 1024, :tcp_nodelay => tr | |
ue, :tcp_nopush => false, :tries => 5, :delay => 0.5, :accept_filter => "httpready" | |
timeout 60 | |
pid "/srv/www/meetfm/shared/pids/unicorn.pid" | |
stderr_path "/srv/www/meetfm/shared/log/unicorn.stderr.log" | |
stdout_path "/srv/www/meetfm/shared/log/unicorn.stdout.log" | |
# combine REE with "preload_app true" for memory savings | |
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow | |
preload_app true | |
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=) | |
# ensure Unicorn doesn't use a stale Gemfile when restarting | |
# more info: https://willj.net/2011/08/02/fixing-the-gemfile-not-found-bundlergemfilenotfo | |
und-error/ | |
before_exec do |server| | |
ENV['BUNDLE_GEMFILE'] = "/srv/www/meetfm/current/Gemfile" | |
end | |
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 = "/srv/www/meetfm/shared/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 | |
# 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 | |
Rails.cache.reconnect | |
# if preload_app is true, then you may also want to check and | |
# restart any other shared sockets/descriptors such as Memcached, | |
# and Redis. TokyoCabinet file handles are safe to reuse | |
# between any number of forked children (assuming your kernel | |
# correctly implements pread()/pwrite() system calls) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment