Class: Killer
Class Method Summary collapse
-
.graceful(pid) ⇒ Object
Forces the (rails) application to gracefully terminate by sending a
TERM
signal to the process. -
.kill(pid) ⇒ Object
Forces the (rails) application to terminate immediately by sending a -9 signal to the process.
-
.process(action, pid_path, pattern, keyword) ⇒ Object
Searches for all processes matching the given keywords, and then invokes a specific action on each of them.
-
.reload(pid) ⇒ Object
Forces the (rails) application to reload by sending a
HUP
signal to the process. -
.restart(pid) ⇒ Object
Force the (rails) application to restart by sending a
USR2
signal to the process. -
.usr1(pid) ⇒ Object
Send a
USR1
signal to the process.
Instance Method Summary collapse
-
#initialize(pid_path, pattern, keyword = nil) ⇒ Killer
constructor
A new instance of Killer.
- #process(action) ⇒ Object
Constructor Details
#initialize(pid_path, pattern, keyword = nil) ⇒ Killer
Returns a new instance of Killer.
48 49 50 |
# File 'lib/commands/process/reaper.rb', line 48 def initialize(pid_path, pattern, keyword=nil) @pid_path, @pattern, @keyword = pid_path, pattern, keyword end |
Class Method Details
.graceful(pid) ⇒ Object
Forces the (rails) application to gracefully terminate by sending a TERM
signal to the process.
32 33 34 |
# File 'lib/commands/process/reaper.rb', line 32 def graceful(pid) `kill -s TERM #{pid}` end |
.kill(pid) ⇒ Object
Forces the (rails) application to terminate immediately by sending a -9 signal to the process.
38 39 40 |
# File 'lib/commands/process/reaper.rb', line 38 def kill(pid) `kill -9 #{pid}` end |
.process(action, pid_path, pattern, keyword) ⇒ 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:
Killer.process(:reload, "/tmp/pids", "dispatcher.*.pid")
14 15 16 |
# File 'lib/commands/process/reaper.rb', line 14 def process(action, pid_path, pattern, keyword) new(pid_path, pattern, keyword).process(action) end |
.reload(pid) ⇒ Object
Forces the (rails) application to reload by sending a HUP
signal to the process.
20 21 22 |
# File 'lib/commands/process/reaper.rb', line 20 def reload(pid) `kill -s HUP #{pid}` end |
.restart(pid) ⇒ Object
Force the (rails) application to restart by sending a USR2
signal to the process.
26 27 28 |
# File 'lib/commands/process/reaper.rb', line 26 def restart(pid) `kill -s USR2 #{pid}` end |
.usr1(pid) ⇒ Object
Send a USR1
signal to the process.
43 44 45 |
# File 'lib/commands/process/reaper.rb', line 43 def usr1(pid) `kill -s USR1 #{pid}` end |
Instance Method Details
#process(action) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/commands/process/reaper.rb', line 52 def process(action) pids = find_processes if pids.empty? warn "Couldn't find any pid file in '#{@pid_path}' matching '#{@pattern}'" warn "(also looked for processes matching #{@keyword.inspect})" if @keyword else pids.each do |pid| puts "#{action.capitalize}ing #{pid}" self.class.send(action, pid) end delete_pid_files if terminating?(action) end end |