Skip to content

Commit

Permalink
Add capistrano task to remove application from the load balancer. (#74)
Browse files Browse the repository at this point in the history
* Add capistrano task to remove application from the load balancer.

Closes #73
  • Loading branch information
tpendragon authored Nov 14, 2024
1 parent 53343cd commit 3645061
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'health-monitor-rails'
gem 'health-monitor-rails', '12.4.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 7.1.0'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ GEM
ffi (1.17.0-x86_64-linux-gnu)
globalid (1.2.1)
activesupport (>= 6.1)
health-monitor-rails (12.3.0)
health-monitor-rails (12.4.0)
railties (>= 6.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -339,7 +339,7 @@ DEPENDENCIES
capistrano-rails
capybara
coffee-rails (~> 4.2)
health-monitor-rails
health-monitor-rails (= 12.4.0)
jbuilder
listen
pagy (~> 3.5)
Expand Down
32 changes: 32 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/opt/geaccirc'

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

# Default value for :format is :airbrussh.
# set :format, :airbrussh

Expand Down
3 changes: 3 additions & 0 deletions config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Rails.application.config.after_initialize do
HealthMonitor.configure do |config|
config.file_absence.configure do |file_config|
file_config.filename = 'public/remove-from-nginx'
end
# Make this health check available at /health
config.path = :health

Expand Down

0 comments on commit 3645061

Please sign in to comment.