Help us understand the problem. What is going on with this article?

capistrano3-pumaのtaskが読み込めない場合の対応

More than 3 years have passed since last update.

事象

CapistranoのVersionを3.8にあげると、デプロイが失敗するようになりました。
capistrano3-pumaのtaskがよみこめなくなったというエラーがでます。

Don't know how to build task 'start' (see --tasks)
Don't know how to build task 'puma:restart' (see --tasks)

設定ファイル

config/deploy.rb
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 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
    end
  end

  after :publishing, :restart
end
require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/rails"
require 'capistrano/puma'
require "capistrano/scm/git"

install_plugin Capistrano::SCM::Git

Dir.glob("lib/capistrano/tasks/*.rake").each{|r| import r}

対応

Capfileにinstall_plugin Capistrano::Pumaを追記しました。

require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/rails"
require 'capistrano/puma'
require "capistrano/scm/git"

install_plugin Capistrano::SCM::Git
install_plugin Capistrano::Puma <-コレ

Dir.glob("lib/capistrano/tasks/*.rake").each{|r| import r}

追記

さらに最新(2017/06/07)のcapistrano3-pumaのGemをinstallすると、またもやエラーが発生

Skipping task `puma:restart'.
Capistrano tasks may only be invoked once. Since task `puma:restart' was previously invoked, invoke("puma:restart") at rails_app/vendor/bundle/ruby/2.4.0/gems/capistrano3-puma-3.1.0/lib/capistrano/tasks/puma.rake:96 will be skipped.
If you really meant to run this task again, first call Rake::Task["puma:restart"].reenable
THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.
https://github.com/capistrano/capistrano/issues/1686

対応

config/deploy.rb
namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      Rake::Task["puma:restart"].reenable <-コレを追記
      invoke 'puma:restart'
    end
  end

#  after :finishing, :restart <- これをコメントアウトする

参考

https://stackoverflow.com/questions/43014993/dont-know-how-to-build-task-start-when-run-cap-production-deploy-for-capist
https://github.com/seuros/capistrano-puma#usage
https://github.com/capistrano/capistrano/issues/1686
https://stackoverflow.com/questions/39810930/pumarestart-invoke-twice-but-i-only-call-it-once-on-my-deploy-app-via-capistr

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした