Class: ElasticSearch::Node::External

Inherits:
Object
  • Object
show all
Includes:
ClientProvider
Defined in:
lib/elasticsearch-node/external.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClientProvider

included

Constructor Details

#initialize(opts = {}) ⇒ External

Returns a new instance of External.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/elasticsearch-node/external.rb', line 10

def initialize(opts = {})
  if opts[:config]
    ENV["ES_HOME"] = ElasticSearch::Node.config(opts[:config])
  end

  commandline = opts.map {|opt,value| "-Des.#{opt}=#{value}" }.join(" ")

  if !(RUBY_PLATFORM == 'java') && (Kernel.respond_to? :spawn)
    capture_ip_and_port do
      self.pid = Kernel.spawn("#{Node.binary} -f #{commandline}", :out => :out, :err => :err)
    end
  else
    process = IO.popen("#{Node.binary} -f #{commandline}", "r")
    parse_ip_and_port(process)
    start_slurper(process)
    self.pid = process.pid
  end

  super(opts)
end

Instance Attribute Details

#pidObject

Returns the value of attribute pid.



8
9
10
# File 'lib/elasticsearch-node/external.rb', line 8

def pid
  @pid
end

Instance Method Details

#closeObject



39
40
41
42
43
44
45
46
47
# File 'lib/elasticsearch-node/external.rb', line 39

def close
  $stderr.puts "Killing ElasticSearch node: #{pid}"
  Process.kill 15, pid
  begin
    Process.waitpid pid
  rescue Errno::ECHILD
    # Possible, if process is already gone
  end
end

#ipObject



35
36
37
# File 'lib/elasticsearch-node/external.rb', line 35

def ip
  @ip
end

#portObject



31
32
33
# File 'lib/elasticsearch-node/external.rb', line 31

def port
  @port
end