Skip to content

Commit 81c95c4

Browse files
authored
Add Capistrano task to remove application from the load balancer. (#1048)
* Add Capistrano task to remove application from the load balancer. Closes #1041 * Still log.
1 parent 49a1daf commit 81c95c4

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ gem "datacite", github: "sul-dlss/datacite-ruby", branch: "main"
6161
gem "dogstatsd-ruby"
6262
gem "flipflop"
6363
gem "google-protobuf", "~> 3.25"
64-
gem "health-monitor-rails"
64+
gem "health-monitor-rails", "12.4.0"
6565
gem "honeybadger"
6666
gem "mailcatcher"
6767
gem "net-http-persistent"

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ GEM
217217
google-protobuf (3.25.5-x86_64-linux)
218218
hashdiff (1.1.0)
219219
hashie (5.0.0)
220-
health-monitor-rails (12.1.0)
220+
health-monitor-rails (12.4.0)
221221
railties (>= 6.1)
222222
honeybadger (5.10.2)
223223
i18n (1.14.6)
@@ -557,7 +557,7 @@ DEPENDENCIES
557557
ffaker
558558
flipflop
559559
google-protobuf (~> 3.25)
560-
health-monitor-rails
560+
health-monitor-rails (= 12.4.0)
561561
honeybadger
562562
importmap-rails
563563
jbuilder

config/deploy.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,37 @@
2121
end
2222
after "deploy:log_revision", "write_version"
2323

24+
namespace :application do
25+
# You can/ should apply this command to a single host
26+
# cap --hosts=tigerdata-staging1.lib.princeton.edu staging application:remove_from_nginx
27+
desc "Marks the server(s) to be removed from the loadbalancer"
28+
task :remove_from_nginx do
29+
count = 0
30+
on roles(:app) do
31+
count += 1
32+
end
33+
if count > (roles(:app).length / 2)
34+
raise "You must run this command on no more than half the servers utilizing the --hosts= switch"
35+
end
36+
on roles(:app) do
37+
within release_path do
38+
execute :touch, "public/remove-from-nginx"
39+
end
40+
end
41+
end
42+
43+
# You can/ should apply this command to a single host
44+
# cap --hosts=tigerdata-staging1.lib.princeton.edu staging application:serve_from_nginx
45+
desc "Marks the server(s) to be added back to the loadbalancer"
46+
task :serve_from_nginx do
47+
on roles(:app) do
48+
within release_path do
49+
execute :rm, "-f public/remove-from-nginx"
50+
end
51+
end
52+
end
53+
end
54+
2455
# rubocop:disable Rails/Output
2556
namespace :mailcatcher do
2657
desc "Opens Mailcatcher Consoles"

config/initializers/health_monitor.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
HealthMonitor.configure do |config|
44
config.cache
55

6+
config.file_absence.configure do |file_config|
7+
file_config.filename = "public/remove-from-nginx"
8+
end
69
# Mediaflux check
710
config.add_custom_provider(MediafluxStatus)
811

@@ -11,7 +14,9 @@
1114

1215
config.error_callback = proc do |e|
1316
Rails.logger.error "Health check failed with: #{e.message}"
14-
Honeybadger.notify(e)
17+
unless e.is_a?(HealthMonitor::Providers::FileAbsenceException)
18+
Honeybadger.notify(e)
19+
end
1520
end
1621
end
1722
end

0 commit comments

Comments
 (0)