Capistrano 3中"不知道如何构建任务"错误

kai*_*der 14 capistrano capistrano3

我正在努力学习遵循DOCS使用Capistrano 3,我写了一个简单的任务来测试我的理解.

任务在默认task目录中创建lib/capistrano/tasks:

  desc "Check status of web server"
    task :nginx_status do
      on roles(:web) do |host|
        execute 'service nginx status'
      end
    end
Run Code Online (Sandbox Code Playgroud)

我的config/deploy/staging.rb文件包含以下内容:

set :stage, :staging

role :web, "192.168.0.11"
role :app,  "192.168.0.11"
role :db, "192.168.0.11", primary:true

server '192.168.0.11', user: 'vagrant', roles: %w{web app}
Run Code Online (Sandbox Code Playgroud)

Capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

# 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的github包含一个应用程序名称和一个repo url.

当我运行时,cap staging nginx_status我收到以下错误:

** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Don't know how to build task 'nginx_status'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/task_manager.rb:62:in `[]'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:149:in `invoke_task'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `each'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block in top_level'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:115:in `run_with_threads'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:100:in `top_level'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:78:in `block in run'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:75:in `run'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/H/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/H/.rbenv/versions/2.1.1/bin/cap:23:in `load'
/Users/H/.rbenv/versions/2.1.1/bin/cap:23:in `<main>'
Run Code Online (Sandbox Code Playgroud)

我也注意到,如果我运行cap -vT任务nginx_status不在列表中(?)

另外,SSH密钥是否必须连接到远程服务器?

更新1

我发现,如果我将任务放入config/deploy.rb其中.所以我现在的问题是如何从任务目录运行任务?

更新2

因此,根据Capfile,tasksdir通过以下方式查看:

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

所以我将任务扩展名更改为.rake并且工作正常.但是文档说它应该是.cap

"我们稍后会深入讨论这些内容,但是将这些行添加到./lib/capistrano/tasks中的文件中,称之为access_check.cap"

Iva*_*lin 8

看看这个提交.

他们已经从3个月前切换.cap到了.rake.

整个想法是capistrano3充分发挥rake-compatible.只需.rake为您的任务使用扩展.