Sha256: c93cd835c0960cd220e89ce0f17e944a65fa6176ec1c79165faa5972b1603892

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

working_directory "<%= current_path %>"
pid "<%= fetch(:unicorn_pid) %>"
stdout_path "<%= unicorn_log_file %>"
stderr_path "<%= unicorn_error_log_file %>"

<% if fetch(:unicorn_use_tcp) -%>
listen <%= fetch(:unicorn_tcp_listen_port) %>
<% else -%>
listen "/tmp/unicorn.<%= fetch(:nginx_config_name) %>.sock"
<% end -%>

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

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
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    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 = 'localhost:6379'
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
capistrano-unicorn-nginx-5.2.0 lib/generators/capistrano/unicorn_nginx/templates/unicorn.rb.erb
capistrano-unicorn-nginx-5.1.0 lib/generators/capistrano/unicorn_nginx/templates/unicorn.rb.erb
capistrano-unicorn-nginx-5.0.0 lib/generators/capistrano/unicorn_nginx/templates/unicorn.rb.erb
capistrano-unicorn-nginx-4.2.0 lib/generators/capistrano/unicorn_nginx/templates/unicorn.rb.erb
capistrano-unicorn-nginx-4.1.0 lib/generators/capistrano/unicorn_nginx/templates/unicorn.rb.erb