Skip to content

Commit

Permalink
depend on recent version of Sidekiq
Browse files Browse the repository at this point in the history
rename tasks to .rake
  • Loading branch information
seuros committed Aug 20, 2015
1 parent e03c69b commit 5745888
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 46 deletions.
2 changes: 1 addition & 1 deletion capistrano-sidekiq.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'capistrano'
spec.add_dependency 'sidekiq'
spec.add_dependency 'sidekiq', '>= 3.4'
end
2 changes: 1 addition & 1 deletion lib/capistrano/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if Gem::Specification.find_by_name('capistrano').version >= Gem::Version.new('3.0.0')
load File.expand_path('../tasks/sidekiq.cap', __FILE__)
load File.expand_path('../tasks/sidekiq.rake', __FILE__)
else
require_relative 'tasks/capistrano2'
end
2 changes: 1 addition & 1 deletion lib/capistrano/sidekiq/monit.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# load monit tasks
load File.expand_path('../../tasks/monit.cap', __FILE__)
load File.expand_path('../../tasks/monit.rake', __FILE__)
67 changes: 27 additions & 40 deletions lib/capistrano/tasks/monit.cap → lib/capistrano/tasks/monit.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace :load do
task :defaults do
set :sidekiq_monit_conf_dir, -> { '/etc/monit/conf.d' }
set :sidekiq_monit_use_sudo, -> { true }
set :monit_bin, -> { '/usr/bin/monit' }
set :sidekiq_monit_default_hooks, -> { true }
set :sidekiq_monit_conf_dir, '/etc/monit/conf.d'
set :sidekiq_monit_use_sudo, true
set :monit_bin, '/usr/bin/monit'
set :sidekiq_monit_default_hooks, true
set :sidekiq_monit_templates_path, 'config/deploy/templates'
end
end

Expand Down Expand Up @@ -38,64 +39,54 @@ namespace :sidekiq do

desc 'Monitor Sidekiq monit-service'
task :monitor do
Array(fetch(:sidekiq_role)).each do |role|
on roles(role) do
sidekiq_processes(role).times do |idx|
begin
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(idx)}"
rescue
invoke 'sidekiq:monit:config'
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(idx)}"
end
on roles(fetch(:sidekiq_role)) do
fetch(:sidekiq_processes).times do |idx|
begin
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(idx)}"
rescue
invoke 'sidekiq:monit:config'
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(idx)}"
end
end
end
end

desc 'Unmonitor Sidekiq monit-service'
task :unmonitor do
Array(fetch(:sidekiq_role)).each do |role|
on roles(role) do
sidekiq_processes(role).times do |idx|
begin
sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sidekiq_service_name(idx)}"
rescue
# no worries here
end
on roles(fetch(:sidekiq_role)) do
fetch(:sidekiq_processes).times do |idx|
begin
sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sidekiq_service_name(idx)}"
rescue
# no worries here
end
end
end
end

desc 'Start Sidekiq monit-service'
task :start do
Array(fetch(:sidekiq_role)).each do |role|
on roles(role) do
sidekiq_processes(role).times do |idx|
sudo_if_needed "#{fetch(:monit_bin)} start #{sidekiq_service_name(idx)}"
end
on roles(fetch(:sidekiq_role)) do
fetch(:sidekiq_processes).times do |idx|
sudo_if_needed "#{fetch(:monit_bin)} start #{sidekiq_service_name(idx)}"
end
end
end

desc 'Stop Sidekiq monit-service'
task :stop do
Array(fetch(:sidekiq_role)).each do |role|
on roles(role) do
sidekiq_processes(role).times do |idx|
sudo_if_needed "#{fetch(:monit_bin)} stop #{sidekiq_service_name(idx)}"
end
on roles(fetch(:sidekiq_role)) do
fetch(:sidekiq_processes).times do |idx|
sudo_if_needed "#{fetch(:monit_bin)} stop #{sidekiq_service_name(idx)}"
end
end
end

desc 'Restart Sidekiq monit-service'
task :restart do
Array(fetch(:sidekiq_role)).each do |role|
on roles(role) do
sidekiq_processes(role).times do |idx|
sudo_if_needed"#{fetch(:monit_bin)} restart #{sidekiq_service_name(idx)}"
end
on roles(fetch(:sidekiq_role)) do
fetch(:sidekiq_processes).times do |idx|
sudo_if_needed"#{fetch(:monit_bin)} restart #{sidekiq_service_name(idx)}"
end
end
end
Expand Down Expand Up @@ -136,9 +127,5 @@ namespace :sidekiq do
fetch(:sidekiq_monit_use_sudo)
end

def sidekiq_processes(role)
fetch(:"#{ role }_processes") || fetch(:sidekiq_processes)
end

end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace :load do
task :defaults do
set :sidekiq_user, nil
set :sidekiq_default_hooks, -> { true }

set :sidekiq_pid, -> { File.join(shared_path, 'tmp', 'pids', 'sidekiq.pid') }
Expand All @@ -13,8 +12,6 @@ namespace :load do
# Rbenv and RVM integration
set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(sidekiq sidekiqctl))
set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(sidekiq sidekiqctl))

set :sidekiq_monit_templates_path, -> { 'config/deploy/templates' }
end
end

Expand Down

0 comments on commit 5745888

Please sign in to comment.