class UnicornRelay::Teardown
Before forking anew, kill the unicorn master process that belongs to the .oldbin PID. This enables 0 downtime deploys.
Public Class Methods
new(server:, pid_file:)
click to toggle source
@param server [ Unicorn::HttpServer ] an instance of a unicorn server @param pid_file [ String ] the path to the old unicorn master's pid file (usually ending in “.oldbin”)
# File lib/unicorn_relay/teardown.rb, line 6 def initialize(server:, pid_file:) @server = server @pid_file = pid_file end
Public Instance Methods
perform()
click to toggle source
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.
# File lib/unicorn_relay/teardown.rb, line 13 def perform server_has_new_pid_file? && pid and kill_pid end
Private Instance Methods
kill_pid()
click to toggle source
# File lib/unicorn_relay/teardown.rb, line 19 def kill_pid Process.kill(:QUIT, pid) rescue Errno::ESRCH end
pid()
click to toggle source
# File lib/unicorn_relay/teardown.rb, line 38 def pid pid = pid_file_content.to_i pid.nonzero? end
pid_file_content()
click to toggle source
# File lib/unicorn_relay/teardown.rb, line 32 def pid_file_content File.read(@pid_file) rescue Errno::ENOENT, Errno::ENOTDIR end
pid_file_exist?()
click to toggle source
# File lib/unicorn_relay/teardown.rb, line 28 def pid_file_exist? File.exist?(@pid_file) end
server_has_new_pid_file?()
click to toggle source
# File lib/unicorn_relay/teardown.rb, line 24 def server_has_new_pid_file? pid_file_exist? && @server.pid != @pid_file end