Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created January 7, 2013 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/4471840 to your computer and use it in GitHub Desktop.
Save komasaru/4471840 to your computer and use it in GitHub Desktop.
Configuration of unicorn on rails application.
# ワーカーの数
worker_processes 2
# RAILS_ROOT を指定
working_directory "/var/www/rails/rails_app/"
# ソケット
listen "/var/www/rails/rails_app/tmp/sockets/unicorn.sock"
# PID
pid "tmp/pids/unicorn.pid"
# ログ
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"
# ダウンタイムなくす
preload_app true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
old_pid = "#{ server.config[:pid] }.oldbin"
unless old_pid == server.pid
begin
Process.kill :QUIT, File.read(old_pid).to_i
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment