Class: Droonga::Serf::Agent

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

Constant Summary collapse

PORT =

the port must be different from droonga-http-server's agent!

7946
MAX_N_READ_CHECKS =
10

Instance Method Summary collapse

Methods included from Deferrable

#wait_until_ready

Constructor Details

#initialize(loop, serf, host, bind_port, rpc_port, *options) ⇒ Agent

Returns a new instance of Agent.



34
35
36
37
38
39
40
41
42
43
# File 'lib/droonga/serf/agent.rb', line 34

def initialize(loop, serf, host, bind_port, rpc_port, *options)
  @loop = loop
  @serf = serf
  @host = host
  @bind_port = bind_port
  @rpc_port = rpc_port
  @options = options
  @pid = nil
  @n_ready_checks = 0
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/droonga/serf/agent.rb', line 77

def running?
  not @pid.nil?
end

#startObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/droonga/serf/agent.rb', line 45

def start
  capture_output do |output_write, error_write|
    env = {}
    spawn_options = {
      :out => output_write,
      :err => error_write,
    }
    @pid = spawn(env, @serf, "agent",
                 "-bind", "#{@host}:#{@bind_port}",
                 "-rpc-addr", "#{@host}:#{@rpc_port}",
                 "-log-level", serf_log_level,
                 *@options, spawn_options)
  end
  start_ready_check
end

#stop(&block) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/droonga/serf/agent.rb', line 61

def stop(&block)
  if @pid.nil?
    yield if block_given?
    return
  end
  Process.waitpid(@pid)
  @output_io.close
  # logger.trace("stop: output_io watcher detached",
  #              :watcher => @output_io)
  @error_io.close
  # logger.trace("stop: error_io watcher detached",
  #              :watcher => @error_io)
  @pid = nil
  yield if block_given?
end