class AutoConsul::RunState::CLIProvider

Constants

AGENT_MASK
SERVER_MASK

Public Instance Methods

agent?() click to toggle source
# File lib/auto-consul/run_state/cli.rb, line 49
def agent?
  (run_state & AGENT_MASK) > 0
end
check_run_state() click to toggle source
# File lib/auto-consul/run_state/cli.rb, line 6
def check_run_state
  result = 0
  r, w = IO.pipe
  if system("consul info", :out => w)
    w.close
    result = flags_from_output r
    r.close
  end
  result
end
flags_from_output(stream) click to toggle source
# File lib/auto-consul/run_state/cli.rb, line 17
def flags_from_output stream
  consul_block = false
  result = 0
  stream.each do |line|
    if line =~ /^consul:\s/
      consul_block = true
      result = AGENT_MASK
      break
    end
  end

  if consul_block
    stream.each do |line|
      # Exit condition from consul block
      break if line !~ /^\s+/

      if line =~ /^\s+server\s+=\s+true/
        result |= SERVER_MASK
        break
      end
    end
  end
  result
end
run_state() click to toggle source
# File lib/auto-consul/run_state/cli.rb, line 42
def run_state
  if @run_state.nil?
    @run_state = check_run_state
  end
  @run_state
end
running?() click to toggle source
# File lib/auto-consul/run_state/cli.rb, line 57
def running?
  run_state > 0
end
server?() click to toggle source
# File lib/auto-consul/run_state/cli.rb, line 53
def server?
  (run_state & SERVER_MASK) > 0
end