Class: ProcessWrapper
- Inherits:
-
Object
show all
- Defined in:
- lib/nsq-cluster/process_wrapper.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ProcessWrapper.
4
5
6
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 4
def initialize(opts = {})
@silent = opts[:silent]
end
|
Instance Method Details
#args ⇒ Object
38
39
40
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 38
def args
raise 'you have to override this in a subclass as well, buddy'
end
|
#command ⇒ Object
33
34
35
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 33
def command
raise 'you have to override this in a subclass, hotshot'
end
|
#destroy ⇒ Object
23
24
25
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 23
def destroy
stop if running?
end
|
#output ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 43
def output
if @silent
'/dev/null'
else
:out
end
end
|
#running? ⇒ Boolean
28
29
30
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 28
def running?
!!@pid
end
|
#start ⇒ Object
9
10
11
12
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 9
def start
raise "#{command} is already running" if running?
@pid = spawn(command, *args, [:out, :err] => output)
end
|
#stop ⇒ Object
15
16
17
18
19
20
|
# File 'lib/nsq-cluster/process_wrapper.rb', line 15
def stop
raise "#{command} is not running" unless running?
Process.kill('TERM', @pid)
Process.waitpid(@pid)
@pid = nil
end
|