From cd72bf42da39fb6c8f74a00fc2589e1d62422752 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 May 2025 14:19:55 +0000 Subject: [PATCH 1/9] Bump capistrano3-puma from 5.2.0 to 6.0.0 Note we aren't updating concurrent-ruby (which Dependabot would have updated) due to an incompatibility with Rails 7.0. Bumps [capistrano3-puma](https://github.com/seuros/capistrano-puma) from 5.2.0 to 6.0.0. - [Changelog](https://github.com/seuros/capistrano-puma/blob/master/CHANGELOG.md) - [Commits](https://github.com/seuros/capistrano-puma/compare/v5.2.0...v6.0.0) --- updated-dependencies: - dependency-name: capistrano3-puma dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 14c2f9473..17969cc1d 100644 --- a/Gemfile +++ b/Gemfile @@ -91,7 +91,7 @@ group :development do gem "capistrano-npm", "~> 1.0.3", require: false gem "capistrano-rails", "~> 1.7.0", require: false gem "capistrano3-delayed-job", "~> 1.7.6" - gem "capistrano3-puma", "~> 5.2.0" + gem "capistrano3-puma", "~> 6.0.0" gem "erb_lint", "~> 0.9.0", require: false gem "faraday-retry", "~> 2.2.1", require: false gem "htmlbeautifier", "~> 1.4.3", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 553988dfc..5ed6ec7d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -139,10 +139,10 @@ GEM capistrano3-delayed-job (1.7.6) capistrano (~> 3.0, >= 3.0.0) daemons (~> 1.3) - capistrano3-puma (5.2.0) + capistrano3-puma (6.0.0) capistrano (~> 3.7) capistrano-bundler - puma (>= 4.0, < 6.0) + puma (>= 5.1, < 7.0) capybara (3.40.0) addressable matrix @@ -751,7 +751,7 @@ DEPENDENCIES capistrano-npm (~> 1.0.3) capistrano-rails (~> 1.7.0) capistrano3-delayed-job (~> 1.7.6) - capistrano3-puma (~> 5.2.0) + capistrano3-puma (~> 6.0.0) capybara (~> 3.40.0) capybara-webmock (~> 0.7.0) caxlsx (~> 4.2.0) From cd6122879005e9cede839568ea2b7fb9cb8909b3 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 13 May 2025 16:02:16 +0200 Subject: [PATCH 2/9] Replace removed Puma systemd tasks by supported equivalents capistrano3-puma 6.0.0 removed the `puma:systemd:config` and `puma:systemd:enable` tasks. This commit updates the deploy script to use the new `puma:install` and `puma:enable` tasks instead. --- config/deploy.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 84d1e6fcc..109c1917f 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -170,6 +170,6 @@ task :setup_puma do end end - after "setup_puma", "puma:systemd:config" - after "setup_puma", "puma:systemd:enable" + after "setup_puma", "puma:install" + after "setup_puma", "puma:enable" end From db361d88f17f4fbbe1bdf9ddb69299a5820c8a8f Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 13 May 2025 16:36:12 +0200 Subject: [PATCH 3/9] Restore puma_bind setting removed in capistrano3-puma 6.0.0 In earlier versions of capistrano3-puma, the puma_bind has a default value to: unix://.../tmp/sockets/puma.sock via set_if_empty in lib/capistrano/puma.rb. This default was removed in 6.0.0, requiring to explicitly set :puma_bind in deploy.rb. This caused the following runtime error during deploy: > Failed to restart consul_puma_staging.service: Unit > consul_puma_staging.socket has a bad unit file setting. --- config/deploy.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/deploy.rb b/config/deploy.rb index 109c1917f..f6f56bd5a 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -53,6 +53,7 @@ set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb" set :puma_systemctl_user, :user set :puma_enable_socket_service, true set :puma_service_unit_env_vars, ["EXECJS_RUNTIME=Disabled"] +set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" set :delayed_job_workers, 2 set :delayed_job_roles, :background From 034ecfeacde3d883969cbf019a10c2ca760f6196 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 13 May 2025 18:42:35 +0200 Subject: [PATCH 4/9] Copy Puma systemd unit template from capistrano3-puma This commit copies the default puma.service.erb template from the capistrano3-puma gem into lib/capistrano/templates. This allows us to customize the generated systemd unit file during deploy. Note that we are also removing the `:puma_conf` variable from `config/deploy.rb`, as the new ExecStart line in the systemd template (based on capistrano3-puma 6.0.0) does not rely on a separate Puma config file. The command now directly invokes: ExecStart=<%= expanded_bundle_command %> exec puma -e <%= fetch(:puma_env) %> This replaces the older format used in 5.2.0: ExecStart=<%= expanded_bundle_command %> exec --keep-file-descriptors puma -C <%= fetch(:puma_conf) %> which required explicitly setting the Puma config path. --- .erb_lint.yml | 1 + config/deploy.rb | 1 - lib/capistrano/templates/puma.service.erb | 40 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lib/capistrano/templates/puma.service.erb diff --git a/.erb_lint.yml b/.erb_lint.yml index aeb957940..e103da640 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -2,6 +2,7 @@ EnableDefaultLinters: false exclude: - '**/vendor/**/*' + - 'lib/capistrano/templates/*' linters: AllowedScriptType: enabled: true diff --git a/config/deploy.rb b/config/deploy.rb index f6f56bd5a..f9ddff364 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -49,7 +49,6 @@ set :fnm_setup_command, -> do set :fnm_install_node_command, -> { "#{fetch(:fnm_setup_command)} && fnm use --install-if-missing" } set :fnm_map_bins, %w[node npm rake yarn] -set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb" set :puma_systemctl_user, :user set :puma_enable_socket_service, true set :puma_service_unit_env_vars, ["EXECJS_RUNTIME=Disabled"] diff --git a/lib/capistrano/templates/puma.service.erb b/lib/capistrano/templates/puma.service.erb new file mode 100644 index 000000000..e546f11dc --- /dev/null +++ b/lib/capistrano/templates/puma.service.erb @@ -0,0 +1,40 @@ +# This file tells systemd how to run Puma as a 24/7 long-running daemon. +# +# Customize this file based on your bundler location, app directory, etc. +# Customize and copy this into /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu). +# Then run: +# - systemctl enable <%= fetch(:puma_service_unit_name) %> +# - systemctl {start,stop,restart} <%= fetch(:puma_service_unit_name) %> +# +# +# Use `journalctl -u <%= fetch(:puma_service_unit_name) %> -rn 100` to view the last 100 lines of log output. +# +[Unit] +Description=Puma HTTP Server for <%= "#{fetch(:application)} (#{fetch(:stage)})" %> +<%= "Requires=#{fetch(:puma_service_unit_name)}.socket" if fetch(:puma_enable_socket_service) %> +After=syslog.target network.target + +[Service] +Type=<%= service_unit_type %> +WatchdogSec=10 +<%="User=#{puma_user(@role)}" if fetch(:puma_systemctl_user) == :system %> +WorkingDirectory=<%= current_path %> +ExecStart=<%= expanded_bundle_command %> exec puma -e <%= fetch(:puma_env) %> +ExecReload=/bin/kill -USR1 $MAINPID +<%- Array(fetch(:puma_service_unit_env_files)).each do |file| %> +<%="EnvironmentFile=#{file}" -%> +<% end -%> +<% Array(fetch(:puma_service_unit_env_vars)).each do |environment_variable| %> +<%="Environment=\"#{environment_variable}\"" -%> +<% end -%> + +# if we crash, restart +RestartSec=1 +Restart=on-failure + +<%="StandardOutput=append:#{fetch(:puma_access_log)}" if fetch(:puma_access_log) %> +<%="StandardError=append:#{fetch(:puma_error_log)}" if fetch(:puma_error_log) %> + +SyslogIdentifier=<%= fetch(:puma_service_unit_name) %> +[Install] +WantedBy=<%=(fetch(:puma_systemctl_user) == :system) ? "multi-user.target" : "default.target"%> From 7712e7a3cfb2c213e613cc561de1a06fba9eb1e0 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 13 May 2025 18:53:56 +0200 Subject: [PATCH 5/9] Set WatchdogSec=0 in Puma systemd unit template The original template sets WatchdogSec=10, which causes systemd to kill Puma if it remains silent for more than 10 seconds. This commit changes WatchdogSec to 0 in our custom puma.service.erb, disabling the watchdog feature. This prevents unwanted restarts and avoids errors like: > consul_puma_staging.service: Failed with result 'watchdog' --- lib/capistrano/templates/puma.service.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/templates/puma.service.erb b/lib/capistrano/templates/puma.service.erb index e546f11dc..75d3dd850 100644 --- a/lib/capistrano/templates/puma.service.erb +++ b/lib/capistrano/templates/puma.service.erb @@ -16,7 +16,7 @@ After=syslog.target network.target [Service] Type=<%= service_unit_type %> -WatchdogSec=10 +WatchdogSec=0 <%="User=#{puma_user(@role)}" if fetch(:puma_systemctl_user) == :system %> WorkingDirectory=<%= current_path %> ExecStart=<%= expanded_bundle_command %> exec puma -e <%= fetch(:puma_env) %> From b99d2e43bb8951c2553ae158c1985983e1865182 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 27 May 2025 18:42:24 +0200 Subject: [PATCH 6/9] Keep SyslogIdentifier=puma for compatibility We keep using SyslogIdentifier=puma instead of the default value from capistrano3-puma 6.0.0, which is based on puma_service_unit_name (usually "_puma_"). This avoids introducing a new config variable in the installer and is enough for our current use case, where we don't run multiple environments on the same server. --- lib/capistrano/templates/puma.service.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/templates/puma.service.erb b/lib/capistrano/templates/puma.service.erb index 75d3dd850..de71f6885 100644 --- a/lib/capistrano/templates/puma.service.erb +++ b/lib/capistrano/templates/puma.service.erb @@ -35,6 +35,6 @@ Restart=on-failure <%="StandardOutput=append:#{fetch(:puma_access_log)}" if fetch(:puma_access_log) %> <%="StandardError=append:#{fetch(:puma_error_log)}" if fetch(:puma_error_log) %> -SyslogIdentifier=<%= fetch(:puma_service_unit_name) %> +SyslogIdentifier=puma [Install] WantedBy=<%=(fetch(:puma_systemctl_user) == :system) ? "multi-user.target" : "default.target"%> From d1693f06fcc9e2bd9b52a05998eeb4c504bf9957 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 27 May 2025 18:52:12 +0200 Subject: [PATCH 7/9] Keep After=network.target in Puma systemd unit We keep After=network.target instead of the new default After=syslog.target network.target introduced in capistrano3-puma 6.0.0. Our Puma service doesn't depend on syslog availability because it writes logs directly to files using: > StandardOutput=append:... > StandardError=append:... So the syslog.target dependency is unnecessary in our case. --- lib/capistrano/templates/puma.service.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/templates/puma.service.erb b/lib/capistrano/templates/puma.service.erb index de71f6885..9571a15ad 100644 --- a/lib/capistrano/templates/puma.service.erb +++ b/lib/capistrano/templates/puma.service.erb @@ -12,7 +12,7 @@ [Unit] Description=Puma HTTP Server for <%= "#{fetch(:application)} (#{fetch(:stage)})" %> <%= "Requires=#{fetch(:puma_service_unit_name)}.socket" if fetch(:puma_enable_socket_service) %> -After=syslog.target network.target +After=network.target [Service] Type=<%= service_unit_type %> From 19ab1139b9ce026202e513025fe9a452494bb802 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 28 May 2025 14:28:35 +0200 Subject: [PATCH 8/9] Define puma_service_unit_name for consistency with installer In capistrano3-puma v6.0.0, the default for 'puma_service_unit_name' changed to: > "#{application}_puma_#{stage}" But the installer uses the older convention: > "puma_#{application}_#{stage}" To ensure consistency and avoid unit name conflicts when switching between versions or deploying older branches, we now define the variable explicitly in config/deploy.rb: > set :puma_service_unit_name, -> { "puma_#{fetch(:application)}_#{fetch(:stage)}" } --- config/deploy.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/deploy.rb b/config/deploy.rb index f9ddff364..b8a837abc 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -52,6 +52,7 @@ set :fnm_map_bins, %w[node npm rake yarn] set :puma_systemctl_user, :user set :puma_enable_socket_service, true set :puma_service_unit_env_vars, ["EXECJS_RUNTIME=Disabled"] +set :puma_service_unit_name, -> { "puma_#{fetch(:application)}_#{fetch(:stage)}" } set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" set :delayed_job_workers, 2 From 4cd2d2f7946b621b78bee550235d79656975f02b Mon Sep 17 00:00:00 2001 From: taitus Date: Mon, 2 Jun 2025 15:02:41 +0200 Subject: [PATCH 9/9] Define Puma log paths for consistency with installer capistrano3-puma v6.0.0 updated the defaults for puma_access_log and puma_error_log to use a single file based on puma_env, like: > set_if_empty :puma_access_log, -> { File.join(shared_path, 'log', "#{fetch(:puma_env)}.log") } > set_if_empty :puma_error_log, -> { File.join(shared_path, 'log', "#{fetch(:puma_env)}.log") } However, our installer expect: - puma_access.log - puma_error.log To keep the existing behavior aligned with the installer, we define the Puma log paths in config/deploy.rb --- config/deploy.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/deploy.rb b/config/deploy.rb index b8a837abc..3b1ab6d2c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -54,6 +54,8 @@ set :puma_enable_socket_service, true set :puma_service_unit_env_vars, ["EXECJS_RUNTIME=Disabled"] set :puma_service_unit_name, -> { "puma_#{fetch(:application)}_#{fetch(:stage)}" } set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" +set :puma_access_log, -> { File.join(shared_path, "log", "puma_access.log") } +set :puma_error_log, -> { File.join(shared_path, "log", "puma_error.log") } set :delayed_job_workers, 2 set :delayed_job_roles, :background