不知道如何在 运行 'cap production deploy' 时为具有 Rails 的 capistrano 3.8.0 构建任务 'start'

Don't know how to build task 'start' when run 'cap production deploy' for capistrano 3.8.0 with Rails

我尝试使用 capist运行o 部署我的 rails 站点。 所以当我 运行

cap production deploy

这就是我得到的

(Backtrace restricted to imported tasks)
cap aborted!
Don't know how to build task 'start' (see --tasks)

Tasks: TOP => production

这是我的帽子文件

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

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

install_plugin Capistrano::SCM::Git

# 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,        'xxx'
set :application,     'xxx'
set :user,            'yyy'
set :puma_threads,    [4, 16]
set :puma_workers,    0

set :pty,             true
set :use_sudo,        false
set :stages,          ["staging", "production"]
set :default_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) }
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/master`
        puts "WARNING: HEAD is not the same as origin/master"
        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
end

所以上面的代码之前是有效的,但是当我更新我的 gem 时,我就不能再部署我的应用程序了。

那么我该如何解决这个问题?

谢谢!

install_plugin Capistrano::Puma 添加到您的 Capfile 之后 require 'capistrano/puma'

capistrano3-puma 几天前搬到了 3.0。在此版本中加载默认 puma 任务需要此行。

https://github.com/seuros/capistrano-puma#usage

这两行应该在 Capfile 中。此外,此更改是在最近的 puma 版本 gem 'capistrano3-puma'.

中完成的
require 'capistrano/puma'
install_plugin Capistrano::Puma  # Default puma tasks

请注意它们在 capfile 中的层次结构。这有助于加载 cap 中的 puma 任务。您可以使用 cap -T 列出 capistrano 任务。使用以上两行更新 Capfile 后,还要查找与 puma 相关的任务。

有关详细信息,请参阅 https://github.com/seuros/capistrano-puma#usage

这些任务需要一些插件包含在 Capfile 中。 Jin 的回答部分解决了它,并且在回答下的评论中提到了这一点。

这是一个总结有效方法的答案。

对于 Capistrano < 3.15.0:

`require 'capistrano/puma'
install_plugin Capistrano::Puma

对于 Capistrano >= 3.15.0 & Puma < 5.0

require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Daemon

对于 Capistrano >= 3.15.0 & Puma >= 5.0

require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Systemd