config_skeleton 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config_skeleton.gemspec +3 -3
- data/lib/config_skeleton.rb +34 -13
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 065e0e44c1b485dc5b32c9466cb68bd9f3c8c3af8704489a0f747951b714347c
|
4
|
+
data.tar.gz: 48518976b9d43abc868a0f1f8b6cb1a2ecefca7274f11d0be6578f035e7e1400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7985e2e04988415a4435d25b233d4515256ca7c352fe9a2df9038d912e8448f1bc26ac582de28f7d39400936165856b31c4a914e7a872ea999dd53ed5debf1dc
|
7
|
+
data.tar.gz: 5a684bf24de1bcc0a8d2fc85b34a335c33c997f747787b02d870b8b5b0b19b87200d362d804752865377b75ec21352a8bd4fc655bf95d95e5d6f16628fb22e05
|
data/config_skeleton.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "config_skeleton"
|
3
3
|
|
4
|
-
s.version = "0.
|
4
|
+
s.version = "0.4.0"
|
5
5
|
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
|
8
8
|
s.summary = "Dynamically generate configs and reload servers"
|
9
9
|
|
10
|
-
s.authors = ["Matt Palmer"]
|
11
|
-
s.email = ["matt.palmer@discourse.org"]
|
10
|
+
s.authors = ["Matt Palmer", "Discourse Team"]
|
11
|
+
s.email = ["matt.palmer@discourse.org", "team@discourse.org"]
|
12
12
|
s.homepage = "https://github.com/discourse/config_skeleton"
|
13
13
|
|
14
14
|
s.files = `git ls-files -z`.split("\0").reject { |f| f =~ /^(G|spec|Rakefile)/ }
|
data/lib/config_skeleton.rb
CHANGED
@@ -5,6 +5,7 @@ require 'logger'
|
|
5
5
|
require 'rb-inotify'
|
6
6
|
require 'service_skeleton'
|
7
7
|
require 'tempfile'
|
8
|
+
require 'digest/md5'
|
8
9
|
|
9
10
|
# Framework for creating config generation systems.
|
10
11
|
#
|
@@ -23,8 +24,7 @@ require 'tempfile'
|
|
23
24
|
#
|
24
25
|
# 1. Implement service-specific config generation and reloading code, by
|
25
26
|
# overriding the private methods #config_file, #config_data, and #reload_server
|
26
|
-
# (and also potentially #config_ok?, #sleep_duration, #before_regenerate_config, and
|
27
|
-
# #after_regenerate_config).
|
27
|
+
# (and also potentially #config_ok?, #sleep_duration, #before_regenerate_config, and #after_regenerate_config).
|
28
28
|
# See the documentation for those methods for what they need to do.
|
29
29
|
#
|
30
30
|
# 1. Setup any file watchers you want with .watch and #watch.
|
@@ -366,16 +366,23 @@ class ConfigSkeleton < ServiceSkeleton
|
|
366
366
|
# Run code before the config is regenerated and the config_file
|
367
367
|
# is written.
|
368
368
|
#
|
369
|
+
# @param force_reload [Boolean] Whether the regenerate_config was called with force_reload
|
370
|
+
# @param existing_config_hash [String] MD5 hash of the config file before regeneration.
|
371
|
+
#
|
369
372
|
# @note this can optionally be implemented by subclasses.
|
370
373
|
#
|
371
|
-
def before_regenerate_config(force_reload); end
|
374
|
+
def before_regenerate_config(force_reload:, existing_config_hash:); end
|
372
375
|
|
373
|
-
# Run code after the config is regenerated and
|
374
|
-
#
|
376
|
+
# Run code after the config is regenerated and potentially a new file is written.
|
377
|
+
#
|
378
|
+
# @param force_reload [Boolean] Whether the regenerate_config was called with force_reload
|
379
|
+
# @param config_was_different [Boolean] Whether the diff of the old and new config was different.
|
380
|
+
# @param config_was_cycled [Boolean] Whether a new config file was cycled in.
|
381
|
+
# @param new_config_hash [String] MD5 hash of the new config file after write.
|
375
382
|
#
|
376
383
|
# @note this can optionally be implemented by subclasses.
|
377
384
|
#
|
378
|
-
def after_regenerate_config(force_reload); end
|
385
|
+
def after_regenerate_config(force_reload:, config_was_different:, config_was_cycled:, new_config_hash:); end
|
379
386
|
|
380
387
|
# Verify that the currently running config is acceptable.
|
381
388
|
#
|
@@ -458,7 +465,8 @@ class ConfigSkeleton < ServiceSkeleton
|
|
458
465
|
# @return [void]
|
459
466
|
#
|
460
467
|
def regenerate_config(force_reload: false)
|
461
|
-
|
468
|
+
existing_config_hash = Digest::MD5.hexdigest(File.read(config_file))
|
469
|
+
before_regenerate_config(force_reload: force_reload, existing_config_hash: existing_config_hash)
|
462
470
|
|
463
471
|
logger.debug(logloc) { "force? #{force_reload.inspect}" }
|
464
472
|
tmpfile = Tempfile.new(service_name, File.dirname(config_file))
|
@@ -466,25 +474,38 @@ class ConfigSkeleton < ServiceSkeleton
|
|
466
474
|
unless (new_config = instrumented_config_data).nil?
|
467
475
|
File.write(tmpfile.path, new_config)
|
468
476
|
tmpfile.close
|
469
|
-
|
477
|
+
|
478
|
+
new_config_hash = Digest::MD5.hexdigest(File.read(tmpfile.path))
|
479
|
+
logger.debug(logloc) do
|
480
|
+
"Existing config hash: #{existing_config_hash}, new config hash: #{new_config_hash}"
|
481
|
+
end
|
470
482
|
|
471
483
|
match_perms(config_file, tmpfile.path)
|
472
484
|
|
473
|
-
diff = Diffy::Diff.new(config_file, tmpfile.path, source: 'files', context: 3, include_diff_info: true)
|
474
|
-
|
475
|
-
|
485
|
+
diff = Diffy::Diff.new(config_file, tmpfile.path, source: 'files', context: 3, include_diff_info: true).to_s
|
486
|
+
config_was_different = diff != ""
|
487
|
+
|
488
|
+
if config_was_different
|
489
|
+
logger.info(logloc) { "Config has changed. Diff:\n#{diff}" }
|
476
490
|
end
|
477
491
|
|
478
492
|
if force_reload
|
479
493
|
logger.debug(logloc) { "Forcing config reload because force_reload == true" }
|
480
494
|
end
|
481
495
|
|
482
|
-
|
496
|
+
config_was_cycled = false
|
497
|
+
if force_reload || config_was_different
|
483
498
|
cycle_config(tmpfile.path)
|
499
|
+
config_was_cycled = true
|
484
500
|
end
|
485
501
|
end
|
486
502
|
|
487
|
-
after_regenerate_config(
|
503
|
+
after_regenerate_config(
|
504
|
+
force_reload: force_reload,
|
505
|
+
config_was_different: config_was_different,
|
506
|
+
config_was_cycled: config_was_cycled,
|
507
|
+
new_config_hash: new_config_hash
|
508
|
+
)
|
488
509
|
ensure
|
489
510
|
metrics.last_change_timestamp.set({}, File.stat(config_file).mtime.to_f)
|
490
511
|
tmpfile.close rescue nil
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_skeleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
|
+
- Discourse Team
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: diffy
|
@@ -195,6 +196,7 @@ dependencies:
|
|
195
196
|
description:
|
196
197
|
email:
|
197
198
|
- matt.palmer@discourse.org
|
199
|
+
- team@discourse.org
|
198
200
|
executables: []
|
199
201
|
extensions: []
|
200
202
|
extra_rdoc_files: []
|