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 ="Error: please use the following syntax:\n  \npassenger_reaper <command> <options>\n\nCommands:\n\nstatus    displays the number of total passenger workers and the number of active workers\nold       kills old workers that passengers has in the pool\nactive    kills stale workers that passengers has in the pool\ninactive  kills workers that passenger no longer controls\nall       kills both active, inactive & old workers\ndebug     shows the last log entry from each inactive worker\n\nOptions:\n\n--noop    don't actually kill processes but show which ones would have been killed\n--hard    send the KILL signal\n  EOF\n    puts help\n    exit 1\n  end\nend\n"