class WorkerKiller::Killer::Passenger

Attributes

passenger_config[R]

Public Class Methods

check_passenger_config(path) click to toggle source
# File lib/worker_killer/killer/passenger.rb, line 36
def self.check_passenger_config path
  path.strip!
  help = `#{path} detach-process --help 2> /dev/null`
  return path if help['Remove an application process from the Phusion Passenger process pool']
rescue StandardError => e
  nil
end
check_passenger_config!(path) click to toggle source
# File lib/worker_killer/killer/passenger.rb, line 44
def self.check_passenger_config! path
  if path = check_passenger_config(path)
    path
  else
    raise "Can't find passenger config at #{path.inspect}"
  end
end
new(path: nil, **kwrags) click to toggle source
Calls superclass method WorkerKiller::Killer::Base::new
# File lib/worker_killer/killer/passenger.rb, line 7
def initialize path: nil, **kwrags
  super
  @passenger_config = if path.nil? || path.empty?
    self.class.check_passenger_config(`which passenger-config`)
  else
    self.class.check_passenger_config!(path)
  end
end

Public Instance Methods

do_kill(sig, pid, alive_sec, **params) click to toggle source
# File lib/worker_killer/killer/passenger.rb, line 16
def do_kill(sig, pid, alive_sec, **params)
  cmd = "#{passenger_config} detach-process #{pid}"
  if sig == :KILL
    logger.error "#{self} force to kill self (pid: #{pid}) alive: #{alive_sec} sec (trial #{kill_attempts})"
    Process.kill sig, pid
    return
  end

  return if @already_detached

  logger.warn "#{self} run #{cmd.inspect} (pid: #{pid}) alive: #{alive_sec} sec (trial #{kill_attempts})"
  @already_detached = true

  Thread.new(cmd) do |command|
    unless Kernel.system(command)
      logger.warn "#{self} run #{command.inspect} failed: #{$?.inspect}"
    end
  end
end