Skip to content

Instantly share code, notes, and snippets.

@benjamintanweihao
Created August 5, 2013 17:06
Show Gist options
  • Select an option

  • Save benjamintanweihao/6157580 to your computer and use it in GitHub Desktop.

Select an option

Save benjamintanweihao/6157580 to your computer and use it in GitHub Desktop.
require "redis"
root = "/home/deployer/apps/qs/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.qs.sock"
worker_processes 7
timeout 30
preload_app true
# TODO: Remove when doen with this.
ENV.each{ |k, v| puts "#{k}:::#{v}" }
before_exec do |_|
ENV["RUBY_HEAP_MIN_SLOTS"] = 500000
ENV["RUBY_GC_MALLOC_LIMIT"] = 50000000
ENV["RUBY_HEAP_SLOTS_INCREMENT"] = 250000
ENV["RUBY_HEAP_SLOTS_GROWTH_FACTOR"] = 1
ENV["RUBY_HEAP_FREE_MIN"] = 100000
ENV["BUNDLE_GEMFILE"] = '/home/deployer/apps/qs/current/Gemfile'
end
before_fork do |server, worker|
# Disconnect since the database connection will not carry over
if defined? ActiveRecord::Base
ActiveRecord::Base.connection.disconnect!
end
# Quit the old unicorn process
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|
# Start up the database connection again in the worker
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
Redis.current.quit
Rails.cache.reconnect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment