Skip to content

Commit

Permalink
Add capistrano task to remove application from the load balancer. (#716)
Browse files Browse the repository at this point in the history
Closes #715
  • Loading branch information
tpendragon authored Nov 14, 2024
1 parent 636f906 commit 38977af
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gem 'bootstrap', '~> 4.0'
gem 'devise'
gem 'devise-guests', '~> 0.6'
gem 'faraday_middleware'
gem 'health-monitor-rails'
gem 'health-monitor-rails', '12.4.0'
gem 'honeybadger'
gem 'httparty'
gem 'jbuilder', '~> 2.7'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ GEM
activesupport (>= 6.1)
hashdiff (1.1.1)
hashie (5.0.0)
health-monitor-rails (12.3.0)
health-monitor-rails (12.4.0)
railties (>= 6.1)
honeybadger (5.16.0)
logger
Expand Down Expand Up @@ -636,7 +636,7 @@ DEPENDENCIES
ed25519
faraday_middleware
foreman
health-monitor-rails
health-monitor-rails (= 12.4.0)
honeybadger
httparty
jbuilder (~> 2.7)
Expand Down
32 changes: 31 additions & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@
# Uncomment to re-index on every deploy. Only needed when we're actively
# updating how indexing happens.
# after "deploy:published", "pdc_discovery:reindex"
namespace :application do
# You can/ should apply this command to a single host
# cap --hosts=pdc-discovery-staging1.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=pdc-discovery-staging1.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

namespace :mailcatcher do
desc "Opens Mailcatcher Consoles"
Expand All @@ -47,4 +77,4 @@
end
end
end
end
end
9 changes: 7 additions & 2 deletions 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
config.solr.configure do |c|
c.url = Blacklight.default_index.connection.uri.to_s
c.collection = Blacklight.default_index.connection.uri.path.split("/").last
Expand All @@ -12,8 +15,10 @@
config.path = :health

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)
Rails.logger.error "Health check failed with: #{e.message}"
Honeybadger.notify(e)
end
end
end
end

0 comments on commit 38977af

Please sign in to comment.