Created
February 12, 2013 02:48
-
-
Save markottaviani/4759821 to your computer and use it in GitHub Desktop.
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
# This file has been generated from unicorn_template.rb.erb which is greatly inspired from: | |
# https://github.com/ricodigo/ricodigo-capistrano-recipes/blob/master/generators/unicorn.rb.erb | |
# | |
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete | |
# documentation. | |
# Local variables | |
old_pid = '/var/www/rescuerails/shared/pids/unicorn.pid.old' | |
# Unicorn setup | |
worker_processes 2 | |
timeout 30 | |
# Listen on a Unix data socket | |
listen '/var/www/rescuerails/shared/sockets/unicorn.sock', :backlog => 1024 | |
pid '/var/www/rescuerails/shared/pids/unicorn.pid' | |
user 'unicorn', 'unicorn' | |
# Help ensure your application will always spawn in the symlinked | |
# "current" directory that Capistrano sets up. | |
working_directory '/var/www/rescuerails/current' | |
stderr_path '/var/www/rescuerails/shared/log/unicorn.stderr.log' | |
stdout_path '/var/www/rescuerails/shared/log/unicorn.stdout.log' | |
preload_app 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 | |
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 = "/tmp/unicorn.my_site.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 | |
# 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