I'm following the directions here to integrate Sidekiq with Capistrano on Ubuntu: https://github.com/mperham/sidekiq/wiki/Deploying-to-Ubuntu
I'm having an issue with the Capistrano part.
I put this code at the end of 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 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
? 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