Sha256: 08652fe3cd8e7ebda28f923edef5da9871fd7a6dfcb849161b911ec4dcc8d307

Contents?: true

Size: 1.76 KB

Versions: 20

Compression:

Stored size: 1.76 KB

Contents

rails_root = '<%= "#{deploy_to}/current" %>'
rails_env  = '<%= environment %>'
pid_file   = '<%= unicorn_pid %>'
socket_file= '<%= unicorn_socket %>'
log_file   = "#{rails_root}/log/unicorn.log"
username   = '<%= unicorn_user %>'
group      = '<%= unicorn_group %>'
old_pid    = pid_file + '.oldbin'


timeout <%= unicorn_workers_timeout %>

worker_processes <%= unicorn_workers %>

# Listen on a Unix data socket
listen socket_file, :backlog => 1024
pid pid_file

stderr_path log_file
stdout_path log_file

preload_app true
##
# REE

GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)

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!

  
  ##
  # 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.

  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
    end
  end
end


after_fork do |server, worker|
    defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection


  worker.user(username, group) if Process.euid == 0 && rails_env == 'production'
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
dark-capistrano-recipes-0.8.4 generators/unicorn.rb.erb
dark-capistrano-recipes-0.8.3 generators/unicorn.rb.erb
dark-capistrano-recipes-0.8.2 generators/unicorn.rb.erb
dark-capistrano-recipes-0.8.1 generators/unicorn.rb.erb
capistrano-recipes-0.8.0 generators/unicorn.rb.erb
dark-capistrano-recipes-0.7.2 generators/unicorn.rb.erb
dark-capistrano-recipes-0.7.0 generators/unicorn.rb.erb
ra-capistrano-recipes-0.7.0 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.17 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.16 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.15 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.14.0 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.12.0 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.11 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.10 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.9 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.8 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.6 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.5 generators/unicorn.rb.erb
dark-capistrano-recipes-0.6.4 generators/unicorn.rb.erb