6

I have read a lot about monitoring delayed_job with monit. The implementation is pretty easy and straight forward. But When one worker is not enough how do I setup monit to ensure that, let's say, 10 workers are constantly running?

Lester Celestial
  • 1,454
  • 1
  • 16
  • 26

1 Answers1

7

You can just replicate the same config you have for the first worker N times. Suppose you have 5 workers, you'll monitor all of them with the following:

check process delayed_job.0
   with pidfile /path/to/shared/pids/delayed_job.0.pid
   start program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job -n 5 start' - user"
   stop program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job stop' - user"

check process delayed_job.1
   with pidfile /path/to/shared/pids/delayed_job.1.pid
   start program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job -n 5 start' - user"
   stop program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job stop' - user"

check process delayed_job.2
  with pidfile /path/to/shared/pids/delayed_job.2.pid
  start program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job -n 5 start' - user"
  stop program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job stop' - user"

check process delayed_job.3
  with pidfile /path/to/shared/pids/delayed_job.3.pid
  start program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job -n 5 start' - user"
  stop program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job stop' - user"

check process delayed_job.4
  with pidfile /path/to/shared/pids/delayed_job.4.pid
  start program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job -n 5 start' - user"
  stop program = "/bin/su -c '/usr/bin/env RAILS_ENV=production /path/to/current/script/delayed_job stop' - user"
matteo
  • 2,256
  • 1
  • 13
  • 10
  • 6
    Doesn't this have the potential for issues if for example only delayed_job.4.pid goes down? Wouldn't it start 5 more nodes? – Bradley Aug 21 '13 at 15:07
  • 3
    @Bradley no it will not, if you try to start 5 workers while for example 2 are already running, delayed_job will only start 3 new workers, and keep those first 2 running. – Nafaa Boutefer Aug 02 '15 at 21:23
  • @NafaaBoutefer Thank you very much for that comment! I was not aware of this behavior and it saved me a lot of troubles. I verified with https://gist.githubusercontent.com/paneq/fe0c27d99c943ecb81023badf80b10d7/raw/4c01bab4105e3dc69b747c2ae20e9f8275606d90/log.txt – Robert Pankowecki Mar 27 '18 at 08:25