Created
August 22, 2014 19:12
-
-
Save pablitoc/22a56736931c548f2667 to your computer and use it in GitHub Desktop.
Unicorn Config
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
require 'dotenv' | |
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3) | |
timeout 15 | |
preload_app true | |
stderr_path "/srv/#{application}/shared/log/"ENV['RAILS_ENV']".log" | |
stdout_path "/srv/#{application}/shared/log/"ENV['RAILS_ENV']".log" | |
pid "/srv/#{application}/shared/tmp/pids/#{application}.pid" | |
before_fork do |server, worker| | |
f = File.open("#{server.config[:pid]}.lock", 'w') | |
exit unless f.flock(File::LOCK_SH) | |
Signal.trap 'TERM' do | |
puts 'Unicorn master intercepting TERM and sending myself QUIT instead' | |
Process.kill 'QUIT', Process.pid | |
end | |
end | |
after_fork do |server, worker| | |
Signal.trap 'TERM' do | |
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' | |
end | |
end |
I was thinking with the app, but if we deploy via Ansible then I can make a role out of it and use the jinja2 variable syntax and get rid of the #{application}
. Just looking into options so that we do not need to keep changing the unicorn config.
Ok, how about something like this then? It would be ideal if we could keep this in the app repo (just like sidekiq.yml) because it's easier to make changes if need-be. Consider this a rough-draft...
require 'dotenv'
worker_processes Integer(ENV['UNICORN_CONCURRENCY'] || 3)
timeout Integer(ENV['UNICORN_TIMEOUT'] || 15)
preload_app true
stderr_path ENV['UNICORN_LOG'] if ENV['UNICORN_LOG']
stdout_path ENV['UNICORN_LOG'] if ENV['UNICORN_LOG']
pid ENV['UNICORN_LOG'] if ENV['UNICORN_PID']
before_fork do |server, worker|
if ENV['UNICORN_PID']
f = File.open("#{server.config[:pid]}.lock", 'w')
exit unless f.flock(File::LOCK_SH)
end
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
end
looks awesome. However, can you explain what
stderr_path ENV['UNICORN_LOG'] if ENV['UNICORN_LOG']
stdout_path ENV['UNICORN_LOG'] if ENV['UNICORN_LOG']
pid ENV['UNICORN_LOG'] if ENV['UNICORN_PID']
does? That is confusing to me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example with the variable definition. Have we ever tried loading
dotenv
like this?