gpt4 book ai didi

capistrano - Capistrano 3 中的“不知道如何构建任务”错误

转载 作者:行者123 更新时间:2023-12-03 22:35:49 27 4
gpt4 key购买 nike

我正在尝试通过遵循 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

我的 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}

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 }

我的 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>'

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

附带说明, 是否必须使用 SSH key 连接到远程服务器?

更新 1

我发现如果我把我的任务放在 config/deploy.rb有用。所以我现在的问题是如何从任务目录运行任务?

更新 2

所以根据 Capfile tasks通过以下方式查看 dir:
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

所以我把任务扩展名改成了 .rake它奏效了。但是文档说它应该是 .cap
"We'll dive into those more later, but add those lines to a file in ./lib/capistrano/tasks, call it something like access_check.cap"

最佳答案

Take a look at this commit.

他们已经从 .cap 切换过来的至 .rake 3个月前。

整个想法是让 capistrano3完全rake-compatible .只需使用 .rake为您的任务扩展。

关于capistrano - Capistrano 3 中的“不知道如何构建任务”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23306437/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com