Last active
August 29, 2015 13:55
-
-
Save koko1000ban/8701520 to your computer and use it in GitHub Desktop.
unicorn config example
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
APP_ROOT = "/home/developer/exchanger/current" | |
before_exec do |server| | |
# Fixing gemfile not found error | |
# stop, startしてる場合は不要 | |
# USR2 -> WINCH -> QUITで無停止でrestartしてる場合は必要 | |
ENV['BUNDLE_GEMFILE'] = "#{APP_ROOT}/Gemfile" | |
end | |
before_fork do |server, worker| | |
begin | |
defined?(ActiveRecord::Base) and | |
ActiveRecord::Base.connection.disconnect! | |
rescue Exception => ex | |
warn "error occured at before_fork worker nr:#{worker.nr} : #{ex.inspect}" | |
warn ex.backtrace.join("\n") | |
end | |
# 公式より | |
# Throttle the master from forking too quickly by sleeping. Due | |
# to the implementation of standard Unix signal handlers, this | |
# helps (but does not completely) prevent identical, repeated signals | |
# from being lost when the receiving process is busy. | |
sleep 1 | |
end | |
after_fork do |server, worker| | |
# 公式より | |
# if preload_app is true, then you may also want to check and | |
# restart any other shared sockets/descriptors such as Memcached, | |
# and Redis. TokyoCabinet file handles are safe to reuse | |
# between any number of forked children (assuming your kernel | |
# correctly implements pread()/pwrite() system calls) | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.establish_connection(Rails.application.config.database_configuration[Rails.env]) | |
if ActiveRecord::Base.respond_to? :connection_proxy | |
ActiveRecord::Base.connection_proxy.instance_variable_get(:@shards).each { |k, v| v.clear_reloadable_connections! } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment