Skip to content

Commit

Permalink
Support multiple processes per host.
Browse files Browse the repository at this point in the history
  • Loading branch information
okoriko committed Aug 5, 2015
1 parent 7bc7310 commit dcab28b
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions lib/capistrano/tasks/monit.cap
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,64 @@ namespace :sidekiq do

desc 'Monitor Sidekiq monit-service'
task :monitor do
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)}"
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
end
end
end
end

desc 'Unmonitor Sidekiq monit-service'
task :unmonitor do
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
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
end
end
end
end

desc 'Start Sidekiq monit-service'
task :start do
on roles(fetch(:sidekiq_role)) do
fetch(:sidekiq_processes).times do |idx|
sudo_if_needed "#{fetch(:monit_bin)} start #{sidekiq_service_name(idx)}"
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
end
end
end

desc 'Stop Sidekiq monit-service'
task :stop do
on roles(fetch(:sidekiq_role)) do
fetch(:sidekiq_processes).times do |idx|
sudo_if_needed "#{fetch(:monit_bin)} stop #{sidekiq_service_name(idx)}"
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
end
end
end

desc 'Restart Sidekiq monit-service'
task :restart do
on roles(fetch(:sidekiq_role)) do
fetch(:sidekiq_processes).times do |idx|
sudo_if_needed"#{fetch(:monit_bin)} restart #{sidekiq_service_name(idx)}"
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
end
end
end
Expand Down Expand Up @@ -126,5 +136,9 @@ namespace :sidekiq do
fetch(:sidekiq_monit_use_sudo)
end

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

end
end

0 comments on commit dcab28b

Please sign in to comment.