【问题标题】:undefined method `run' for main:Objectmain:Object 的未定义方法“run”
【发布时间】:2014-05-24 22:52:47
【问题描述】:

我在部署时得到以下输出:

cap aborted!
NoMethodError: undefined method `run' for main:Object
config/deploy.rb:37:in `block (2 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/dsl/task_enhancements.rb:12:in `block in after'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
Tasks: TOP => deploy:permissions
(See full trace by running task with --trace)
The deploy has failed with an error: #<NoMethodError: undefined method `run' for main:Object>

我正在使用 Capistrano 版本:3.2.1(Rake 版本:10.3.2)。 部署工作正常,但我创建了一个部署后任务来修改已部署版本的所有者,如下所示:

namespace :deploy do
    task :permissions do
      run "chown -R :#{fetch(:group)} #{deploy_to} && chmod -R g+s #{deploy_to}"
    end
end

after :deploy, "deploy:permissions"

vars 被正确定义(我之前修复了那个错误)但是我得到了 run 方法的缺失方法错误,我不知道为什么。

【问题讨论】:

  • 它现在可以通过调用on 指定我想在哪里运行代码。我也必须用执行命令替换运行命令。

标签: ruby-on-rails capistrano web-deployment


【解决方案1】:

您的代码使用 2.x 语法,而您的版本是 3.x。在 3.x 中,语法如下所示:

namespace :deploy do
  on roles :all do
    execute :chown, "-R :#{fetch(:group)} #{deploy_to} && chmod -R g+s #{deploy_to}"
  end
end

【讨论】:

  • 我想我为不同的帽子版本混合了一些操作方法。它现在可以工作了,所以谢谢!
  • @Gergo Erdosi:可能相当于namespace :myapp do task :restart_webserver do # Restart Web Server run "sudo service apache2 restart" end end after "deploy","myapp:restart_webserver"
猜你喜欢
  • 2012-04-04
  • 2012-05-05
  • 2014-09-23
  • 2015-01-23
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多