Skip to content

Commit

Permalink
Merge pull request #2549 from pulibrary/i2546_cap_task_take_app_off_lb
Browse files Browse the repository at this point in the history
Add capistrano tasks to take a node off the load balancer.
  • Loading branch information
tpendragon authored Nov 14, 2024
2 parents f9745a6 + 6a9bb32 commit 5d76fe6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ gem 'faraday_middleware', '~> 1.0'
gem 'ffi', '>= 1.9.25'
gem 'friendly_id'
gem 'gyoku', '~> 1.0'
gem 'health-monitor-rails'
# Pinning to 12.4.0 due to Rails 7.1 compatibility issue in 12.4.1
gem 'health-monitor-rails', '12.4.0'
gem 'high_voltage', '~> 3.0'
gem 'honeybadger'
gem 'human_languages', '~> 0.7'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ GEM
rexml (~> 3.0)
hashdiff (1.1.1)
hashie (5.0.0)
health-monitor-rails (12.1.0)
health-monitor-rails (12.4.0)
railties (>= 6.1)
high_voltage (3.1.2)
honeybadger (5.4.1)
Expand Down Expand Up @@ -701,7 +701,7 @@ DEPENDENCIES
ffi (>= 1.9.25)
friendly_id
gyoku (~> 1.0)
health-monitor-rails
health-monitor-rails (= 12.4.0)
high_voltage (~> 3.0)
honeybadger
human_languages (~> 0.7)
Expand Down
31 changes: 31 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,37 @@
end
end

namespace :application do
# You can/ should apply this command to a single host
# cap --hosts=bibdata-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=bibdata-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

after 'deploy:reverted', 'sidekiq:restart'
after 'deploy:published', 'sidekiq:restart'
after 'deploy:restart', 'sqs_poller:restart'
Expand Down
4 changes: 3 additions & 1 deletion config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
config.cache

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

# Make this health check available at /health
config.path = :health

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

0 comments on commit 5d76fe6

Please sign in to comment.