6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-06-07

事象

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

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?