Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created June 12, 2012 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tobiashm/2916821 to your computer and use it in GitHub Desktop.
Save tobiashm/2916821 to your computer and use it in GitHub Desktop.
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
@jesperronn
Copy link

Thanks! Just what i needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment