Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
13
Help us understand the problem. What is going on with this article?
@townsoft

Unicorn設定完全版

More than 5 years have passed since last update.

タイトルは釣りです。すいません。

とりあえずunicornを設定しなければという人向け。

何もわからない人は以下のファイルを配置すれば、Unicornを起動できます。

rails_root/config/unicron.rb
rails_root = File.expand_path('../../', __FILE__)

worker_processes 2
working_directory rails_root
timeout 10

ENV['BUNDLE_GEMFILE'] = rails_root + "/Gemfile"

stderr_path File.expand_path('../../log/unicorn_stderr.log', __FILE__)
stdout_path File.expand_path('../../log/unicorn_stdout.log', __FILE__)

listen File.expand_path('../../tmp/sockets/unicorn.sock', __FILE__)
pid File.expand_path('../../tmp/pids/unicorn.pid', __FILE__)

preload_app true
# GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true

# USR2シグナルを受けると古いプロセスを止める。
before_fork do |server, worker|
  defined?(ActiveRecord::Base) and
      ActiveRecord::Base.connection.disconnect!

  old_pid = "#{server.config[:pid]}.oldbin"
  if old_pid != server.pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, 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

必要に応じて以下の値を変えてください。

worker_processes 2
timeout 10

詳細を知りたい方はUnicornの設定をみてください。

13
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
townsoft
RailsやSwiftを使って、様々なアプリケーションを作ることが好きです。 それを生業にして仕事を請けてます。 HPより仕事の依頼も受けてますので、お気軽にご連絡ください。(条件によっては常駐開発も請け負います。)

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
13
Help us understand the problem. What is going on with this article?