From 38efd919c95f5628b58f7f60ef49c2414b236054 Mon Sep 17 00:00:00 2001 From: carolyncole <1599081+carolyncole@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:40:05 -0500 Subject: [PATCH] Allows a file `public/remove-from-nginx` existance to fail the status of the health page (#1985) --- Gemfile | 2 +- Gemfile.lock | 20 +++++++++++------- config/deploy.rb | 29 +++++++++++++++++++++++++++ config/initializers/health_monitor.rb | 7 ++++++- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 24a76677a..8bd71d935 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ gem "amazing_print" gem "aws-sdk-s3" gem "datacite-mapping" gem "dogstatsd-ruby" -gem "health-monitor-rails" +gem "health-monitor-rails", github: "pulibrary/health-monitor-rails", branch: "add-file-absence-check" gem "honeybadger" gem "io-wait", "0.2.1" gem "net-ftp" diff --git a/Gemfile.lock b/Gemfile.lock index 6744608cb..cc037691c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,14 @@ GIT hashie (~> 3.4, >= 3.4.3) nokogiri +GIT + remote: https://github.com/pulibrary/health-monitor-rails.git + revision: 69f1ded751c5fa2f0b6a0f1c2180cbd832a41365 + branch: add-file-absence-check + specs: + health-monitor-rails (12.3.0) + railties (>= 6.1) + GIT remote: https://github.com/sul-dlss/datacite-ruby.git revision: e17b5eb313aa8cfa7a345efb71c98bb51d660a9f @@ -245,15 +253,13 @@ GEM activesupport (>= 6.1) hashdiff (1.1.1) hashie (3.6.0) - health-monitor-rails (12.3.0) - railties (>= 6.1) honeybadger (5.15.6) i18n (1.14.6) concurrent-ruby (~> 1.0) ice_nine (0.11.2) io-console (0.7.2) io-wait (0.2.1) - irb (1.14.0) + irb (1.14.1) rdoc (>= 4.0.0) reline (>= 0.4.2) jbuilder (2.13.0) @@ -276,7 +282,7 @@ GEM rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) logger (1.6.1) - loofah (2.22.0) + loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -373,7 +379,7 @@ GEM rack (< 3) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.0) + rackup (1.0.1) rack (< 3) webrick rails (7.2.1.1) @@ -577,7 +583,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.8.2) + webrick (1.9.0) websocket (1.2.11) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) @@ -628,7 +634,7 @@ DEPENDENCIES ffaker foreman friendly_id (~> 5.4.0) - health-monitor-rails + health-monitor-rails! honeybadger io-wait (= 0.2.1) jbuilder (~> 2.7) diff --git a/config/deploy.rb b/config/deploy.rb index 4b333712c..62595b8da 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -79,6 +79,35 @@ end end end + + # You can/ should apply this command to a single host + # cap --hosts=pdc-describe-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 > 1 + raise "You must run this command on individual 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-describe-staging1.princeton.edu staging application:serve_from_nginx + desc "Marks the server(s) to be removed from 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 before "deploy:reverted", "deploy:assets:precompile" diff --git a/config/initializers/health_monitor.rb b/config/initializers/health_monitor.rb index bd0ace720..976bb678f 100644 --- a/config/initializers/health_monitor.rb +++ b/config/initializers/health_monitor.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + HealthMonitor.configure do |config| config.cache config.redis @@ -13,8 +14,12 @@ sidekiq_config.critical = false end + config.file_absence.configure do |file_config| + file_config.filename = "public/remove-from-nginx" + end + config.error_callback = proc do |e| Rails.logger.error "Health check failed with: #{e.message}" - Honeybadger.notify(e) + Honeybadger.notify(e) unless e.is_a?(HealthMonitor::Providers::FileAbsenceException) end end