Class: Droonga::Serf::SerfProcess

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/droonga/serf.rb

Instance Method Summary collapse

Constructor Details

#initialize(loop, serf, command, *options) ⇒ SerfProcess

Returns a new instance of SerfProcess.



262
263
264
265
266
267
268
# File 'lib/droonga/serf.rb', line 262

def initialize(loop, serf, command, *options)
  @loop = loop
  @serf = serf
  @command = command
  @options = options
  @pid = nil
end

Instance Method Details

#run_onceObject



293
294
295
296
297
298
299
300
# File 'lib/droonga/serf.rb', line 293

def run_once
  stdout, stderror, status = Open3.capture3(@serf, @command, *@options, :pgroup => true)
  {
    :result => stdout,
    :error  => stderror,
    :status => status,
  }
end

#running?Boolean

Returns:

  • (Boolean)


289
290
291
# File 'lib/droonga/serf.rb', line 289

def running?
  not @pid.nil?
end

#startObject



270
271
272
273
274
275
276
277
278
279
# File 'lib/droonga/serf.rb', line 270

def start
  capture_output do |output_write, error_write|
    env = {}
    spawn_options = {
      :out => output_write,
      :err => error_write,
    }
    @pid = spawn(env, @serf, @command, *@options, spawn_options)
  end
end

#stopObject



281
282
283
284
285
286
287
# File 'lib/droonga/serf.rb', line 281

def stop
  return if @pid.nil?
  Process.waitpid(@pid)
  @output_io.close
  @error_io.close
  @pid = nil
end