简体   繁体   English

使用Capistrano将Sidekiq部署到Ubuntu时出错

[英]Error deploying Sidekiq to Ubuntu using Capistrano

I'm following the directions here to integrate Sidekiq with Capistrano on Ubuntu: https://github.com/mperham/sidekiq/wiki/Deploying-to-Ubuntu 我正在按照以下说明在Ubuntu上将Sidekiq与Capistrano集成: https : //github.com/mperham/sidekiq/wiki/Deploying-to-Ubuntu

I'm having an issue with the Capistrano part. 我的Capistrano部分有问题。

I put this code at the end of deploy.rb : 我将此代码放在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'

And I get this error when I run cap production deploy : 当我运行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>

Obviously, it's the capture function that's undefined, but what is the problem? 显然,捕获功能未定义,但是出了什么问题? Did I put the code in the right file deploy.rb ? 我是否将代码放在正确的文件deploy.rb Do I need to require something? 我需要什么吗?

You have to specify which server to run the code on. 您必须指定在哪个服务器上运行代码。 For instance: 例如:

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

尝试要求使用sidekiq宝石,或看看具有sidekiq集成的capistrano

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM