Sha256: b0fc109cf24db65cd422843fd4c8f1abd0e9ce83b1820113adc4cece85ffac67

Contents?: true

Size: 1.64 KB

Versions: 33

Compression:

Stored size: 1.64 KB

Contents

# Unicorn configuration

APP_ROOT = File.expand_path('../..', __FILE__)

require 'dotenv'
Dotenv.load

if ENV['UNICORN_BEHIND_NGINX']
  listen '/tmp/unicorn.<%= @config.app_name %>.sock'
else
  listen Integer(ENV['UNICORN_PORT'] || 3000)
end
worker_processes Integer(ENV['UNICORN_WORKERS'] || 1)
timeout Integer(ENV['UNICORN_TIMEOUT'] || 60)
working_directory APP_ROOT
pid "#{APP_ROOT}/tmp/pids/unicorn.pid"

stderr_path "#{APP_ROOT}/log/unicorn.log"
stdout_path "/#{APP_ROOT}/log/unicorn.log"

# load the application in the master process before forking worker processes
preload_app true

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

before_fork do |server, worker|
  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.
  old_pid = "#{APP_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
      # someone else did our job for us
    end
  end
end

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
railman-0.6.0 templates/rails_app/config/unicorn.rb.tt
railman-0.5.2 templates/rails_app/config/unicorn.rb.tt
railman-0.5.1 templates/rails_app/config/unicorn.rb.tt
railman-0.5.0 templates/rails_app/config/unicorn.rb.tt
railman-0.4.0 templates/rails_app/config/unicorn.rb.tt
railman-0.3.7 templates/rails_app/config/unicorn.rb.tt
railman-0.3.6 templates/rails_app/config/unicorn.rb.tt
railman-0.3.5 templates/rails_app/config/unicorn.rb.tt
railman-0.3.4 templates/rails_app/config/unicorn.rb.tt
railman-0.3.3 templates/rails_app/config/unicorn.rb.tt
railman-0.3.2 templates/rails_app/config/unicorn.rb.tt
railman-0.3.1 templates/rails_app/config/unicorn.rb.tt
railman-0.3.0 templates/rails_app/config/unicorn.rb.tt