aggkit 0.4.91.20757 → 0.4.91.21460
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +1 -1
- data/bin/aggwait +3 -4
- data/bin/aggwrap +74 -65
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85bf25ce943e64b3c06008e05eeb9fbae99e9e57640d630c929f042126da0610
|
|
4
|
+
data.tar.gz: b5bbd577d16a586ebd768ebdc7ed0f6bbc5e99b218f0dcec5ac51fdb77d0e0df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5cb6116f61a6f8828ba7f6eb3fe37289da61676bf89674955fe94b25a240c188430280be32199a4e3f8ba5a0609c9ef1093e8c77860cb9af5347c6aa9b15d174
|
|
7
|
+
data.tar.gz: 8e519d2aac6935545298fb17d2c565e6125161f90dbe8a19a9329e223ab062f9bc8ee22c8a3eacacc92dd7790e14faa62a11d349be2a90c916ca8e02d385ad1a
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/bin/aggwait
CHANGED
|
@@ -178,13 +178,12 @@ def wait_for_consul_service(tag_with_service)
|
|
|
178
178
|
tag = nil
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
tags = "#{tag}+#{@opts[:consul_tag]}".to_s.split('+').map(&:to_s).reject(&:empty?).uniq
|
|
182
182
|
|
|
183
|
-
log("Waiting for consul service #{service}#{
|
|
183
|
+
log("Waiting for consul service #{service}#{tags.empty? ? '' : " with tag #{tags}"}...")
|
|
184
184
|
ret = wait_for @opts[:timeout] do
|
|
185
|
-
tag_query =
|
|
185
|
+
tag_query = tags.empty? ? '' : tags.reduce(''){|q, t| q + "&tag=#{t}"}
|
|
186
186
|
cmd = "curl -s \"#{@opts[:consul_addr]}/v1/health/service/#{service}?passing#{tag_query}\""
|
|
187
|
-
|
|
188
187
|
result = `#{cmd}`
|
|
189
188
|
result = begin
|
|
190
189
|
JSON.parse(result)
|
data/bin/aggwrap
CHANGED
|
@@ -19,7 +19,7 @@ consul_addr = Aggkit::Consul.build_consul_addr(addr: ENV['CONSUL_HTTP_ADDR'], ho
|
|
|
19
19
|
|
|
20
20
|
@opts = {
|
|
21
21
|
service: ENV['AGGREDATOR_SERVICE'],
|
|
22
|
-
component: ENV.fetch(
|
|
22
|
+
component: ENV.fetch('AGGREDATOR_COMPONENT', 'service').strip,
|
|
23
23
|
id: Socket.gethostname,
|
|
24
24
|
reload_interval: DEFAULT_RELOAD_INTERVAL,
|
|
25
25
|
tags: []
|
|
@@ -117,7 +117,7 @@ SERVICE_ID = "#{@opts[:service]}_#{@opts[:component]}_#{@opts[:id]}".freeze
|
|
|
117
117
|
ID: SERVICE_ID,
|
|
118
118
|
Checks: [],
|
|
119
119
|
Tags: @opts[:tags],
|
|
120
|
-
Meta:
|
|
120
|
+
Meta: {
|
|
121
121
|
component: @opts[:component]
|
|
122
122
|
}
|
|
123
123
|
}
|
|
@@ -132,8 +132,8 @@ SERVICE_ID = "#{@opts[:service]}_#{@opts[:component]}_#{@opts[:id]}".freeze
|
|
|
132
132
|
ServiceID: SERVICE_ID,
|
|
133
133
|
Name: "Wrapped service: #{@opts[:service]}. Process: #{@opts[:exec].inspect}",
|
|
134
134
|
Notes: "Service: #{SERVICE_ID} Check: #{@checks[:exec]}",
|
|
135
|
-
DeregisterCriticalServiceAfter: '
|
|
136
|
-
TTL: '
|
|
135
|
+
DeregisterCriticalServiceAfter: '10m',
|
|
136
|
+
TTL: '100s'
|
|
137
137
|
)
|
|
138
138
|
|
|
139
139
|
if @opts[:http]
|
|
@@ -143,8 +143,8 @@ if @opts[:http]
|
|
|
143
143
|
ServiceID: SERVICE_ID,
|
|
144
144
|
Name: "Wrapped service: #{@opts[:service]}. HTTP: #{@opts[:http]}",
|
|
145
145
|
Notes: "Service: #{SERVICE_ID} Check: #{@checks[:http]}",
|
|
146
|
-
DeregisterCriticalServiceAfter: '
|
|
147
|
-
TTL: '
|
|
146
|
+
DeregisterCriticalServiceAfter: '10m',
|
|
147
|
+
TTL: '100s'
|
|
148
148
|
)
|
|
149
149
|
end
|
|
150
150
|
|
|
@@ -155,8 +155,8 @@ if @opts[:file]
|
|
|
155
155
|
ServiceID: SERVICE_ID,
|
|
156
156
|
Name: "Wrapped service: #{@opts[:service]}. File: #{@opts[:file]}",
|
|
157
157
|
Notes: "Service: #{SERVICE_ID} Check: #{@checks[:file]}",
|
|
158
|
-
DeregisterCriticalServiceAfter: '
|
|
159
|
-
TTL: '
|
|
158
|
+
DeregisterCriticalServiceAfter: '10m',
|
|
159
|
+
TTL: '100s'
|
|
160
160
|
)
|
|
161
161
|
end
|
|
162
162
|
|
|
@@ -167,8 +167,8 @@ if @opts[:pidfile]
|
|
|
167
167
|
ServiceID: SERVICE_ID,
|
|
168
168
|
Name: "Wrapped service: #{@opts[:service]}. Pidfile: #{@opts[:pidfile]}",
|
|
169
169
|
Notes: "Service: #{SERVICE_ID} Check: #{@checks[:pidfile]}",
|
|
170
|
-
DeregisterCriticalServiceAfter: '
|
|
171
|
-
TTL: '
|
|
170
|
+
DeregisterCriticalServiceAfter: '10m',
|
|
171
|
+
TTL: '100s'
|
|
172
172
|
)
|
|
173
173
|
end
|
|
174
174
|
|
|
@@ -179,19 +179,19 @@ if @opts[:script]
|
|
|
179
179
|
ServiceID: SERVICE_ID,
|
|
180
180
|
Name: "Wrapped service: #{@opts[:service]}. Script: #{@opts[:script]}",
|
|
181
181
|
Notes: "Service: #{SERVICE_ID} Check: #{@checks[:script]}",
|
|
182
|
-
DeregisterCriticalServiceAfter: '
|
|
183
|
-
TTL: '
|
|
182
|
+
DeregisterCriticalServiceAfter: '10m',
|
|
183
|
+
TTL: '100s'
|
|
184
184
|
)
|
|
185
185
|
end
|
|
186
186
|
|
|
187
187
|
def make_ttl_pass(check_id, output = nil)
|
|
188
188
|
output = "Check at: #{Time.now.utc}\n#{output}"
|
|
189
|
-
|
|
189
|
+
warn "TTL call failed: #{check_id}" unless Diplomat::Check.pass(check_id, output, timeout: 5)
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
def make_ttl_fail(check_id, output = nil)
|
|
193
193
|
output = "#{Time.now.utc}\n#{output}"
|
|
194
|
-
|
|
194
|
+
warn "TTL call failed: #{check_id}" unless Diplomat::Check.fail(check_id, output, timeout: 5)
|
|
195
195
|
end
|
|
196
196
|
|
|
197
197
|
def check_http(check_id, port)
|
|
@@ -235,7 +235,7 @@ end
|
|
|
235
235
|
def run_check(check_id)
|
|
236
236
|
yield(check_id)
|
|
237
237
|
rescue StandardError => e
|
|
238
|
-
|
|
238
|
+
warn "make_ttl_pass[#{check_id}] Exception: #{e.inspect}"
|
|
239
239
|
end
|
|
240
240
|
|
|
241
241
|
Thread.abort_on_exception = true
|
|
@@ -246,7 +246,7 @@ def with_retry(count = 2)
|
|
|
246
246
|
yield(retries + 1)
|
|
247
247
|
rescue StandardError
|
|
248
248
|
if (retries += 1) < count
|
|
249
|
-
|
|
249
|
+
warn "Retry #{retries} at: #{Time.now}..."
|
|
250
250
|
retry
|
|
251
251
|
else
|
|
252
252
|
raise
|
|
@@ -254,74 +254,81 @@ def with_retry(count = 2)
|
|
|
254
254
|
end
|
|
255
255
|
end
|
|
256
256
|
|
|
257
|
-
def ensure_service_registered
|
|
258
|
-
with_retry(
|
|
259
|
-
timeout =
|
|
257
|
+
def ensure_service_registered(retries = 2)
|
|
258
|
+
with_retry(retries) do |_r|
|
|
259
|
+
timeout = 30
|
|
260
260
|
unless Diplomat::Service.register(@service, timeout: timeout)
|
|
261
|
-
raise "Registration failed by Diplomat. Service:#{@service[:Name]} ID:#{@service[:ID]} (retry #{r})"
|
|
261
|
+
raise "Registration failed by Diplomat. Service:#{@service[:Name]} ID:#{@service[:ID]} (retry #{r})"
|
|
262
262
|
end
|
|
263
|
+
|
|
263
264
|
yield
|
|
264
265
|
end
|
|
265
|
-
rescue => e
|
|
266
|
+
rescue StandardError => e
|
|
266
267
|
die("Can't register service #{@service} in consul: #{e}")
|
|
267
268
|
end
|
|
268
269
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
run_check(@checks[:exec]) do |check_id|
|
|
273
|
-
make_ttl_pass(check_id)
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
if @checks[:http]
|
|
277
|
-
run_check(@checks[:http]) do |check_id|
|
|
278
|
-
check_http(check_id, @opts[:http])
|
|
279
|
-
end
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
if @checks[:file]
|
|
283
|
-
run_check(@checks[:file]) do |check_id|
|
|
284
|
-
check_file(check_id, @opts[:file])
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
if @checks[:pidfile]
|
|
289
|
-
run_check(@checks[:pidfile]) do |check_id|
|
|
290
|
-
check_pidfile(check_id, @opts[:pidfile])
|
|
291
|
-
end
|
|
292
|
-
end
|
|
270
|
+
def run_all_checks(checks, options)
|
|
271
|
+
checks.each do |(type, check_id)|
|
|
272
|
+
opts = options[type]
|
|
293
273
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
274
|
+
case type
|
|
275
|
+
when :exec then run_check(check_id) { make_ttl_pass(check_id) }
|
|
276
|
+
when :http then run_check(check_id) { check_http(check_id, opts) }
|
|
277
|
+
when :file then run_check(check_id) { check_file(check_id, opts) }
|
|
278
|
+
when :pidfile then run_check(check_id) { check_pidfile(check_id, opts) }
|
|
279
|
+
when :script then run_check(check_id) { check_script(check_id, opts) }
|
|
280
|
+
else
|
|
281
|
+
die("Invalid check type: #{type} with id: #{check_id}")
|
|
299
282
|
end
|
|
300
283
|
|
|
301
|
-
sleep rand(
|
|
284
|
+
sleep rand(1..5)
|
|
302
285
|
end
|
|
303
286
|
end
|
|
304
287
|
|
|
288
|
+
def start_ttl_thread
|
|
289
|
+
Thread.new do
|
|
290
|
+
sleep rand(5..15)
|
|
305
291
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
loop do
|
|
311
|
-
sleep sleep_interval
|
|
312
|
-
data = Diplomat::Kv.get(service_kv_path, recurse: true, convert_to_hash: true) rescue {}
|
|
292
|
+
loop do
|
|
293
|
+
ensure_service_registered(50) do
|
|
294
|
+
run_all_checks(@checks, @opts)
|
|
295
|
+
end
|
|
313
296
|
|
|
314
|
-
|
|
315
|
-
|
|
297
|
+
sleep rand(30..59)
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
end
|
|
316
301
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
302
|
+
def start_config_reload_thread(pid)
|
|
303
|
+
Thread.new(@opts[:reload_interval], @opts[:service]) do |sleep_interval, service_name|
|
|
304
|
+
kv_prefix = %w[services env]
|
|
305
|
+
config_hash = nil
|
|
306
|
+
service_kv_path = kv_prefix.push(service_name).join('/')
|
|
307
|
+
loop do
|
|
308
|
+
sleep sleep_interval
|
|
309
|
+
data = Diplomat::Kv.get(service_kv_path, recurse: true, convert_to_hash: true) rescue {}
|
|
310
|
+
|
|
311
|
+
service_data = data.dig(*kv_prefix)
|
|
312
|
+
next if service_data.nil?
|
|
313
|
+
|
|
314
|
+
new_hash = Digest::MD5.new.update(service_data.to_json).hexdigest
|
|
315
|
+
if !config_hash.nil? && config_hash != new_hash
|
|
316
|
+
warn 'Change kv configuration for consul service.'
|
|
317
|
+
::Process.kill(:TERM, pid)
|
|
318
|
+
sleep 15
|
|
319
|
+
::Process.kill(:KILL, pid)
|
|
320
|
+
sleep 10
|
|
321
|
+
die('Something wrong: we must be killed')
|
|
322
|
+
end
|
|
323
|
+
config_hash = new_hash
|
|
320
324
|
end
|
|
321
|
-
config_hash = new_hash
|
|
322
325
|
end
|
|
323
326
|
end
|
|
324
327
|
|
|
328
|
+
ensure_service_registered(2) do |r|
|
|
329
|
+
STDOUT.puts "Registration success by Diplomat. Service:#{@service[:Name]} ID:#{@service[:ID]} (retry #{r})"
|
|
330
|
+
start_ttl_thread
|
|
331
|
+
end
|
|
325
332
|
|
|
326
333
|
$pid = fork do
|
|
327
334
|
STDERR.sync
|
|
@@ -336,6 +343,8 @@ end
|
|
|
336
343
|
end
|
|
337
344
|
end
|
|
338
345
|
|
|
346
|
+
start_config_reload_thread($pid)
|
|
347
|
+
|
|
339
348
|
_pid, status = Process.wait2($pid)
|
|
340
349
|
|
|
341
350
|
result = {}
|
|
@@ -358,7 +367,7 @@ if result[:signal]
|
|
|
358
367
|
elsif result[:exit]
|
|
359
368
|
exit(result[:exit])
|
|
360
369
|
else
|
|
361
|
-
|
|
370
|
+
warn 'unknown subprocess result'
|
|
362
371
|
exit(-1)
|
|
363
372
|
end
|
|
364
373
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aggkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.91.
|
|
4
|
+
version: 0.4.91.21460
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Godko Ivan
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2019-12-
|
|
12
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: diplomat
|