Module: Terminate
- Defined in:
- lib/terminate.rb,
lib/terminate/options.rb,
lib/terminate/railtie.rb,
lib/terminate/version.rb
Defined Under Namespace
Classes: Options, Railtie
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Method Summary
collapse
Class Method Details
.execute(pid, timeout = 10, signal = 'TERM') ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/terminate.rb', line 23
def self.execute(pid, timeout = 10, signal = 'TERM')
if pid_exist?(pid)
Process.kill(signal, pid)
info "Send SIGNAL #{signal} to process #{pid}."
begin
Timeout.timeout(timeout) do
while pid_exist?(pid)
sleep 0.1
end
info "Process #{pid} is done."
end
rescue Timeout::Error
Process.kill('KILL', pid)
info "Timeout, send SIGNAL KILL to process #{pid}."
end
else
info "Process #{pid} is not found."
end
end
|
.info(*args) ⇒ Object
43
44
45
|
# File 'lib/terminate.rb', line 43
def self.info(*args)
logger.info(*args) unless logger.nil?
end
|
.logger ⇒ Object
10
11
12
|
# File 'lib/terminate.rb', line 10
def self.logger
@@logger
end
|
.logger=(logger) ⇒ Object
6
7
8
|
# File 'lib/terminate.rb', line 6
def self.logger=(logger)
@@logger = logger
end
|
.pid_exist?(pid) ⇒ Boolean
14
15
16
17
18
19
20
21
|
# File 'lib/terminate.rb', line 14
def self.pid_exist?(pid)
begin
Process.getpgid( pid )
true
rescue Errno::ESRCH
false
end
end
|