Skip to content

Commit

Permalink
Allows a file public/remove-from-nginx existance to fail the status…
Browse files Browse the repository at this point in the history
… of the health page (#1985)
  • Loading branch information
carolyncole authored Nov 8, 2024
1 parent 2c9e47c commit 38efd91
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 13 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

HealthMonitor.configure do |config|
config.cache
config.redis
Expand All @@ -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

0 comments on commit 38efd91

Please sign in to comment.