From 9aea93a82e12dfb7138ddae218eae10147e02f3e Mon Sep 17 00:00:00 2001 From: Francis Kayiwa Date: Wed, 13 Nov 2024 09:20:20 -0500 Subject: [PATCH] add the configuration for health-monitor we initialize health-monitor and configure it --- config/deploy.rb | 30 +++++++++++++++++++++++++++ config/initializers/health_monitor.rb | 17 +++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 config/initializers/health_monitor.rb diff --git a/config/deploy.rb b/config/deploy.rb index 2fb664a0..f978ae54 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -157,6 +157,36 @@ after :finishing, 'deploy:cleanup' + # # You can/ should apply this command to a subset of hosts +# cap --hosts=lib-approvals-staging2.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 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 subset of hosts + # cap --hosts=lib-approvals-staging2.lib.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" # # We shouldn't need this because it should be built in to Rails 5.1 # # see https://github.com/rails/webpacker/issues/1037 # desc 'Run yarn install' diff --git a/config/initializers/health_monitor.rb b/config/initializers/health_monitor.rb new file mode 100644 index 00000000..ebc4e13c --- /dev/null +++ b/config/initializers/health_monitor.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true +Rails.application.config.after_initialize do + HealthMonitor.configure do |config| + config.cache + + config.path = :health + + 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) + end + end +end