【问题标题】:Error deploying Sidekiq to Ubuntu using Capistrano使用 Capistrano 将 Sidekiq 部署到 Ubuntu 时出错
【发布时间】:2015-04-02 07:52:43
【问题描述】:

我正在按照此处的说明在 Ubuntu 上将 Sidekiq 与 Capistrano 集成:https://github.com/mperham/sidekiq/wiki/Deploying-to-Ubuntu

我遇到了 Capistrano 部分的问题。

我把这段代码放在deploy.rb的末尾:

# For capistrano 3
namespace :sidekiq do
  task :quiet do
    # Horrible hack to get PID without having to use terrible PID files
    puts capture("kill -USR1 $(sudo initctl status workers | grep /running | awk '{print $NF}') || :") 
  end
  task :restart do
    execute :sudo, :initctl, :restart, :workers
  end
end

after 'deploy:starting', 'sidekiq:quiet'
after 'deploy:reverted', 'sidekiq:restart'
after 'deploy:published', 'sidekiq:restart'

当我运行 cap production deploy 时出现此错误:

cap aborted!
NoMethodError: undefined method `capture' for main:Object
config/deploy.rb:67:in `block (2 levels) in <top (required)>'
/Users/user/.rvm/gems/ruby-2.1.2@project/gems/capistrano-3.2.1/lib/capistrano/dsl/task_enhancements.rb:12:in `block in after'
/Users/user/.rvm/gems/ruby-2.1.2@project/gems/capistrano-3.2.1/lib/capistrano/dsl.rb:15:in `invoke'
/Users/user/.rvm/gems/ruby-2.1.2@project/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:65:in `block (2 levels) in <top (required)>'
/Users/user/.rvm/gems/ruby-2.1.2@project/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:64:in `each'
/Users/user/.rvm/gems/ruby-2.1.2@project/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:64:in `block in <top (required)>'
/Users/user/.rvm/gems/ruby-2.1.2@project/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/user/.rvm/gems/ruby-2.1.2@project/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/user/.rvm/gems/ruby-2.1.2@project/bin/cap:23:in `load'
/Users/user/.rvm/gems/ruby-2.1.2@project/bin/cap:23:in `<main>'
/Users/user/.rvm/gems/ruby-2.1.2@project/bin/ruby_executable_hooks:15:in `eval'
/Users/user/.rvm/gems/ruby-2.1.2@project/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => sidekiq:quiet
(See full trace by running task with --trace)
The deploy has failed with an error: #<NoMethodError: undefined method `capture' for main:Object>

显然,未定义的是捕获函数,但问题是什么?我是否将代码放在正确的文件deploy.rb 中?我需要什么吗?

【问题讨论】:

    标签: ruby-on-rails ubuntu capistrano sidekiq capistrano3


    【解决方案1】:

    您必须指定在哪个服务器上运行代码。例如:

    namespace :sidekiq do
      task :quiet do
        # Horrible hack to get PID without having to use terrible PID files
        on roles(:app) do
          puts capture("kill -USR1 $(sudo initctl status workers | grep /running | awk '{print $NF}') || :") 
        end
      end
      task :restart do
        on roles(:app) do
          execute :sudo, :initctl, :restart, :workers
        end
      end
    end
    

    【讨论】:

      【解决方案2】:

      尝试要求 sidekiq gem,或查看capistrano with sidekiq integration

      【讨论】:

      • 为什么这被否决了?根据github.com/mperham/sidekiq/blob/…,该方法是在 Sidekiq 模块中定义的,所以需要模块来修复它。
      • @NekoNova 我尝试使用require 'sidekiq' 要求deploy.rb 顶部的模块。 sidekiq 已经在我的 Gemfile 中。仍然得到NoMethodError: undefined method 'capture' for main:Object。尝试将其更改为Sidekiq.capture,但这也不起作用。你确定捕获的方法不是这个方法:github.com/capistrano/capistrano/wiki/…
      • 也可以。如果您使用 Capistrano 的完整模块符号来调用它,它是否有效?您是否使用 bundle exec 调用 rake 任务?
      • @ill_always_be_a_warriors 向我展示你的整个错误日志。我假设 Capistrano 的 Application 类没有被初始化或者什么的。
      • @seoyoochan 完整错误已添加到上述问题中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-03
      • 1970-01-01
      • 2017-04-30
      • 2014-10-21
      • 2019-05-05
      • 1970-01-01
      相关资源
      最近更新 更多