config_o_mat 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +26 -0
  7. data/Gemfile.lock +56 -0
  8. data/LICENSE +202 -0
  9. data/NOTICE +2 -0
  10. data/README.md +15 -0
  11. data/Rakefile +35 -0
  12. data/bin/config_o_mat-configurator +49 -0
  13. data/bin/config_o_mat-meta_configurator +49 -0
  14. data/config_o_mat.gemspec +49 -0
  15. data/design/configurator_lifecycle_test.dot +91 -0
  16. data/design/original_design.md +45 -0
  17. data/lib/config_o_mat/configurator/cond/first_run.rb +29 -0
  18. data/lib/config_o_mat/configurator/cond/next_state.rb +29 -0
  19. data/lib/config_o_mat/configurator/cond/profiles_to_apply.rb +29 -0
  20. data/lib/config_o_mat/configurator/cond/retries_left.rb +37 -0
  21. data/lib/config_o_mat/configurator/cond/services_to_reload.rb +29 -0
  22. data/lib/config_o_mat/configurator/cond.rb +17 -0
  23. data/lib/config_o_mat/configurator/memory.rb +93 -0
  24. data/lib/config_o_mat/configurator/op/apply_all_profiles.rb +35 -0
  25. data/lib/config_o_mat/configurator/op/commit_staged_profile.rb +35 -0
  26. data/lib/config_o_mat/configurator/op/compile_templates.rb +41 -0
  27. data/lib/config_o_mat/configurator/op/connect_to_appconfig.rb +35 -0
  28. data/lib/config_o_mat/configurator/op/generate_all_templates.rb +66 -0
  29. data/lib/config_o_mat/configurator/op/next_tick.rb +48 -0
  30. data/lib/config_o_mat/configurator/op/notify_systemd_start.rb +29 -0
  31. data/lib/config_o_mat/configurator/op/parse_cli.rb +93 -0
  32. data/lib/config_o_mat/configurator/op/refresh_all_profiles.rb +63 -0
  33. data/lib/config_o_mat/configurator/op/refresh_profile.rb +65 -0
  34. data/lib/config_o_mat/configurator/op/reload_one_service.rb +73 -0
  35. data/lib/config_o_mat/configurator/op/stage_one_profile.rb +33 -0
  36. data/lib/config_o_mat/configurator/op/wait_retry.rb +41 -0
  37. data/lib/config_o_mat/configurator/op.rb +17 -0
  38. data/lib/config_o_mat/configurator.rb +122 -0
  39. data/lib/config_o_mat/flip_flopper/cond/service_status.rb +29 -0
  40. data/lib/config_o_mat/flip_flopper/cond.rb +17 -0
  41. data/lib/config_o_mat/flip_flopper/memory.rb +51 -0
  42. data/lib/config_o_mat/flip_flopper/op/check_service_status.rb +72 -0
  43. data/lib/config_o_mat/flip_flopper/op/determine_running_instance.rb +56 -0
  44. data/lib/config_o_mat/flip_flopper/op/report_failure.rb +36 -0
  45. data/lib/config_o_mat/flip_flopper/op/start_activating_instance.rb +34 -0
  46. data/lib/config_o_mat/flip_flopper/op/stop_activating_instance.rb +34 -0
  47. data/lib/config_o_mat/flip_flopper/op/stop_initial_instance.rb +34 -0
  48. data/lib/config_o_mat/flip_flopper/op.rb +17 -0
  49. data/lib/config_o_mat/flip_flopper.rb +46 -0
  50. data/lib/config_o_mat/meta_configurator/memory.rb +73 -0
  51. data/lib/config_o_mat/meta_configurator/op/generate_systemd_config.rb +80 -0
  52. data/lib/config_o_mat/meta_configurator/op/parse_meta_cli.rb +103 -0
  53. data/lib/config_o_mat/meta_configurator/op.rb +17 -0
  54. data/lib/config_o_mat/meta_configurator.rb +44 -0
  55. data/lib/config_o_mat/shared/cond/early_exit.rb +29 -0
  56. data/lib/config_o_mat/shared/cond.rb +17 -0
  57. data/lib/config_o_mat/shared/op/load_meta_config.rb +188 -0
  58. data/lib/config_o_mat/shared/op.rb +17 -0
  59. data/lib/config_o_mat/shared/systemd_interface.rb +93 -0
  60. data/lib/config_o_mat/shared/types.rb +248 -0
  61. data/lib/config_o_mat/version.rb +19 -0
  62. data/lib/version.rb +19 -0
  63. data/systemd/teak-configurator-restart-service@.path +27 -0
  64. data/systemd/teak-configurator-restart-service@.service +21 -0
  65. data/systemd/teak-configurator-start-service@.path +27 -0
  66. data/systemd/teak-configurator-start-service@.service +21 -0
  67. data/systemd/teak-configurator-stop-service@.path +27 -0
  68. data/systemd/teak-configurator-stop-service@.service +21 -0
  69. data/systemd/teak-configurator.service +68 -0
  70. data/systemd/teak-metaconfigurator.service +57 -0
  71. metadata +213 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4f7f711f4b074d2c732ce431dfd678df82d8fe579ba8da5f9035937af9f278f4
4
+ data.tar.gz: 8540f7ffdaa0e2474b0a00a9ade88c912e9babbd9b41b5ff43c6ece58b8f64e6
5
+ SHA512:
6
+ metadata.gz: ae17e8208db65c89c8c0ad943d7ec55a1decf711cab1a1692beccf6a593307548a59b231bd1957780de7f44c18a43ac6718ef9db22ce7fb43dd347dee179cf8e
7
+ data.tar.gz: f5810b31cc743ceb07622b1db928f4db28f39bd593d94ba3e73004d90d8e9b0e9c274de28cf84502e21098c20812df4ad3ffa0dea067ddd82d0d111dfa94eda9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ # rspec persistence data
2
+ spec/rspec_persistence.txt
3
+
4
+ # test coverage data
5
+ coverage/
6
+
7
+ # YARD doc db and output
8
+ .yardoc/
9
+ doc/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ configurator
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.4
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Teak.io, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ source 'https://rubygems.org'
18
+
19
+ gem 'aws-sdk-appconfig', '~> 1.18', require: false
20
+ gem 'logsformyfamily', '~> 0.2', require: false
21
+ gem 'lifecycle_vm', '~> 0.1.1', require: false
22
+ gem 'ruby-dbus', '~> 0.16.0', require: false
23
+ gem 'sd_notify', '~> 0.1', require: false
24
+
25
+ gem 'rspec', '~> 3.10', group: :test, require: false
26
+ gem 'simplecov', '~> 0.21', group: :test, require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ aws-eventstream (1.2.0)
5
+ aws-partitions (1.525.0)
6
+ aws-sdk-appconfig (1.19.0)
7
+ aws-sdk-core (~> 3, >= 3.122.0)
8
+ aws-sigv4 (~> 1.1)
9
+ aws-sdk-core (3.122.0)
10
+ aws-eventstream (~> 1, >= 1.0.2)
11
+ aws-partitions (~> 1, >= 1.525.0)
12
+ aws-sigv4 (~> 1.1)
13
+ jmespath (~> 1.0)
14
+ aws-sigv4 (1.4.0)
15
+ aws-eventstream (~> 1, >= 1.0.2)
16
+ diff-lcs (1.4.4)
17
+ docile (1.4.0)
18
+ jmespath (1.4.0)
19
+ lifecycle_vm (0.1.2)
20
+ logsformyfamily (0.2.3)
21
+ rspec (3.10.0)
22
+ rspec-core (~> 3.10.0)
23
+ rspec-expectations (~> 3.10.0)
24
+ rspec-mocks (~> 3.10.0)
25
+ rspec-core (3.10.1)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-expectations (3.10.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-mocks (3.10.2)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-support (3.10.3)
34
+ ruby-dbus (0.16.0)
35
+ sd_notify (0.1.1)
36
+ simplecov (0.21.2)
37
+ docile (~> 1.1)
38
+ simplecov-html (~> 0.11)
39
+ simplecov_json_formatter (~> 0.1)
40
+ simplecov-html (0.12.3)
41
+ simplecov_json_formatter (0.1.3)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ aws-sdk-appconfig (~> 1.18)
48
+ lifecycle_vm (~> 0.1.1)
49
+ logsformyfamily (~> 0.2)
50
+ rspec (~> 3.10)
51
+ ruby-dbus (~> 0.16.0)
52
+ sd_notify (~> 0.1)
53
+ simplecov (~> 0.21)
54
+
55
+ BUNDLED WITH
56
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ configurator
2
+ Copyright 2021 Teak.io, Inc.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Configurator
2
+
3
+ Configurator manages runtime configuration of services by reading data from AWS AppConfig and AWS SecretsManager, rendering ERB templates with that data, and then restarting systemd services to apply configuration updates.
4
+
5
+ ## Usage
6
+ Configurator requires two pieces of meta configuration to start
7
+ - A configuration directory in $CONFIGURATION_DIRECTORY or passed in with -c/--configuration-directory
8
+ - A runtime directory in $RUNTIME_DIRECTORY or passed in with -r/--runtime-directory
9
+
10
+ Configurator will read all and apply files ending in .conf in the configuration directory in lexical order to configure itself.
11
+
12
+ Configuration files are in YAML. Configurator will read the following keys:
13
+
14
+ log_level: # One of debug, info, notice, warn, error. Defaults to info.
15
+ refresh_interval: # Number of seconds between each configuration source poll. Defaults to 5
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Teak.io, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ begin
18
+ require 'rspec/core/rake_task'
19
+ RSpec::Core::RakeTask.new(:spec)
20
+ rescue LoadError
21
+ # No rspec here
22
+ end
23
+
24
+ begin
25
+ require 'yard'
26
+
27
+ YARD::Rake::YardocTask.new(:doc) do |t|
28
+ t.files = ['lib/**/*.rb']
29
+ t.stats_options = ['--list-undoc']
30
+ end
31
+ rescue LoadError
32
+ # No doc generation for you
33
+ end
34
+
35
+ require "bundler/gem_tasks"
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2021 Teak.io, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'config_o_mat/configurator'
18
+ require 'logsformyfamily'
19
+
20
+ LogsForMyFamily.configure do |config|
21
+ config.version = ConfigOMat::Configurator::VM::VERSION
22
+ config.app_name = ConfigOMat::Configurator::VM.name
23
+ end
24
+
25
+ logger = LogsForMyFamily::Logger.new
26
+ logger.backends = [ConfigOMat::StdoutLogWriter.new]
27
+ log_level = ENV['CONFIG_O_MAT_LOG_LEVEL']&.to_sym
28
+ if log_level && LogsForMyFamily::Logger::LEVELS.include?(log_level)
29
+ logger.filter_level(log_level)
30
+ elsif log_level
31
+ warn "Unknown log level requested in CONFIG_O_MAT_LOG_LEVEL: #{log_level}"
32
+ end
33
+
34
+ memory = ConfigOMat::Configurator::Memory.new(argv: ARGV, env: ENV, logger: logger)
35
+ vm = ConfigOMat::Configurator::VM.new(memory)
36
+ vm.call
37
+
38
+ if vm.errors?
39
+ warn "Errored executing #{vm.error_op.class.name}"
40
+ warn "Errors: #{vm.errors}"
41
+
42
+ if vm.recovery_errors?
43
+ warn ''
44
+ warn "Errors recovering from error. Errored executing recovery #{vm.current_op.class.name}"
45
+ warn "Errors: #{vm.recovery_errors}"
46
+ end
47
+
48
+ exit 1
49
+ end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2021 Teak.io, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'config_o_mat/meta_configurator'
18
+ require 'logsformyfamily'
19
+
20
+ LogsForMyFamily.configure do |config|
21
+ config.version = ConfigOMat::MetaConfigurator::VM::VERSION
22
+ config.app_name = ConfigOMat::MetaConfigurator::VM.name
23
+ end
24
+
25
+ logger = LogsForMyFamily::Logger.new
26
+ logger.backends = [ConfigOMat::StdoutLogWriter.new]
27
+ log_level = ENV['CONFIG_O_MAT_LOG_LEVEL']&.to_sym
28
+ if log_level && LogsForMyFamily::Logger::LEVELS.include?(log_level)
29
+ logger.filter_level(log_level)
30
+ elsif log_level
31
+ warn "Unknown log level requested in CONFIG_O_MAT_LOG_LEVEL: #{log_level}"
32
+ end
33
+
34
+ memory = ConfigOMat::MetaConfigurator::Memory.new(argv: ARGV, env: ENV, logger: logger)
35
+ vm = ConfigOMat::MetaConfigurator::VM.new(memory)
36
+ vm.call
37
+
38
+ if vm.errors?
39
+ warn "Errored executing #{vm.error_op.class.name}"
40
+ warn "Errors: #{vm.errors}"
41
+
42
+ if vm.recovery_errors?
43
+ warn ''
44
+ warn "Errors recovering from error. Errored executing recovery #{vm.current_op.class.name}"
45
+ warn "Errors: #{vm.recovery_errors}"
46
+ end
47
+
48
+ exit 1
49
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Teak.io, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative 'lib/config_o_mat/version'
18
+
19
+ Gem::Specification.new do |spec|
20
+ spec.name = "config_o_mat"
21
+ spec.version = ConfigOMat::VERSION
22
+ spec.authors = ["Alex Scarborough"]
23
+ spec.email = ["alex@teak.io"]
24
+
25
+ spec.summary = "ConfigOMat applies AWS AppConfig to Systemd services."
26
+ spec.homepage = "https://github.com/GoCarrot/configurator"
27
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
28
+
29
+ spec.metadata["homepage_uri"] = spec.homepage
30
+ spec.metadata["source_code_uri"] = "https://github.com/GoCarrot/configurator"
31
+
32
+ # Specify which files should be added to the gem when it is released.
33
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
35
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|script)/}) }
36
+ end
37
+
38
+ spec.require_paths = ["lib"]
39
+ spec.executables = ["config_o_mat-configurator", "config_o_mat-meta_configurator"]
40
+
41
+ spec.add_dependency('aws-sdk-appconfig', '~> 1.18')
42
+ spec.add_dependency('logsformyfamily', '~> 0.2')
43
+ spec.add_dependency('lifecycle_vm', '~> 0.1.1')
44
+ spec.add_dependency('ruby-dbus', '~> 0.16.0')
45
+ spec.add_dependency('sd_notify', '~> 0.1.1')
46
+
47
+ spec.add_development_dependency('simplecov', '~> 0.21.2')
48
+ spec.add_development_dependency('rspec', '~> 3.10')
49
+ end
@@ -0,0 +1,91 @@
1
+ digraph "configurator_lifecycle_test"
2
+ {
3
+ bgcolor = "#ffffff"
4
+
5
+ node [
6
+ class = "node"
7
+ ,fillcolor = "#ffffff",style = "filled"
8
+ ,shape = "rect"
9
+ ,"_vis_" = "label"
10
+ ];
11
+
12
+ subgraph {
13
+ "reading_meta_config" []
14
+
15
+ rank = "source"
16
+ }
17
+
18
+ "Config Error?" [label="Config Error?", shape="diamond"]
19
+ "running" []
20
+
21
+ subgraph {
22
+ "applying_profiles" []
23
+ "initial_applying_profiles" []
24
+ rank = "same"
25
+ }
26
+
27
+ "refreshing_profiles" []
28
+ "Refresh Error?" [label="Refresh Error?", shape="diamond"]
29
+
30
+ "applying_profile" []
31
+ "First Run?" [label="First Run?", shape="diamond"]
32
+ "generating_templates" []
33
+ "Template Error?" [label="Template Error?", shape="diamond"]
34
+ "Profiles to Apply?" [label="Profiles to Apply?", shape="diamond"]
35
+
36
+ "reloading_services" []
37
+ "Services to Reload?" [label="Services to Reload?", shape="diamond"]
38
+ "reloading_service" []
39
+ "Reload Error?" [label="Reload Error?", shape="diamond"]
40
+
41
+ "pending_failure" []
42
+ "First Run PF" [label="First Run?", shape="diamond"]
43
+ "Retries Left?" [label="Retries Left?", shape="diamond"]
44
+ "refreshing_profile" []
45
+
46
+ subgraph {
47
+ "FAIL" []
48
+ "EXIT" []
49
+ rank = "sink"
50
+ }
51
+
52
+ edge [
53
+ class = "edge"
54
+ ,weight = "1"
55
+ ,penwidth = "1"
56
+ ,"_vis_" = "label"
57
+ ,"color" = "#a0a0a4"
58
+ ,"style" = "solid"
59
+ ];
60
+
61
+ "reading_meta_config" -> "Config Error?"
62
+ "Config Error?" -> "pending_failure" [label="Yes", color="red"]
63
+ "Config Error?" -> "refreshing_profiles" [label="No", color="green"]
64
+ "refreshing_profiles" -> "First Run?"
65
+ "Refresh Error?" -> "pending_failure" [label="Yes", color="red"]
66
+ "Refresh Error?" -> "generating_templates" [label="No", color="green"]
67
+ "First Run?" -> "initial_applying_profiles" [label="Yes"]
68
+ "First Run?" -> "applying_profiles" [label="No"]
69
+ "initial_applying_profiles" -> "Refresh Error?"
70
+ "generating_templates" -> "Template Error?"
71
+ "Template Error?" -> "reloading_services" [label="No", color="green"]
72
+ "Template Error?" -> "pending_failure" [label="Yes", color="red"]
73
+ "reloading_services" -> "Services to Reload?"
74
+ "Services to Reload?" -> "reloading_service" [label="Yes"]
75
+ "Services to Reload?" -> "applying_profiles" [label="No"]
76
+ "reloading_service" -> "Reload Error?"
77
+ "Reload Error?" -> "reloading_services" [label="No", color="green"]
78
+ "Reload Error?" -> "pending_failure" [label="Yes", color="red"]
79
+ "applying_profiles" -> "Profiles to Apply?"
80
+ "Profiles to Apply?" -> "applying_profile" [label="Yes"]
81
+ "Profiles to Apply?"-> "running" [label="No", constraint=false]
82
+ "applying_profile" -> "Refresh Error?"
83
+ "pending_failure" -> "First Run PF"
84
+ "First Run PF" -> "FAIL" [label="Yes"]
85
+ "First Run PF" -> "Retries Left?" [label="No", color="green"]
86
+ "Retries Left?" -> "FAIL" [label="No", color="red"]
87
+ "Retries Left?" -> "refreshing_profile" [label="Yes"]
88
+ "refreshing_profile" -> "applying_profile"
89
+ "running" -> "refreshing_profiles"
90
+ "running" -> "EXIT"
91
+ }
@@ -0,0 +1,45 @@
1
+ Configurator
2
+
3
+ Object Types:
4
+
5
+ Service -- A systemd service that is configured/managed by the configurator
6
+ ConfigurationProfile -- An AWS AppConfig configuration that the configurator retrieves
7
+ Template -- A template file that the configurator will use to generate an updated configuration file
8
+
9
+ Lifecycle:
10
+ OnBoot
11
+ Each ConfigurationProfile will be loaded in declaration order. Once all ConfigurationProfiles are fully loaded, each Template will be evaluated. Once all Templates are evaluated, the configurator will go through each Service in declaration order and trigger a configuration update. Configuration updates are synchronus -- the configurator will not proceed to the next service until it has confirmed that configuration has been applied to the current service. If a service is not currently running then a configuration update will be considered successful immediately after updating configuration files.
12
+
13
+ ConfigurationProfileLoad
14
+ The configuration profile will be loaded from AWS AppConfig. Any ancillary data defined by the loaded profile, e.g. secrets, will then be loaded. If any step fails the configurator will enter the OnPendingFailure state with the given ConfigurationProfile.
15
+
16
+ Every RefreshInterval
17
+ Each ConfigurationProfile will be refreshed in declaration order. If a ConfigurationProfile is updated, Templates which reference that profile will be reevaluated. Once all such Templates are reevaluated, any which change will trigger configuration updates for any referencing Services in declaration order. All steps are synchronous, that is if a ConfigurationProfile has an update the configurator will _stop_ refreshing other profiles until all changes from the updated ConfigurationProfile have been successfully applied, and if multiple Services reference a Template each service must successfully complete its reload before the configurator will refresh the next Service.
18
+
19
+ ConfigurationUpdate
20
+ Configuration updates are applied atomically. That is, if updating a single ConfigurationProfile modifies multiple Templates, the configurator will not apply changes until _all_ such Templates have been updated. Similarily if a modification to a Template requires multiple Services to be reloaded the configurator will not start reloading a Service until the prior Service reload is complete and successful. If any Service reload fails in the process of applying a ConfigurationUpdate, the source ConfigurationProfile will be considered to have failed and the configurator will
21
+ 1. Roll back the faulty ConfigurationProfile
22
+ 2. Perform a ConfigurationUpdate with the rolled back ConfigurationProfile
23
+ 3. In some way indicate failure such that AWS AppConfig can determine a course of action
24
+
25
+ OnPendingFailure
26
+ If a ConfigurationUpdate fails, the configurator enters a "pending failure" state. When pending failure, the configurator will exclusively refresh the ConfigurationProfile which triggered the failed ConfigurationUpdate. If the ConfigurationProfile does not receive any updates (including a rollback by AWS AppConfig) within FailureTimeout, the configurator will itself enter a failure state and trigger its systemd OnFailure action. N.B. This may include systemd initiated restarts of the configurator.
27
+
28
+ State:
29
+ For each ConfigurationProfile the configurator will persistently store the most recently successfully applied version and the most recently retrieved version. If the configurator starts with state present, and any ConfigurationProfile has a retrieved version that does not equal its applied version, the configurator will immediately refresh the ConfigurationProfile from AWS AppConfig and proceed to ConfigurationUpdate for that ConfigurationProfile.
30
+
31
+ Service reload:
32
+ A Service may define one of the following ways to apply its updated configuration
33
+ - try-reload-or-restart
34
+ This will use systemd to try-reload-or-restart the managed service. By default this will be considered successful if the try-reload-or-restart operation succeeds.
35
+ - flip-flpp
36
+ This will use a custom script to manage an instantiated service unit with the instances @1 and @2. If both instances are running at the time of the reload, the configurator will enter OnPendingFailure. Otherwise the configurator will bring up the instance which is not currently running. By default if starting that instance succeeds then the configurator will stop the old instance and consider the reload successful.
37
+
38
+ A Service may also define additional health checks to verify that configuration reload both took effect and is a "good" configuration
39
+ - change-child-pid
40
+ The configurator will monitor the set of child pids for the service's MAINPID for changes. If no changes occur (that is the service does not rotate its children) within ReloadTimeout then the configurator will enter OnPendingFailure. If the service has no child pids then the configurator will enter OnPendingFailure.
41
+ - unicorn-health-comparison
42
+ The configurator will read health data from both active unicorn masters after BakeTime. If the new master is failing notably more requests than the previous master, the configurator will enter OnPendingFailure.
43
+
44
+ Communicating with systemd:
45
+ As Debian 11 still uses a pre-JS version of polkit we can't just grant the configurator limited permissions to manipulate systemd. Instead, we use a set of signal files monitored with systemd path units to trigger actions in systemd.