Sha256: 4abafb0ee230aae20c7cc5dc8646b7af60a6cfd8fd7cc32c0fa62b2e7c509076

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

 def processor_count
    case RbConfig::CONFIG['host_os']
    when /darwin9/
      `hwprefs cpu_count`.to_i
    when /darwin/
      ((`which hwprefs` != '') ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
    when /linux/
      `cat /proc/cpuinfo | grep processor | wc -l`.to_i
    when /freebsd/
      `sysctl -n hw.ncpu`.to_i
    when /mswin|mingw/
      require 'win32ole'
      wmi = WIN32OLE.connect("winmgmts://")
      cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this
      cpu.to_enum.first.NumberOfCores
    end
  end


working_directory "<%= current_path %>"

<% if instances %>
worker_processes <%= instances %>
<% else %>
worker_processes processor_count * 2
<% end %>
preload_app true
timeout 180


stderr_path "<%= shared_path.join("log/unicorn-error.log") %>"
stdout_path "<%= shared_path.join("log/unicorn.log") %>"


pid "<%= shared_path.join("tmp/pids/unicorn.pid") %>"

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

before_exec do |server|
  ENV["BUNDLE_GEMFILE"] = "<%=current_path%>/Gemfile"
  Unicorn::HttpServer::START_CTX[0] = "<%=shared_path%>/bin/unicorn"
end

before_fork do |server, worker|
  defined?(ActiveRecord) && ActiveRecord::Base.connection.disconnect!

  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
end

after_fork do |server, worker|
  defined?(ActiveRecord) && ActiveRecord::Base.establish_connection
  defined?(Rails) and Rails.cache.respond_to?(:reconnect) and Rails.cache.reconnect
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
capistrano-cluster-0.0.18 files/unicorn.rb.erb
capistrano-cluster-0.0.17 files/unicorn.rb.erb
capistrano-cluster-0.0.16 files/unicorn.rb.erb
capistrano-cluster-0.0.15 files/unicorn.rb.erb
capistrano-cluster-0.0.14 files/unicorn.rb.erb
capistrano-cluster-0.0.13 files/unicorn.rb.erb
capistrano-cluster-0.0.12 files/unicorn.rb.erb
capistrano-cluster-0.0.11 files/unicorn.rb.erb
capistrano-cluster-0.0.10 files/unicorn.rb.erb