Class: EtFullSystem::LocalCommand
- Inherits:
-
Thor
- Object
- Thor
- EtFullSystem::LocalCommand
show all
- Defined in:
- lib/et_full_system/cli/local.rb
Defined Under Namespace
Classes: RestProviderNotConfigured, ServiceUrlIncorrect, ServicesNotConfigured
Constant Summary
collapse
- DEFAULT_BASE_URL =
"http://localhost:3200"
- LOCK_FILE =
File.join(Dir.tmpdir, 'et_full_system_traefik_rest_lockfile')
- PROJECT_PATH =
Dir.pwd
- GEM_PATH =
File.absolute_path('../../..', __dir__)
Instance Method Summary
collapse
Instance Method Details
#boot ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/et_full_system/cli/local.rb', line 22
def boot
STDERR.puts "boot - base_url is #{options[:base_url]}"
json_setup_file = File.absolute_path('../../../foreman/traefik.json', __dir__)
connect_retry_countdown = 10
begin
resp = HTTParty.put "#{options[:base_url]}/api/providers/rest", body: File.read(json_setup_file) , headers: {'Content-Type': 'application/json', 'Accept': 'application/json'}
raise "Error from traefik when performing initial config says: #{resp.body}" unless (200..299).include? resp.code
sleep 1
rescue Errno::EADDRNOTAVAIL, Errno::ECONNREFUSED
connect_retry_countdown -= 1
if connect_retry_countdown.zero?
raise "Could not connect to the traefik API after 10 retries (boot)"
else
STDERR.puts "boot - Retrying connection to traefik API in 5 seconds"
sleep 5
retry
end
end
end
|
#disable_admin ⇒ Object
279
280
281
282
|
# File 'lib/et_full_system/cli/local.rb', line 279
def disable_admin
invoker 'remove', 'admin_web'
puts "Admin is now stopped"
end
|
#disable_api ⇒ Object
272
273
274
275
276
|
# File 'lib/et_full_system/cli/local.rb', line 272
def disable_api
invoker 'remove', 'api_web'
invoker 'remove', 'api_sidekiq'
puts "api is now stopped"
end
|
#disable_atos_api ⇒ Object
266
267
268
269
|
# File 'lib/et_full_system/cli/local.rb', line 266
def disable_atos_api
invoker 'remove', 'atos_api_web'
puts "atos_api is now stopped"
end
|
#disable_ccd_export ⇒ Object
260
261
262
263
|
# File 'lib/et_full_system/cli/local.rb', line 260
def disable_ccd_export
invoker 'remove', 'et_ccd_export_sidekiq'
puts "ccd_export is now stopped"
end
|
#disable_et1 ⇒ Object
253
254
255
256
257
|
# File 'lib/et_full_system/cli/local.rb', line 253
def disable_et1
invoker 'remove', 'et1_web'
invoker 'remove', 'et1_sidekiq'
puts "ET1 is now stopped"
end
|
#disable_et3 ⇒ Object
285
286
287
288
|
# File 'lib/et_full_system/cli/local.rb', line 285
def disable_et3
invoker 'remove', 'et3_web'
puts "ET3 is now stopped"
end
|
#enable_admin ⇒ Object
241
242
243
244
|
# File 'lib/et_full_system/cli/local.rb', line 241
def enable_admin
invoker 'add', 'admin_web'
puts "Admin is now running"
end
|
#enable_api ⇒ Object
234
235
236
237
238
|
# File 'lib/et_full_system/cli/local.rb', line 234
def enable_api
invoker 'add', 'api_web'
invoker 'add', 'api_sidekiq'
puts "api is now running"
end
|
#enable_atos_api ⇒ Object
228
229
230
231
|
# File 'lib/et_full_system/cli/local.rb', line 228
def enable_atos_api
invoker 'add', 'atos_api_web'
puts "atos_api is now running"
end
|
#enable_ccd_export ⇒ Object
222
223
224
225
|
# File 'lib/et_full_system/cli/local.rb', line 222
def enable_ccd_export
invoker 'add', 'et_ccd_export_sidekiq'
puts "ccd_export is now running"
end
|
#enable_et1 ⇒ Object
215
216
217
218
219
|
# File 'lib/et_full_system/cli/local.rb', line 215
def enable_et1
invoker 'add', 'et1_web'
invoker 'add', 'et1_sidekiq'
puts "ET1 is now running"
end
|
#enable_et3 ⇒ Object
247
248
249
250
|
# File 'lib/et_full_system/cli/local.rb', line 247
def enable_et3
invoker 'add', 'et3_web'
puts "ET3 is now running"
end
|
#invoker(*args) ⇒ Object
206
207
208
209
210
211
212
|
# File 'lib/et_full_system/cli/local.rb', line 206
def invoker(*args)
cmd = "invoker #{args.join(' ')}"
puts cmd
result = `#{cmd}`
puts result
result
end
|
#restart_admin ⇒ Object
311
312
313
314
|
# File 'lib/et_full_system/cli/local.rb', line 311
def restart_admin
invoker 'reload', 'admin_web'
puts "admin Has been restarted"
end
|
#restart_api ⇒ Object
298
299
300
301
302
|
# File 'lib/et_full_system/cli/local.rb', line 298
def restart_api
invoker 'reload', 'api_web'
invoker 'reload', 'api_sidekiq'
puts "api Has been restarted"
end
|
#restart_atos_api ⇒ Object
317
318
319
320
|
# File 'lib/et_full_system/cli/local.rb', line 317
def restart_atos_api
invoker 'reload', 'atos_api_web'
puts "atos_api Has been restarted"
end
|
#restart_ccd_export ⇒ Object
323
324
325
326
|
# File 'lib/et_full_system/cli/local.rb', line 323
def restart_ccd_export
invoker 'reload', 'et_ccd_export_sidekiq'
puts "ccd_export Has been restarted"
end
|
#restart_et1 ⇒ Object
291
292
293
294
295
|
# File 'lib/et_full_system/cli/local.rb', line 291
def restart_et1
invoker 'reload', 'et1_web'
invoker 'reload', 'et1_sidekiq'
puts "ET1 Has been restarted"
end
|
#restart_et3 ⇒ Object
305
306
307
308
|
# File 'lib/et_full_system/cli/local.rb', line 305
def restart_et3
invoker 'reload', 'et3_web'
puts "et3 Has been restarted"
end
|
#server ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/et_full_system/cli/local.rb', line 99
def server
puts "Scheduling traefik config and file storage config"
pid = fork do
self.class.start(['boot']) unless options.in_docker_compose?
EtFullSystem::Cli::Local::FileStorageCommand.start(['setup'])
end
Process.detach(pid)
puts "Starting Invoker"
unbundled do
without = options[:without]
if options.minimal?
without = ['et1', 'et3', 'admin', 'api', 'ccd_export', 'atos_api']
end
if options.in_docker_compose?
cmd = "RAILS_ENV=#{options[:rails_env]} FS_ROOT_PATH=#{PROJECT_PATH} FOREMAN_PATH=#{GEM_PATH}/foreman godotenv -f #{GEM_PATH}/foreman/.env invoker start \"#{GEM_PATH}/foreman/ComposeProcfile\" --port=4000"
else
cmd = "RAILS_ENV=#{options[:rails_env]} AZURITE_STORAGE_PATH=\"#{options[:azurite_storage_path]}\" FS_ROOT_PATH=#{PROJECT_PATH} FOREMAN_PATH=#{GEM_PATH}/foreman godotenv -f #{GEM_PATH}/foreman/.env invoker start \"#{GEM_PATH}/foreman/Procfile\" --port=4000"
end
STDERR.puts cmd
unless without.empty?
stop_cmds = without.reduce([]) do |acc, service|
acc.concat(invoker_processes_for(service))
end.map do |proc|
"invoker remove #{proc}"
end
stop_cmd = stop_cmds.join(' && ')
puts "---------------------- DISABLING SERVICES IN 30 SECONDS ---------------------------"
puts "command is #{stop_cmd}"
Process.fork do
sleep 30
puts `#{stop_cmd}`
end
end
exec cmd
end
end
|
#service_env(service) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/et_full_system/cli/local.rb', line 187
def service_env(service)
lookup = {
'atos_api' => :et_atos,
'admin' => :et_admin,
'api' => :et_api,
'et1' => :et1,
'et3' => :et3,
'et_ccd_export' => :et_ccd_export
}
file = lookup.fetch(service)
parsed = Dotenv.parse("#{GEM_PATH}/foreman/.env", "#{GEM_PATH}/foreman/#{file}.env")
parsed.each_pair do |name, value|
puts "#{name}=#{value}"
end
rescue KeyError
puts "The service must be one of #{lookup.keys}"
end
|
#setup ⇒ Object
143
144
145
146
147
148
149
|
# File 'lib/et_full_system/cli/local.rb', line 143
def setup
setup_depencencies
install_rvm if options.in_docker_compose? && rvm_required?
install_bundler if rvm_installed?
setup_ruby_versions
setup_services
end
|
#setup_depencencies ⇒ Object
164
165
166
167
168
|
# File 'lib/et_full_system/cli/local.rb', line 164
def setup_depencencies
cmd = "bash --login -c \"cd #{File.join(PROJECT_PATH, 'support', 'fake_services')} && bundle install\""
STDERR.puts cmd
external_command cmd, 'setup_dependencies'
end
|
#setup_ruby_versions ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/et_full_system/cli/local.rb', line 171
def setup_ruby_versions
additional_ruby_versions.each do |version|
puts "------------------------------------------------ SETTING UP ruby #{version} ---------------------------------------------------"
cmds = [
"bash --login -c \"rvm install #{version} --autolibs=disable\"",
"bash --login -c \"rvm use #{version} && gem install bundler:1.17.3 \"",
]
cmds.each do |cmd|
puts cmd
external_command cmd, "ruby #{version} install"
end
end
end
|
#setup_services ⇒ Object
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/et_full_system/cli/local.rb', line 152
def setup_services
unbundled do
setup_et1_service
setup_et3_service
setup_api_service
setup_admin_service
setup_atos_service
setup_ccd_service
end
end
|
#update_service_url(service, url) ⇒ Object
45
46
47
48
49
|
# File 'lib/et_full_system/cli/local.rb', line 45
def update_service_url(service, url)
within_rest_lock do
update_rest_backend_url(service, url)
end
end
|
#wait_for_support ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/et_full_system/cli/local.rb', line 53
def wait_for_support
connect_retry_countdown = 10
setup_retry_countdown = 10
begin
resp = HTTParty.get "#{options[:base_url]}/api/rawdata", headers: {'Content-Type': 'application/json', 'Accept': 'application/json'}
raise RestProviderNotConfigured if resp.code == 404 || resp.parsed_response.dig('routers', 'rest@internal').nil?
raise ServicesNotConfigured if resp.parsed_response.dig('routers', 'et1@rest').nil?
rescue Errno::EADDRNOTAVAIL, Errno::ECONNREFUSED
connect_retry_countdown -= 1
if connect_retry_countdown.zero?
raise "Could not connect to the traefik API after 10 retries (wait_for_support)"
else
STDERR.puts "wait_for_support - Retrying connection to traefik API in 5 seconds"
sleep 5
retry
end
rescue RestProviderNotConfigured
setup_retry_countdown -= 1
if setup_retry_countdown.zero?
raise "Could not find the REST provider in traefik after 10 retries"
else
STDERR.puts "Re checking for the REST provider in traefik in 5 seconds"
sleep 5
retry
end
rescue ServicesNotConfigured
setup_retry_countdown -= 1
if setup_retry_countdown.zero?
raise "Could not find the ET1 router in traefik after 10 retries"
else
STDERR.puts "Re checking for the ET1 router in traefik in 5 seconds"
sleep 5
retry
end
end
STDERR.puts "Support services now ready"
end
|