Created
July 20, 2011 13:27
-
-
Save timothyklim/1094944 to your computer and use it in GitHub Desktop.
unicorn.rb
This file contains 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 = File.expand_path(File.dirname(File.dirname(__FILE__))) | |
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm') | |
begin | |
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME'])) | |
rvm_lib_path = File.join(rvm_path, 'lib') | |
$LOAD_PATH.unshift rvm_lib_path | |
require 'rvm' | |
RVM.use_from_path! APP_ROOT | |
rescue LoadError | |
raise "RVM ruby lib is currently unavailable." | |
end | |
end | |
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__)) | |
worker_processes 4 | |
working_directory APP_ROOT | |
preload_app true | |
timeout 30 | |
listen APP_ROOT + "/tmp/sockets/unicorn.sock", :backlog => 64 | |
pid APP_ROOT + "/tmp/pids/unicorn.pid" | |
stderr_path APP_ROOT + "/log/unicorn.stderr.log" | |
stdout_path APP_ROOT + "/log/unicorn.stdout.log" | |
before_fork do |server, worker| | |
defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect! | |
old_pid = RAILS_ROOT + '/tmp/pids/unicorn.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 | |
puts "Old master alerady dead" | |
end | |
end | |
end | |
after_fork do |server, worker| | |
require File.expand_path('../initializers/ms_sql', __FILE__) if defined?(ActiveRecord::Base) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment