Skip to content

inokappa/mruby-consul

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mruby-consul Build Status

install by mrbgems

  • add conf.gem line to build_config.rb
MRuby::Build.new do |conf|

    # ... (snip) ...

    conf.gem :github => 'inokappa/mruby-consul'
end

supported endpoint


example(1)

Run Consul

$ cat /etc/consul.d/default.json
{
  "server": true,
  "bootstrap_expect": 1,
  "log_level": "INFO",
  "node_name": "localhost",
  "data_dir": "/opt/consul",
  "ui_dir": "/opt/consul-ui",
  "client_addr": "0.0.0.0"
}
$ consul agent -config-dir /etc/consul.d &

code

config = {
  :host => "127.0.0.1",
  :port => "8500",
}

kv = Consul::Kv.new(config)
puts "put: #{kv.put("foo", "bar")['body']}"
puts "get: #{kv.get("foo")['body']}"
puts "delete: #{kv.del("foo")['body']}"

status = Consul::Status.new(config)
puts "leader: #{status.leader['body']}"
puts "peers: #{status.peers['body']}"

health = Consul::Health.new(config)
puts "node: #{health.node("localhost")['body']}"
puts "checks: #{health.checks("your_service")['body']}"
puts "service: #{health.service("your_service")['body']}"
puts "state: #{health.state("any")['body']}"

output

put: true
get: [{"CreateIndex":523,"ModifyIndex":523,"LockIndex":0,"Key":"foo","Flags":0,"Value":"YmFy"}]
delete: true
leader: "10.0.2.xx:8300"
peers: ["10.0.2.xx:8300"]
node: [{"Node":"localhost","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"Agent alive and reachable","ServiceID":"","ServiceName":""}]
checks: []
service: []
state: [{"Node":"localhost","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"Agent alive and reachable","ServiceID":"","ServiceName":""}]

example(2)

Referred to

Thank you!!!

Run Consul

$ cat /etc/consul.d/default.json
{
  "server": true,
  "bootstrap_expect": 1,
  "log_level": "INFO",
  "node_name": "localhost",
  "data_dir": "/opt/consul",
  "ui_dir": "/opt/consul-ui",
  "client_addr": "0.0.0.0"
}
$ consul agent -config-dir /etc/consul.d &

docker build

$ docker build -t inokappa/mruby-consul .

code

config = {
  :host => "${your docker0 IP address}",
  :port => "8500",
}

kv = Consul::Kv.new(config)
puts "put: #{kv.put("foo", "bar")['body']}"
puts "get: #{kv.get("foo")['body']}"
puts "delete: #{kv.del("foo")['body']}"

status = Consul::Status.new(config)
puts "leader: #{status.leader['body']}"
puts "peers: #{status.peers['body']}"

health = Consul::Health.new(config)
puts "node: #{health.node("localhost")['body']}"
puts "checks: #{health.checks("your_service")['body']}"
puts "service: #{health.service("your_service")['body']}"
puts "state: #{health.state("any")['body']}"

docker run

$ docker run --rm -v `pwd`:/tmp inokappa/mruby-consul /tmp/example/example.rb

output

put: true
get: [{"CreateIndex":523,"ModifyIndex":523,"LockIndex":0,"Key":"foo","Flags":0,"Value":"YmFy"}]
delete: true
leader: "10.0.2.xx:8300"
peers: ["10.0.2.xx:8300"]
node: [{"Node":"localhost","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"Agent alive and reachable","ServiceID":"","ServiceName":""}]
checks: []
service: []
state: [{"Node":"localhost","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"Agent alive and reachable","ServiceID":"","ServiceName":""}]

License

under the MIT License:

  • see LICENSE file

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published