diff --git a/lib/capistrano/tasks/monit.cap b/lib/capistrano/tasks/monit.cap index e52a60b..5c3ab31 100644 --- a/lib/capistrano/tasks/monit.cap +++ b/lib/capistrano/tasks/monit.cap @@ -38,13 +38,15 @@ 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 @@ -52,12 +54,14 @@ namespace :sidekiq do 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 @@ -65,27 +69,33 @@ namespace :sidekiq do 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 @@ -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