Created
August 25, 2012 00:35
-
-
Save cmer/3457954 to your computer and use it in GitHub Desktop.
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
# Set your full path to application. | |
app_path = "/Users/carl/Dropbox/code/web" # -> changed for development env | |
# Set unicorn options | |
worker_processes 20 | |
preload_app true | |
timeout 180 | |
listen 8080 #"/tmp/.unicorn.sock" -> changed for development env | |
# Spawn unicorn master worker for user apps (group: apps) | |
# user 'deploy', 'deploy' -> commented for development env | |
# Fill path to your app | |
working_directory app_path | |
raise ArgumentError.new("RAILS_ENV is not set.") unless ENV['RAILS_ENV'].to_s.size > 0 | |
rails_env = ENV['RAILS_ENV'] | |
# Log everything to one file | |
stderr_path "log/unicorn.log" | |
stdout_path "log/unicorn.log" | |
# Set master PID location | |
pid "#{app_path}/tmp/pids/unicorn.pid" | |
before_fork do |server, worker| | |
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 | |
# someone else did our job for us | |
end | |
end | |
end | |
after_fork do |server, worker| | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.establish_connection | |
end | |
# Reset Rails's object cache | |
# Only works with DalliStore | |
Rails.cache.reset if Rails.cache.respond_to? :reset | |
# Reset Rails's session store | |
# If you know a cleaner way to find the session store instance, please let me know | |
if defined?(ActionDispatch::Session::DalliStore) | |
ObjectSpace.each_object(ActionDispatch::Session::DalliStore) { |obj| obj.reset } | |
end | |
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