Class: ProcessWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/nsq-cluster/process_wrapper.rb

Direct Known Subclasses

Nsqadmin, Nsqd, Nsqlookupd

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ProcessWrapper

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

#argsObject



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

#commandObject



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

#destroyObject



23
24
25
# File 'lib/nsq-cluster/process_wrapper.rb', line 23

def destroy
  stop if running?
end

#outputObject



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

Returns:

  • (Boolean)


28
29
30
# File 'lib/nsq-cluster/process_wrapper.rb', line 28

def running?
  !!@pid
end

#startObject



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

#stopObject



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