Skip to content

Instantly share code, notes, and snippets.

@wnoguchi
Created November 15, 2012 00:59
Show Gist options
  • Save wnoguchi/4075953 to your computer and use it in GitHub Desktop.
Save wnoguchi/4075953 to your computer and use it in GitHub Desktop.
unicorn configuration
# coding: utf-8
# Wataru Noguchi <wnoguchi@unicast.ne.jp>
application = 'app-name'
#listen "/tmp/unicorn_#{application}.sock"
listen 4000
pid "/tmp/unicorn_#{application}.pid"
worker_processes 6
#================================================================================
# Capistranoデプロイを使う場合
#================================================================================
working_directory "/home/yuichi/work/#{application}/src"
if ENV['RAILS_ENV'] == 'production'
shared_path = "/home/admin/apps/#{application}/shared"
stderr_path = "#{shared_path}/log/unicorn.stderr.log"
stdout_path = "#{shared_path}/log/unicorn.stdout.log"
end
#================================================================================
# ログ
#================================================================================
# stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
# stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
#================================================================================
# ダウンタイムなくす
#================================================================================
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
#================================================================================
# 動かし方
#================================================================================
# 1. gem "unicorn" を追加してbundle install
# 2. config/unicorn.rbを作成(このファイル!)
# 3. unicorn_rails -c config/unicorn.rb -E development -D
# -c 設定ファイルの指定
# -E rails動作モード
# -D デーモンとして動作(ない場合は、フォアグラウンドで動作する。)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment