Sha256: 9560610f0d3d66a3e9587361654c33194e02f2c622823aaec035a391ca9a27f3

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

module WorkerKiller
  module Killer
    class Passenger < ::WorkerKiller::Killer::Base

      attr_reader :passenger_config

      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

      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

      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

      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

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
worker_killer-1.0.3.189564 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.3.189098 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.2.187852 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.2.187805 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.2.187732 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.1.83603 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.1.75538 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.1.39842 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.0.39841 lib/worker_killer/killer/passenger.rb
worker_killer-1.0.0.39839 lib/worker_killer/killer/passenger.rb
worker_killer-0.1.1.39838 lib/worker_killer/killer/passenger.rb