Sha256: f2246e19a2d4c813f437d8d4ea17183f4fdd241b64e64befb0e82d7150bdad9b

Contents?: true

Size: 1.84 KB

Versions: 9

Compression:

Stored size: 1.84 KB

Contents

working_directory "<%= current_path %>"
pid "<%= unicorn_pid %>"
stderr_path "<%= unicorn_log %>"
stdout_path "<%= unicorn_log %>"

listen "/tmp/<%= application %>.sock"
worker_processes <%= unicorn_workers %>
timeout 90

preload_app true

before_exec do |server|
  ENV["BUNDLE_GEMFILE"] = "<%= current_path %>/Gemfile"
end

before_fork do |server, worker|
  # Disconnect since the database connection will not carry over
  if defined? ActiveRecord::Base
    ActiveRecord::Base.connection.disconnect!
  end

  # Quit the old unicorn process
  old_pid = "#{server.config[: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

  # The following is only recommended for memory/DB-constrained
  # installations.  It is not needed if your system can house
  # twice as many worker_processes as you have configured.
  #
  # # This allows a new master process to incrementally
  # # phase out the old master process with SIGTTOU to avoid a
  # # thundering herd (especially in the "preload_app false" case)
  # # when doing a transparent upgrade.  The last worker spawned
  # # will then kill off the old master process with a SIGQUIT.

  #old_pid = "#{server.config[:pid]}.oldbin"
    #if old_pid != server.pid
      #begin
        ##sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
        #Process.kill(sig, File.read(old_pid).to_i)
      #rescue Errno::ENOENT, Errno::ESRCH
      #end
    #end

  if defined?(Resque)
    Resque.redis.quit
  end

  sleep 1
end

after_fork do |server, worker|
  # Start up the database connection again in the worker
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
  end

  if defined?(Resque)
    Resque.redis.client.reconnect
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kapify-0.1.3 lib/generators/kapify/unicorn/templates/unicorn.rb.erb
kapify-0.1.2 lib/generators/kapify/unicorn/templates/unicorn.rb.erb
kapify-0.1.1 lib/generators/kapify/unicorn/templates/unicorn.rb.erb
kapify-0.1.0 lib/generators/kapify/unicorn/templates/unicorn.rb.erb
kapify-0.0.16 lib/generators/kapify/unicorn/templates/unicorn.rb.erb
kapify-0.0.15 lib/generators/kapify/unicorn/templates/unicorn.rb.erb
kapify-0.0.14 lib/generators/kapify/unicorn/templates/unicorn.rb.erb
kapify-0.0.13 lib/generators/kapify/unicorn/templates/unicorn.rb.erb
kapify-0.0.12 lib/generators/kapify/unicorn/templates/unicorn.rb.erb