Capistrano:更新 gem 版本后 puma:start 无法识别

Capistrano: puma:start not recognized after updating gem versions

我最近将 Ruby on Rails 应用程序从 6.0 升级到 6.1。为此,我决定升级 capistrano 和 puma。我正在使用以下宝石:

  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)

现在,当我尝试 运行 capistrano 任务时,我得到以下结果

** 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`)

甚至 cap --tasks 也会生成相同的消息。

我已经尝试 cap staging puma:restart 并得到 Don't know how to build task 'puma:start'

这是我的 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 }

我的deploy.rb没变,会不会是新版本不兼容?

set :repo_url,        'git@ssh.dev.azure.com: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")

更新

这是 运行ning 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>'

如果您查看之前使用的版本与现在使用的版本 (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) 的差异,那么您必须将 install_plugin Capistrano::Puma::Systemd 添加到您的Capistrano 设置(当然还要确保你的设置正确运行 systemd)。

如果您t/don不想使用 systemd 并想坚持使用 Puma 的经典守护进程,则必须使用 Puma 4(gem 'puma', '< 5' 在您的 Gemfile) 直到您准备好升级。