poise / application_ruby

Development repository for Opscode Cookbook application_ruby
Apache License 2.0
124 stars 153 forks source link

Unicorn: allow for custom runit templates (unicorn zero-downtime) #51

Closed JeanMertz closed 10 years ago

JeanMertz commented 10 years ago

This change, combined with the below custom template/config allowed for zero-downtime deployments with unicorn:

recipes/my_app.rb

application 'unicorn_zero_downtime' do

  # ...

  unicorn do
    preload_app true
    runit_cookbook '<my-cookbook>'
    runit_options pid: '/path/to/unicorn.pid'

    before_fork <<-EOF
      old_pid = '/path/to/unicorn.pid.oldbin'
      if File.exists?(old_pid) and server.pid != old_pid
        begin
          Process.kill('QUIT', File.read(old_pid).to_i)
        rescue Errno::ENOENT, Errno::ESRCH
        end
      end
    EOF

    restart_command Proc.new do
      runit_service 'unicorn_zero_downtime' do
        action :usr2
        sv_timeout 30
      end
    end
  end
end

templates/default/sv-unicorn-run.erb (modified from this gist, thanks @czarneckid)

https://gist.github.com/JeanMertz/8996796

JeanMertz commented 10 years ago

@jtimberman @coderanger, any interest in this PR? Would be nice to have it merged upstream. Thanks.

I also updated the original runit script as seen in this gist: https://gist.github.com/JeanMertz/8996796

coderanger commented 10 years ago

Please rebuild this branch without all the documentation changes.

damm commented 10 years ago

@jeanmertz you should post that somewhere on github and version it. That's pretty useful and I would hate it to get lost in a pull request.

JeanMertz commented 10 years ago

@damn the runit script is available as a gist, hope that helps.