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

问题描述 投票:0回答:2

我正在按照以下说明在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
2个回答
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

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.