Skip to content

Commit

Permalink
Merge pull request seuros#100 from torchlight-dev/add-process-count-p…
Browse files Browse the repository at this point in the history
…er-host

Add support for different number of processes per host on monit.cap
  • Loading branch information
seuros committed Aug 5, 2015
2 parents 7bc7310 + 1330e7f commit ac4f81f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ set :sidekiq_monit_use_sudo, false
```

## Changelog
- 0.5.4: Add support for custom count of processes per host in monit task @okoriko
- 0.5.3: Custom count of processes per each host
- 0.5.0: Multiple processes @mrsimo
- 0.3.9: Restore daemon flag from Monit template
Expand Down Expand Up @@ -131,6 +132,7 @@ set :sidekiq_monit_use_sudo, false
- [Saicheg] (https://github.com/Saicheg)
- [Alex Yakubenko] (https://github.com/alexyakubenko)
- [Robert Strobl] (https://github.com/rstrobl)
- [Eurico Doirado] (https://github.com/okoriko)

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano/sidekiq/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Capistrano
module Sidekiq
VERSION = '0.5.3'
VERSION = '0.5.4'
end
end
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 ac4f81f

Please sign in to comment.