Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

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

Closed

Conversation

JeanMertz
Copy link
Contributor

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

caleb and others added 2 commits January 17, 2014 23:12
@JeanMertz
Copy link
Contributor Author

@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
Copy link
Member

Please rebuild this branch without all the documentation changes.

@coderanger coderanger closed this Mar 3, 2014
@damm
Copy link

damm commented Mar 3, 2014

@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
Copy link
Contributor Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants