Class: UnicornRelay::Teardown

Inherits:
Object
  • Object
show all
Defined in:
lib/unicorn_relay/teardown.rb

Overview

Before forking anew, kill the unicorn master process that belongs to the .oldbin PID. This enables 0 downtime deploys.

Instance Method Summary collapse

Constructor Details

#initialize(server:, pid_file:) ⇒ Teardown

Returns a new instance of Teardown.

Parameters:

  • server (Unicorn::HttpServer)

    an instance of a unicorn server

  • pid_file (String)

    the path to the old unicorn master’s pid file (usually ending in “.oldbin”)



6
7
8
9
# File 'lib/unicorn_relay/teardown.rb', line 6

def initialize(server:, pid_file:)
  @server   = server
  @pid_file = pid_file
end

Instance Method Details

#performObject

Peforms the teardown of the old unicorn master from one of the workers forked by the new master, if the new master has a different pid file.



13
14
15
# File 'lib/unicorn_relay/teardown.rb', line 13

def perform
  server_has_new_pid_file? && pid and kill_pid
end