Class: ProcessWrapper
- Inherits:
-
Object
show all
- Defined in:
- lib/nsq-cluster/process_wrapper.rb
Constant Summary
collapse
- HTTPCHECK_INTERVAL =
0.01
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}, verbose = false) ⇒ ProcessWrapper
Returns a new instance of ProcessWrapper.
6
7
8
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 6
def initialize(opts = {}, verbose = false)
@verbose = verbose
end
|
Instance Attribute Details
#pid ⇒ Object
Returns the value of attribute pid.
4
5
6
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 4
def pid
@pid
end
|
Instance Method Details
#another_instance_is_running? ⇒ Boolean
37
38
39
40
41
42
43
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 37
def another_instance_is_running?
if respond_to?(:http_port)
http_port_open?
else
false
end
end
|
#args ⇒ Object
51
52
53
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 51
def args
raise 'you have to override this in a subclass as well, buddy'
end
|
#block_until_running ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 65
def block_until_running
if respond_to?(:http_port) && respond_to?(:host)
wait_for_http_port
else
raise "Can't block without http port and host"
end
end
|
#block_until_stopped ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 74
def block_until_stopped
if respond_to?(:http_port) && respond_to?(:host)
wait_for_no_http_port
else
raise "Can't block without http port and host"
end
end
|
#command ⇒ Object
46
47
48
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 46
def command
raise 'you have to override this in a subclass, hotshot'
end
|
#destroy ⇒ Object
27
28
29
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 27
def destroy
stop(async: true) if running?
end
|
#output ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 56
def output
if @verbose
:out
else
'/dev/null'
end
end
|
#running? ⇒ Boolean
32
33
34
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 32
def running?
!!@pid
end
|
#start(opts = {}) ⇒ Object
11
12
13
14
15
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 11
def start(opts = {})
raise "#{command} is already running" if running? || another_instance_is_running?
@pid = spawn(command, *args, [:out, :err] => output)
block_until_running unless opts[:async]
end
|
#stop(opts = {}) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 18
def stop(opts = {})
raise "#{command} is not running" unless running?
Process.kill('TERM', @pid)
Process.waitpid(@pid)
@pid = nil
block_until_stopped unless opts[:async]
end
|