Sha256: 15ec8346d56462f55843b57644e1cc9b97d4eb3748a588250234ad7ba9d519b7

Contents?: true

Size: 1.89 KB

Versions: 18

Compression:

Stored size: 1.89 KB

Contents

##############################################
# Negorku Base Unicorn Configuration File
##############################################

# Load rails into the master before forking workers
# for super-fast worker spawn times
preload_app <%= fetch(:unicorn_preload) %>

working_directory "<%= "#{current_path}" %>"
pid "<%= fetch(:unicorn_pid) %>"
stderr_path "<%= "#{current_path}" %>/log/unicorn-error.log"
stdout_path "<%= "#{current_path}" %>/log/unicorn-out.log"

listen "<%= fetch(:unicorn_socket) %>"

worker_processes <%= fetch(:unicorn_workers) %>
timeout <%= fetch(:unicorn_workers_timeout) %>

# use correct Gemfile on restarts
before_exec do |server|
	ENV['BUNDLE_GEMFILE'] = "<%= "#{current_path}" %>/Gemfile"
end

before_fork do |server, worker|
  ##
  # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
  # immediately start loading up a new version of itself (loaded with a new
  # version of our app). When this new Unicorn is completely loaded
  # it will begin spawning workers. The first worker spawned will check to
  # see if an .oldbin pidfile exists. If so, this means we've just booted up
  # a new Unicorn and need to tell the old one that it can now die. To do so
  # we send it a QUIT.
  #
  # Using this method we get 0 downtime deploys.

  defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!

  old_pid = "<%= fetch(: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
      # someone else did our job for us
      puts "Old master already dead"
    end
  end
end

after_fork do |server, worker|
  ##
  # Unicorn master loads the app then forks off workers - because of the way
  # Unix forking works, we need to make sure we aren't using any of the parent's
  # sockets, e.g. db connection

  ActiveRecord::Base.establish_connection
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
negroku-2.8.6 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.8.5 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.8.4 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.8.3 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.8.2 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.8.1 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.8.0 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.7.1 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.7.0 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.6.0 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.5.5 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.5.4 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.5.3 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.5.2 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.5.1 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.5.0 lib/negroku/capistrano/templates/unicorn_rails_activerecord.rb.erb
negroku-2.4.2 lib/negroku/templates/tasks/unicorn_rails_activerecord.rb.erb
negroku-2.4.1 lib/negroku/templates/tasks/unicorn_rails_activerecord.rb.erb