Last active
May 19, 2018 06:15
-
-
Save nikukyugamer/48be8f1ccb32fb85ba5e0cec757c8d2c to your computer and use it in GitHub Desktop.
unicorn.rb with Capistrano
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://github.com/tablexi/capistrano3-unicorn/blob/master/examples/unicorn.rb | |
| worker_processes 2 | |
| listen 12345 | |
| before_exec do |server| | |
| ENV['BUNDLE_GEMFILE'] = '/var/tmp/foobar/current/Gemfile' | |
| end | |
| shared_path = '/var/tmp/foobar/shared' | |
| pid File.expand_path('tmp/unicorn.pid', shared_path) | |
| listen File.expand_path('tmp/unicorn.sock', shared_path) | |
| stderr_path File.expand_path('log/foobar_unicorn_stderr.log', shared_path) | |
| stdout_path File.expand_path('log/foobar_unicorn_stdout.log', shared_path) | |
| preload_app true # ダウンタイムをなしにする | |
| before_fork do |server, worker| | |
| defined?(ActiveRecord::Base) and | |
| ActiveRecord::Base.connection.disconnect! | |
| old_pid = "#{server.config[:pid]}.oldbin" | |
| if File.exists?(old_pid) && server.pid != old_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