37

I tried to deploy my rails site using capistrano. So when i ran

cap production deploy

This is what i got

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

Tasks: TOP => production

This is my cap file

# 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 }

This is my 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

So the code above is working before but when i update my gems then i can not deploy my app anymore.

So how can i fix this?

Thanks!

Varis Darasirikul
  • 3,907
  • 9
  • 40
  • 75

3 Answers3

101

Add install_plugin Capistrano::Puma into your Capfile after require 'capistrano/puma'.

capistrano3-puma moved to 3.0 a few days ago. This line is required for loading default puma tasks in this version.

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

Jin
  • 1,671
  • 1
  • 14
  • 13
  • 2
    thanks. Could you tell us how you solved this one since the error message was so crypt? – sandre89 Apr 17 '17 at 12:49
  • 2
    @sandre89 I deployed the same project just a few weeks before this happens. After a lot of googling but no answers, I start to find what changed between these two deployment. I noticed most gems in my Gemfile has a version constraint except the capistrano extension group. So I checked the lock file and these gems' history on [rubygems.org](https://rubygems.org/gems/capistrano3-puma/), found a main version upgrade for `capistrano3-puma`. Then following the document solved this error. – Jin Apr 19 '17 at 07:35
  • Wish I could buy you a beer for this. Maybe I can send you some cash? – Augusto Samamé Barrientos Jun 29 '17 at 23:10
  • 1
    Saved me. Took me awhile to find this answer. – iamse7en Nov 16 '18 at 12:49
  • 17
    I used `3.15.0` and need to add `install_plugin Capistrano::Puma::Daemon` as well in addition to `install_plugin Capistrano::Puma` – Amit Patel Feb 27 '21 at 06:44
  • Thanks @AmitPatel! This solved it for me. Please consider also adding an answer to this question with your solution =) – RSmithlal Mar 08 '21 at 15:31
23

These tasks need some plugins to be included in the Capfile. Jin's answer solves it partially and comment under the answer mentions that.

Here is an answer which concludes what works.

For Capistrano < 3.15.0:

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

For Capistrano >= 3.15.0 & Puma < 5.0

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

For Capistrano >= 3.15.0 & Puma >= 5.0

require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Systemd
Sagar Ranglani
  • 5,491
  • 4
  • 34
  • 47
0

This two line should be there in Capfile. Also this changes are done in recent puma version gem 'capistrano3-puma'.

require 'capistrano/puma'
install_plugin Capistrano::Puma  # Default puma tasks

Please mind the heirarchy in which they are written in capfile. This helps to loads the puma tasks in cap. You can list the capistrano tasks with cap -T. Also look for task related to puma once you have updated the Capfile with above two lines.

For more details, see https://github.com/seuros/capistrano-puma#usage

V K Singh
  • 1,134
  • 9
  • 14