Class: WorkerKiller::Killer::Passenger
- Defined in:
- lib/worker_killer/killer/passenger.rb
Instance Attribute Summary collapse
-
#passenger_config ⇒ Object
readonly
Returns the value of attribute passenger_config.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #do_kill(sig, pid, alive_sec, **params) ⇒ Object
-
#initialize(path: nil, **kwrags) ⇒ Passenger
constructor
A new instance of Passenger.
Methods inherited from Base
Constructor Details
#initialize(path: nil, **kwrags) ⇒ Passenger
Returns a new instance of Passenger.
7 8 9 10 11 12 13 14 |
# 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 |
Instance Attribute Details
#passenger_config ⇒ Object (readonly)
Returns the value of attribute passenger_config.
5 6 7 |
# File 'lib/worker_killer/killer/passenger.rb', line 5 def passenger_config @passenger_config end |
Class Method Details
.check_passenger_config(path) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/worker_killer/killer/passenger.rb', line 36 def self.check_passenger_config path path.strip! help_str = `#{path} detach-process --help 2> /dev/null` return path if help_str['Remove an application process'] || help_str['Phusion Passenger'] rescue StandardError => e nil end |
.check_passenger_config!(path) ⇒ Object
44 45 46 47 48 49 50 |
# 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 |
Instance Method Details
#do_kill(sig, pid, alive_sec, **params) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 |