Sha256: 416d6d1b21cd1829fe9be18fceb83c16d2e538a0f953b3d7429ecb350a6deabe

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

Rainbows! do
  name = '<%= @name %>'
 
  case ENV['RACK_ENV'].to_sym
  when :development
  	worker_processes 1
  	worker_connections 32
    listen 8080
    stderr_path "log/development.log"
    stdout_path "log/development.log"
  when :production
    worker_processes 2
    worker_connections 32
    timeout 30
    listen 8080
    pid "log/#{name}.pid"
    stderr_path "log/production.log"
    stdout_path "log/production.log"
 
    ###
    # Hardcore performance tweaks, described here: https://github.com/blog/517-unicorn
    ###
 
    # This loads the app in master, and then forks workers. Kill with USR2 and it will do a graceful restart using the block proceeding.
    preload_app true
 
    before_fork do |server, worker|
      ##
      # 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.
      # kill -USR2 `log/yourappname.pid`
 
      old_pid = "/var/run/yourcompany/#{name}.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
 
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
guyifeng-0.1.7 lib/guyifeng/template/config/zbatery.rb.tt
guyifeng-0.1.6 lib/guyifeng/template/config/zbatery.rb.tt
guyifeng-0.1.5 lib/guyifeng/template/config/zbatery.rb.tt
guyifeng-0.1.4 lib/guyifeng/template/config/zbatery.rb.tt
guyifeng-0.1.2 lib/guyifeng/template/config/zbatery.rb.tt