Created
November 20, 2012 13:25
-
-
Save tycooon/4117920 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
working_directory "/srv/tutti/current" | |
pid "/srv/tutti/current/tmp/pids/unicorn.pid" | |
stderr_path "/srv/tutti/shared/log/unicorn.log" | |
stdout_path "/srv/tutti/shared/log/unicorn.log" | |
listen "/tmp/unicorn.tutti.sock" | |
worker_processes 2 | |
timeout 30 | |
preload_app true | |
before_fork do |server, worker| | |
# Disconnect since the database connection will not carry over | |
if defined? ActiveRecord::Base | |
ActiveRecord::Base.connection.disconnect! | |
end | |
# Quit the old unicorn process | |
old_pid = "#{server.config[: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| | |
# Start up the database connection again in the worker | |
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