Class: ProgramProcess
Overview
Instances of this class represent a single running process. Processes may be queried by “keyword” to find those that meet a specific set of criteria.
Class Method Summary collapse
-
.find_by_keyword(keyword) ⇒ Object
Searches for all processes matching the given keyword:.
-
.process_keywords(action, *keywords) ⇒ Object
Searches for all processes matching the given keywords, and then invokes a specific action on each of them.
Instance Method Summary collapse
-
#graceful ⇒ Object
Forces the (rails) application to gracefully terminate by sending a
TERM
signal to the process. -
#initialize(pid, command) ⇒ ProgramProcess
constructor
Create a new ProgramProcess instance that represents the process with the given pid, running the given command.
-
#kill ⇒ Object
Forces the (rails) application to terminate immediately by sending a -9 signal to the process.
-
#reload ⇒ Object
Forces the (rails) application to reload by sending a
HUP
signal to the process. -
#restart ⇒ Object
Force the (rails) application to restart by sending a
USR2
signal to the process. -
#to_s ⇒ Object
:nodoc:.
-
#usr1 ⇒ Object
Send a
USR1
signal to the process.
Constructor Details
#initialize(pid, command) ⇒ ProgramProcess
Create a new ProgramProcess instance that represents the process with the given pid, running the given command.
49 50 51 |
# File 'lib/commands/process/reaper.rb', line 49 def initialize(pid, command) @pid, @command = pid, command end |
Class Method Details
.find_by_keyword(keyword) ⇒ Object
Searches for all processes matching the given keyword:
ProgramProcess.find_by_keyword("basecamp")
33 34 35 36 37 38 39 |
# File 'lib/commands/process/reaper.rb', line 33 def find_by_keyword(keyword) process_lines_with_keyword(keyword).split("\n").collect { |line| next if line =~ /inq|ps axww|grep|spawn-fcgi|spawner|reaper/ pid, *command = line.split new(pid, command.join(" ")) }.compact end |
.process_keywords(action, *keywords) ⇒ Object
Searches for all processes matching the given keywords, and then invokes a specific action on each of them. This is useful for (e.g.) reloading a set of processes:
ProgramProcess.process_keywords(:reload, "basecamp")
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/commands/process/reaper.rb', line 17 def process_keywords(action, *keywords) processes = keywords.collect { |keyword| find_by_keyword(keyword) }.flatten if processes.empty? puts "Couldn't find any process matching: #{keywords.join(" or ")}" else processes.each do |process| puts "#{action.capitalize}ing #{process}" process.send(action) end end end |
Instance Method Details
#graceful ⇒ Object
Forces the (rails) application to gracefully terminate by sending a TERM
signal to the process.
61 62 63 |
# File 'lib/commands/process/reaper.rb', line 61 def graceful `kill -s TERM #{@pid}` end |
#kill ⇒ Object
Forces the (rails) application to terminate immediately by sending a -9 signal to the process.
67 68 69 |
# File 'lib/commands/process/reaper.rb', line 67 def kill `kill -9 #{@pid}` end |
#reload ⇒ Object
Forces the (rails) application to reload by sending a HUP
signal to the process.
55 56 57 |
# File 'lib/commands/process/reaper.rb', line 55 def reload `kill -s HUP #{@pid}` end |
#restart ⇒ Object
Force the (rails) application to restart by sending a USR2
signal to the process.
78 79 80 |
# File 'lib/commands/process/reaper.rb', line 78 def restart `kill -s USR2 #{@pid}` end |
#to_s ⇒ Object
:nodoc:
82 83 84 |
# File 'lib/commands/process/reaper.rb', line 82 def to_s #:nodoc: "[#{@pid}] #{@command}" end |
#usr1 ⇒ Object
Send a USR1
signal to the process.
72 73 74 |
# File 'lib/commands/process/reaper.rb', line 72 def usr1 `kill -s USR1 #{@pid}` end |