1

I am deploying a rails app with sidekiq. On each deploy Capistrano stops a previous running version of sidekiq (a ruby process) and then starts a new one. I am monitoring the sidekiq pid file with monit.

Problem: Each time I deploy the pid file changes but monit detects that it has changed and restarts the process. Over the period of a few days and multiple releases I end up with multiple sidekiq instances when I only want one.

Here is my monit config for sidekiq:

check process sidekiq_main with pidfile /srv/apps/orders/current/tmp/pids/sidekiq.pid
  every 3 cycles
  start program = "/bin/bash -c -l 'cd /srv/apps/orders/current ; nohup bundle exec sidekiq -e production -C /srv/apps/orders/current/config/sidekiq.yml -i 0 -P /srv/apps/orders/current/tmp/pids/sidekiq.pid >> /srv/apps/orders/current/log/sidekiq.log 2>&1 &'"
  stop program  = "/bin/bash -c -l 'cd /srv/apps/orders/current ; bundle exec sidekiqctl stop /srv/apps/orders/current/tmp/pids/sidekiq.pid 10'"
  group sidekiq

Is there a way to configure monit to allow for the pid file to change and only make sure that a sidekiq instance is running?

1 Answer 1

4

Override the default capistrano task to ensure that restarting sidekiq is done through monit.

For example, you could add this to your deploy.rb

namespace :sidekiq do    
  desc "Restart sidekiq"
  task :restart, :roles => :app, :on_no_matching_servers => :continue do
    run "sudo /usr/bin/monit restart sidekiq"
  end
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.