Module: AutoConsul::Runner
- Defined in:
- lib/auto-consul/runner.rb
Defined Under Namespace
Classes: AgentProcess
Constant Summary collapse
- INITIAL_VERIFY_SLEEP =
0.1- SLEEP_INTERVAL =
2- RETRIES =
5
Class Method Summary collapse
- .agent_runner(identity, bind_ip, expiry, local_state, registry, opt = {}) ⇒ Object
- .join(remote_ip) ⇒ Object
- .joining_runner(agent_args, opt = {}) ⇒ Object
- .pick_joining_host(hosts) ⇒ Object
- .server_runner(identity, bind_ip, expiry, local_state, registry, opt = {}) ⇒ Object
- .verify_running(pid) ⇒ Object
Class Method Details
.agent_runner(identity, bind_ip, expiry, local_state, registry, opt = {}) ⇒ Object
162 163 164 165 166 167 |
# File 'lib/auto-consul/runner.rb', line 162 def self.agent_runner identity, bind_ip, expiry, local_state, registry, opt={} opt[:remote_ip] = pick_joining_host(registry.agents.members(expiry)) args = ['-bind', bind_ip, '-data-dir', local_state.data_path, '-node', identity] args += ['-config-dir', opt[:config_dir]] if ! opt[:config_dir].nil? joining_runner(args, opt) end |
.join(remote_ip) ⇒ Object
153 154 155 |
# File 'lib/auto-consul/runner.rb', line 153 def self.join remote_ip system('consul', 'join', remote_ip) end |
.joining_runner(agent_args, opt = {}) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/auto-consul/runner.rb', line 135 def self.joining_runner(agent_args, opt={}) opt_args = [] opt_args += ['-advertise', opt[:advertise]] if ! opt[:advertise].nil? runner = AgentProcess.new(agent_args + opt_args) if not opt[:remote_ip].nil? runner.on_up {|a| join opt[:remote_ip]} end runner end |
.pick_joining_host(hosts) ⇒ Object
157 158 159 160 |
# File 'lib/auto-consul/runner.rb', line 157 def self.pick_joining_host hosts # Lets randomize this later. hosts[0].data end |
.server_runner(identity, bind_ip, expiry, local_state, registry, opt = {}) ⇒ Object
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/auto-consul/runner.rb', line 169 def self.server_runner identity, bind_ip, expiry, local_state, registry, opt={} members = registry.servers.members(expiry) opt[:remote_ip] = members.size > 0 ? pick_joining_host(members) : nil args = ['-bind', bind_ip, '-data-dir', local_state.data_path, '-node', identity, '-server'] args += ['-config-dir', opt[:config_dir]] if ! opt[:config_dir].nil? args << '-bootstrap' if members.size < 1 joining_runner(args, opt) end |
.verify_running(pid) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/auto-consul/runner.rb', line 145 def self.verify_running pid RETRIES.times do |i| sleep SLEEP_INTERVAL + (SLEEP_INTERVAL * i) return true if system('consul', 'info') end return false end |