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

时间:2017-03-25 09:59:42

标签: ruby-on-rails capistrano

我尝试使用capistrano部署我的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

所以上面的代码工作之前,但是当我更新我的宝石时,我再也无法部署我的应用程序了。

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

谢谢!

3 个答案:

答案 0 :(得分:82)

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

几天前

capistrano3-puma已移至3.0。在此版本中加载默认puma任务需要此行。

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

答案 1 :(得分:5)

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

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

对于 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

答案 2 :(得分:0)

这两个行应该在Capfile中。另外,最近的彪马版宝石“ capistrano3-puma”也进行了此更改。

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

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

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