Skip to content

Instantly share code, notes, and snippets.

@raffone
Created August 14, 2013 10:13
Show Gist options
  • Save raffone/6229715 to your computer and use it in GitHub Desktop.
Save raffone/6229715 to your computer and use it in GitHub Desktop.
# unicorn_rails -c /var/www/public/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
worker_processes 2
APP_PATH = "/var/www/public"
working_directory APP_PATH
# This loads the application in the master process before forking
# worker processes
# Read more about it here:
# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true
timeout 30
# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
listen "/tmp/.unicorn.sock", :backlog => 2048
pid APP_PATH + "/tmp/pids/unicorn.pid"
# Set the path of the log files inside the log folder of the testapp
stderr_path APP_PATH + "/log/unicorn.stderr.log"
stdout_path APP_PATH + "/log/unicorn.stdout.log"
before_fork do |server, worker|
# This option works in together with preload_app true setting
# What is does is prevent the master process from holding
# the database connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
# Here we are establishing the connection after forking worker
# processes
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment