Skip to content

Commit

Permalink
Add Capistrano task to remove application from the load balancer. (#1048
Browse files Browse the repository at this point in the history
)

* Add Capistrano task to remove application from the load balancer.

Closes #1041

* Still log.
  • Loading branch information
tpendragon authored Nov 14, 2024
1 parent 49a1daf commit 81c95c4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ gem "datacite", github: "sul-dlss/datacite-ruby", branch: "main"
gem "dogstatsd-ruby"
gem "flipflop"
gem "google-protobuf", "~> 3.25"
gem "health-monitor-rails"
gem "health-monitor-rails", "12.4.0"
gem "honeybadger"
gem "mailcatcher"
gem "net-http-persistent"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ GEM
google-protobuf (3.25.5-x86_64-linux)
hashdiff (1.1.0)
hashie (5.0.0)
health-monitor-rails (12.1.0)
health-monitor-rails (12.4.0)
railties (>= 6.1)
honeybadger (5.10.2)
i18n (1.14.6)
Expand Down Expand Up @@ -557,7 +557,7 @@ DEPENDENCIES
ffaker
flipflop
google-protobuf (~> 3.25)
health-monitor-rails
health-monitor-rails (= 12.4.0)
honeybadger
importmap-rails
jbuilder
Expand Down
31 changes: 31 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,37 @@
end
after "deploy:log_revision", "write_version"

namespace :application do
# You can/ should apply this command to a single host
# cap --hosts=tigerdata-staging1.lib.princeton.edu staging application:remove_from_nginx
desc "Marks the server(s) to be removed from the loadbalancer"
task :remove_from_nginx do
count = 0
on roles(:app) do
count += 1
end
if count > (roles(:app).length / 2)
raise "You must run this command on no more than half the servers utilizing the --hosts= switch"
end
on roles(:app) do
within release_path do
execute :touch, "public/remove-from-nginx"
end
end
end

# You can/ should apply this command to a single host
# cap --hosts=tigerdata-staging1.lib.princeton.edu staging application:serve_from_nginx
desc "Marks the server(s) to be added back to the loadbalancer"
task :serve_from_nginx do
on roles(:app) do
within release_path do
execute :rm, "-f public/remove-from-nginx"
end
end
end
end

# rubocop:disable Rails/Output
namespace :mailcatcher do
desc "Opens Mailcatcher Consoles"
Expand Down
7 changes: 6 additions & 1 deletion config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
HealthMonitor.configure do |config|
config.cache

config.file_absence.configure do |file_config|
file_config.filename = "public/remove-from-nginx"
end
# Mediaflux check
config.add_custom_provider(MediafluxStatus)

Expand All @@ -11,7 +14,9 @@

config.error_callback = proc do |e|
Rails.logger.error "Health check failed with: #{e.message}"
Honeybadger.notify(e)
unless e.is_a?(HealthMonitor::Providers::FileAbsenceException)
Honeybadger.notify(e)
end
end
end
end

0 comments on commit 81c95c4

Please sign in to comment.