Created
March 7, 2014 21:44
-
-
Save guivinicius/9420832 to your computer and use it in GitHub Desktop.
unicorn.rb example with redis
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
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete | |
# documentation. | |
worker_processes <%= fetch(:unicorn_workers) %> | |
listen "/tmp/unicorn.<%= fetch(:application) %>.sock", :backlog => 64 | |
# listen 8080, :tcp_nopush => true | |
# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings | |
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow | |
preload_app true | |
GC.respond_to?(:copy_on_write_friendly=) and | |
GC.copy_on_write_friendly = true | |
timeout 30 | |
pid "<%= fetch(:unicorn_pid) %>" | |
check_client_connection false | |
working_directory "<%= current_path %>" | |
user 'rails', 'admin' | |
stderr_path "<%= fetch(:unicorn_log) %>" | |
stdout_path "<%= fetch(:unicorn_log) %>" | |
before_fork do |server, worker| | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.connection.disconnect! | |
end | |
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 | |
sleep 1 | |
end | |
after_fork do |server, worker| | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.establish_connection | |
end | |
child_pid = server.config[:pid].sub(".pid", ".#{worker.nr}.pid") | |
system("echo #{Process.pid} > #{child_pid}") | |
Sidekiq.configure_client do |config| | |
config.redis = { :size => 1 } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment