Skip to content

Commit

Permalink
Merge pull request #155 from pulibrary/i154_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 0add1b0 + 2287957 commit a6c3dd1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem 'cancancan', '~> 3.3'
gem 'faraday'

gem 'devise'
gem 'health-monitor-rails'
gem 'health-monitor-rails', '12.4.0'
gem 'omniauth'
gem "omniauth-cas"
gem "omniauth-rails_csrf_protection"
Expand Down Expand Up @@ -60,4 +60,3 @@ group :development do
gem 'capistrano-passenger'
gem 'ed25519'
end

4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ GEM
activesupport (>= 6.1)
hashdiff (1.1.0)
hashie (5.0.0)
health-monitor-rails (12.2.0)
health-monitor-rails (12.4.0)
railties (>= 6.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -418,7 +418,7 @@ DEPENDENCIES
ed25519
factory_bot_rails
faraday
health-monitor-rails
health-monitor-rails (= 12.4.0)
jbuilder
jquery-rails
jquery-tablesorter
Expand Down
31 changes: 31 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@
# passenger-config restart-app which requires sudo access
set :passenger_restart_with_touch, true

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

# stop sprokets from crashing the production deploy
Rake::Task["deploy:assets:backup_manifest"].clear_actions
Rake::Task["deploy:assets:restore_manifest"].clear_actions
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
HealthMonitor.configure do |config|
# Make this health check available at /health
config.path = :health

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

0 comments on commit a6c3dd1

Please sign in to comment.