Created
June 12, 2012 10:37
-
-
Save tobiashm/2916821 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
APP_PATH = File.expand_path('../..', __FILE__) | |
require File.join(APP_PATH, "lib/site") | |
working_directory APP_PATH | |
pid_path = File.join(APP_PATH, "tmp/pids/web.pid") | |
pid pid_path | |
stderr_path File.join(APP_PATH, "log/unicorn-stderr") | |
stdout_path File.join(APP_PATH, "log/unicorn-stdout") | |
worker_processes ENV['RAILS_ENV'] == 'production' ? 4 : 1 | |
listen Site.current.http_port, :tcp_nopush => true | |
preload_app true | |
before_fork do |server, worker| | |
ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base) | |
ENV['BUNDLE_GEMFILE'] = File.join(APP_PATH, "Gemfile") | |
old_pid_file = "#{pid_path}.oldbin" | |
old_pid = File.exists?(old_pid_file) && File.read(old_pid_file).to_i | |
if old_pid && server.pid != old_pid | |
puts "Killing old unicorn with PID #{old_pid}..." | |
begin | |
Process.kill("QUIT", old_pid) | |
rescue Errno::ENOENT, Errno::ESRCH | |
# someone else did our job for us | |
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
Thanks! Just what i needed :)