-
-
Save sr75/3873017 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
# 4 workers is enough for our app | |
worker_processes 4 | |
# App location | |
@app = "/var/rails/myapp/current" | |
# Listen on fs socket for better performance | |
listen "#{@app}/tmp/sockets/unicorn.sock", :backlog => 64 | |
# Nuke workers after 30 seconds instead of 60 seconds (the default) | |
timeout 30 | |
# App PID | |
pid "#{@app}/tmp/pids/unicorn.pid" | |
# By default, the Unicorn logger will write to stderr. | |
# Additionally, some applications/frameworks log to stderr or stdout, | |
# so prevent them from going to /dev/null when daemonized here: | |
stderr_path "#{@app}/log/unicorn.stderr.log" | |
stdout_path "#{@app}/log/unicorn.stdout.log" | |
# To save some memory and improve performance | |
preload_app true | |
GC.respond_to?(:copy_on_write_friendly=) and | |
GC.copy_on_write_friendly = true | |
# Force the bundler gemfile environment variable to | |
# reference the capistrano "current" symlink | |
before_exec do |_| | |
ENV["BUNDLE_GEMFILE"] = File.join(@app, 'Gemfile') | |
end | |
before_fork do |server, worker| | |
# the following is highly recomended for Rails + "preload_app true" | |
# as there's no need for the master process to hold a connection | |
defined?(ActiveRecord::Base) and | |
ActiveRecord::Base.connection.disconnect! | |
end | |
after_fork do |server, worker| | |
# the following is *required* for Rails + "preload_app true", | |
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