Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ group :development do
gem "capistrano", require: false
# For puma 6 support we're using the "beta" version
gem "capistrano3-puma", ">= 6.0.0.beta.1", require: false
gem "capistrano-aws"
gem "capistrano-aws", require: false
gem "capistrano-bundler", require: false
gem "capistrano-rails", require: false
gem "capistrano-rvm", require: false
Expand Down
17 changes: 16 additions & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
# Note that phased restarts will NOT upgrade puma. So disable this if upgrading puma
set :puma_phased_restart, true

# Control puma serviced config
# set :puma_service_unit_type, "notify"
# set :puma_systemd_watchdog_sec, 10
set :puma_access_log, "/srv/www/production/shared/log/puma.log"
set :puma_error_log, "/srv/www/production/shared/log/puma.log"
# Puma master + 3 workers start at ~260 MB each, capped at 550 MB per worker
# Total limit = 3 workers x 550 MB + 30 MB master = 1,680 MB
# In practice memory is expected to peak at 72%, just under the 75% warning level
set :puma_service_unit_props, %w[MemoryMax=1680M TimeoutStopSec=300]
set :puma_enable_lingering, false
set :puma_systemctl_user, :user

set :aws_ec2_regions, ['ap-southeast-2']
# We don't want to use the stage tag to filter because we have both production and staging on the same machine
set :aws_ec2_default_filters, (proc {
Expand Down Expand Up @@ -152,8 +164,11 @@
end
end


before "deploy:finishing", "foreman:restart"
before "foreman:restart", "foreman:enable"
before "foreman:enable", "foreman:export"
before "deploy:check:linked_files", "upload_memcache_config"

before "deploy:publishing", "puma:install"
before "deploy:check", "puma:check_lingering"

34 changes: 0 additions & 34 deletions config/deploy/templates/puma.service.erb

This file was deleted.

26 changes: 26 additions & 0 deletions lib/capistrano/tasks/puma_check_lingering.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# typed: strict
# frozen_string_literal: true

# Check if lingering is already set - warn if not.

namespace :puma do
desc "Check lingering is already set"
task :check_lingering do
on roles(fetch(:puma_role)) do |host|
linger_status = capture("loginctl show-user #{host.user} 2>/dev/null | grep Linger || true")

if linger_status.include?("Linger=yes")
info "OK: Linger is enabled for #{host.user}@#{host.hostname}."
else
warn "FATAL: Linger is NOT enabled for #{host.user}@#{host.hostname}! Run as root:"
warn ""
warn " loginctl enable-linger #{host.user}"
warn ""
warn "Without this, #{host.user}'s systemd --user services (including Puma) will"
warn "stop when their SSH session ends or the box reboots."
warn ""
raise "Linger not enabled for #{host.user}@#{host.hostname}!"
end
end
end
end