Created
June 28, 2018 07:33
-
-
Save anoobbava/cb5b1fa5a71f73a204a6c51ea1e03c08 to your computer and use it in GitHub Desktop.
put this file in the config/unicorn.rb used for blog don't delete
This file contains 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
# encoding: utf-8 | |
# Set your full path to application. | |
app_dir = File.expand_path('../../', __FILE__) | |
shared_dir = File.expand_path('../../../shared/', __FILE__) | |
# Set unicorn options | |
worker_processes 2 | |
preload_app true | |
timeout 30 | |
# Fill path to your app | |
working_directory app_dir | |
# Set up socket location | |
listen "#{shared_dir}/sockets/unicorn.sock", backlog: 64 | |
# Loging | |
stderr_path "#{shared_dir}/log/unicorn.stderr.log" | |
stdout_path "#{shared_dir}/log/unicorn.stdout.log" | |
# Set master PID location | |
pid "#{shared_dir}/pids/unicorn.pid" | |
before_fork do |server, worker| | |
defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect! | |
old_pid = "#{server.config[:pid]}.oldbin" | |
if File.exists?(old_pid) && server.pid != old_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 | |
# someone else did our job for us | |
end | |
end | |
end | |
after_fork do |server, worker| | |
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection | |
end | |
before_exec do |server| | |
ENV['BUNDLE_GEMFILE'] = "#{app_dir}/Gemfile" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment