Sha256: bfe7d00bc4e0e91b25a1e4015b0fde5480c38c5f43230a85e0433ef825f53e6a

Contents?: true

Size: 1.43 KB

Versions: 16

Compression:

Stored size: 1.43 KB

Contents

working_directory "<%= current_path %>"
pid "<%= unicorn_pid_file %>"
stderr_path "<%= unicorn_log_file %>"
stdout_path "<%= unicorn_log_file %>"

# Listen on a Unix domain socket
# Use shorter backlog for quicker failover when busy
listen "<%= unicorn_socket_file %>", backlog: 64

# Preload our app for more speed
preload_app true

# See unicorn docs for more configuration details
worker_processes <%= unicorn_workers %>

# Kill workers after <%= unicorn_workers_timeout %> seconds, instead of the default 60
timeout <%= unicorn_workers_timeout %>

before_fork do |server, worker|
  # the following is recommended for Rails + "preload_app true"
  # as there is no need for the master process to hold a connection
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
  end
  
  # Before forking, kill the master process that belongs to the .oldbin PID.
  # This enables 0 downtime deploys.
  old_pid = "<%= unicorn_pid_file %>.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 killed it
    end
  end
end

after_fork do |server, worker|
  # the following is required for Rails + "preload_app true"
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
  end
  
  # if preload_app is true, you may also want to check and
  # restart any other shared sockets such as Memcached
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
capistrano_recipes-1.4.2 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.4.1 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.4.0 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.3.4 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.3.3 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.3.2 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.3.1 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.3.0 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.2.0 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.1.0 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.0.5 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.0.4 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.0.3 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.0.2 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.0.1 lib/capistrano/recipes/templates/unicorn.rb.erb
capistrano_recipes-1.0.0 lib/capistrano/recipes/templates/unicorn.rb.erb