LoginSignup
12
13

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の設定をみてください。

12
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
13