在使用Rails为capistrano 3.8.0运行'cap production deploy'时,不知道如何构建任务'start'

Var*_*kul 24 capistrano ruby-on-rails

我尝试使用capistrano部署我的rails网站.所以,当我跑

cap production deploy
Run Code Online (Sandbox Code Playgroud)

这就是我得到的

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

Tasks: TOP => production
Run Code Online (Sandbox Code Playgroud)

这是我的上限文件

# 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 }
Run Code Online (Sandbox Code Playgroud)

这是我的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
Run Code Online (Sandbox Code Playgroud)

所以上面的代码工作之前,但当我更新我的宝石,然后我不能再部署我的应用程序.

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

谢谢!

Jin*_*Jin 87

添加install_plugin Capistrano::Puma到您的Capfilerequire 'capistrano/puma'.

capistrano3-puma几天前搬到了3.0.此行是在此版本中加载默认puma任务所必需的.

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

  • 我使用了 `3.15.0`,除了 `install_plugin Capistrano::Puma` 之外,还需要添加 `install_plugin Capistrano::Puma::Daemon` (12认同)
  • 谢谢。由于错误消息是如此隐晦,您能告诉我们您是如何解决这个问题的吗? (2认同)
  • @sandre89 在这发生前几周,我部署了同一个项目。经过大量谷歌搜索但没有答案后,我开始发现这两个部署之间发生了什么变化。我注意到我的 Gemfile 中的大多数 gem 都有一个版本限制,除了 capistrano 扩展组。因此,我在 [rubygems.org](https://rubygems.org/gems/capistrano3-puma/) 上检查了锁定文件和这些 gem 的历史记录,发现了“capistrano3-puma”的主要版本升级。然后按照文档解决了这个错误。 (2认同)

Sag*_*ani 7

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

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

对于 Capistrano < 3.15.0:

`require 'capistrano/puma'
install_plugin Capistrano::Puma
Run Code Online (Sandbox Code Playgroud)

对于 Capistrano >= 3.15.0 & Puma < 5.0

require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Daemon
Run Code Online (Sandbox Code Playgroud)

对于 Capistrano >= 3.15.0 & Puma >= 5.0

require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Systemd
Run Code Online (Sandbox Code Playgroud)