Search code examples
ruby-on-railscapistranopumacapistrano3

Capistrano: puma:start not recognized after updating gem versions


I have recently upgraded my Ruby on Rails application from 6.0 to 6.1. In doing so I decided to upgrade capistrano and puma. I'm using the following gems:

  capistrano-bundler (2.0.1)
  capistrano-rails (1.6.1)
  capistrano-rvm (0.1.2)
  capistrano3-puma (5.0.2) (was 3.1.1)
  puma (5.1.1) (was 3.10.0)

Now when I try to run capistrano tasks I get the following

** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Don't know how to build task 'start' (See the list of available tasks with `cap --tasks`)

Even cap --tasks produces the same message.

I have tried cap staging puma:restart and get Don't know how to build task 'puma:start'.

Here is my capfile:

# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'

require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'

install_plugin Capistrano::Puma

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

My deploy.rb has not changed, could something be incompatible with the newer version?

set :repo_url,        '[email protected]:v3/orgname/reponame/repo'
set :application,     'projectname-prod'
set :user,            'deploy'
set :puma_threads,    [4, 16]
set :puma_workers,    0

# Don't change these unless you know what you're doing
set :pty,             true
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true  # Change to false when not using ActiveRecord

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

  before :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}`
        puts "WARNING: HEAD is not the same as origin/develop"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
    end
  end

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart
end

set :linked_files, fetch(:linked_files, []).push("config/master.key")

Update

Here's the trace when running cap staging deploy --trace:

** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Don't know how to build task 'start' (See the list of available tasks with `cap --tasks`)
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task_manager.rb:59:in `[]'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:405:in `[]'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.15.0/lib/capistrano/dsl/task_enhancements.rb:7:in `before'
config/deploy.rb:46:in `block in <top (required)>'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task_manager.rb:232:in `in_namespace'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/dsl_definition.rb:141:in `namespace'
config/deploy.rb:37:in `<top (required)>'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.15.0/lib/capistrano/setup.rb:27:in `load'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.15.0/lib/capistrano/setup.rb:27:in `block (3 levels) in <top (required)>'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.15.0/lib/capistrano/configuration/variables.rb:32:in `untrusted!'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/delegate.rb:83:in `method_missing'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.15.0/lib/capistrano/setup.rb:26:in `block (2 levels) in <top (required)>'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `block in execute'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `each'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `execute'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:188:in `invoke'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:160:in `invoke_task'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `each'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `block in top_level'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:125:in `run_with_threads'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:110:in `top_level'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:83:in `block in run'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:80:in `run'
/Users/username/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.15.0/lib/capistrano/application.rb:14:in `run'
/Users/tibsarsoftware/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.15.0/bin/cap:3:in `<top (required)>'
/Users/username/.rbenv/versions/2.6.3/bin/cap:23:in `load'
/Users/username/.rbenv/versions/2.6.3/bin/cap:23:in `<main>'

Solution

  • If you look at the diff of the version you've used before vs. the version you're using now (https://github.com/seuros/capistrano-puma/compare/v3.1.1...v5.0.2), you can see that the puma:start command (together with others) was apparently removed from the main puma.rake and instead moved to the the pluggable adapters for daemonization and systemd respectively. Judging by the readme (https://github.com/seuros/capistrano-puma#usage), Puma 5+ only allows systemd (see https://github.com/puma/puma/pull/2170), so you'll have to add install_plugin Capistrano::Puma::Systemd to your Capistrano setup (and of course make sure that your setup runs systemd properly).

    If you can't/don't want to use systemd and want to stick with Puma's classic daemonization, you'll have to go with Puma 4 (gem 'puma', '< 5' in your Gemfile) until you're ready to upgrade.