From 2287957781b9c4485b92314cc3e85486bee84a36 Mon Sep 17 00:00:00 2001 From: Max Kadel Date: Wed, 13 Nov 2024 13:56:40 -0500 Subject: [PATCH] Add capistrano tasks to take a node off the load balancer. Closes #154 --- Gemfile | 3 +-- Gemfile.lock | 4 ++-- config/deploy.rb | 31 +++++++++++++++++++++++++++ config/initializers/health_monitor.rb | 4 ++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 76425df..2fe6777 100644 --- a/Gemfile +++ b/Gemfile @@ -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" @@ -60,4 +60,3 @@ group :development do gem 'capistrano-passenger' gem 'ed25519' end - diff --git a/Gemfile.lock b/Gemfile.lock index 0b8e8ea..aadb2e4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -418,7 +418,7 @@ DEPENDENCIES ed25519 factory_bot_rails faraday - health-monitor-rails + health-monitor-rails (= 12.4.0) jbuilder jquery-rails jquery-tablesorter diff --git a/config/deploy.rb b/config/deploy.rb index 263a4c4..ec21d7f 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -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 diff --git a/config/initializers/health_monitor.rb b/config/initializers/health_monitor.rb index 2764bea..d2f5f86 100644 --- a/config/initializers/health_monitor.rb +++ b/config/initializers/health_monitor.rb @@ -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