Class: PassengerReaper::Runner

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

Constant Summary collapse

VALID_COMMANDS =
%w(old active inactive all debug status)

Class Method Summary collapse

Class Method Details

.runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/passenger_reaper.rb', line 9

def self.run
  commands = ARGV.select {|cmd| VALID_COMMANDS.include?(cmd) }
  unless commands.empty?
    commands.each do |arg|
      case arg
      when 'old'
        PassengerProcess.kill_old_passengers
      when 'active'
        PassengerProcess.kill_stale_passengers
      when 'inactive'
        PassengerProcess.kill_inactive_passengers
      when 'all'
        PassengerProcess.kill_old_passengers
        PassengerProcess.kill_stale_passengers
        PassengerProcess.kill_inactive_passengers
      when 'debug'
        PassengerProcess.inactive_passengers_last_log_entry
      when 'status'
        puts "Total of passengers: #{PassengerProcess.all_passenger_pids.count}"
        puts "Stale passengers: #{PassengerProcess.stale.count}"
      end
    end
  else
    help =<<-EOF
Error: please use the following syntax:
  
passenger_reaper <command> <options>

Commands:

status    displays the number of total passenger workers and the number of active workers
old       kills old workers that passengers has in the pool
active    kills stale workers that passengers has in the pool
inactive  kills workers that passenger no longer controls
all       kills both active, inactive & old workers
debug     shows the last log entry from each inactive worker

Options:

--noop    don't actually kill processes but show which ones would have been killed
--hard    send the KILL signal
  EOF
    puts help
    exit 1
  end
end