Delayed Job and Monit
When I first got started running Delayed::Job under Monit, I searched around for a pid dropping launch script but couldn’t find one.
I did find Running Delayed::Worker as a daemon but consistently had trouble running that under Monit. For some reason, Monit didn’t catch the pid in time or didn’t wait long enough after restart or something and I regularly ended up with multiple Delayed::Workers running simultaneously.
Because Monit requires a pid file, the command I use locally (script/runner Delayed::Job.new.start) doesn’t work.
As a result, I’ve been hacking out a solution in bash that I’m happy with. Check it out on github. Note that it requires two files, both a ruby file and a bash file.
To start a runner, you can do dj_monit_runner.sh start production 1. To stop that one, dj_monit_runner.sh start production 1. You can replace the third argument with an arbitrary identifier for your runner if you need to have multiple runners.
To use this with monit, put something like job_runner.monit in /etc/monit.d and sudo monit reload (after editing paths and your app name, obviously).
We’re using this in production at Stormweight and have had no orphaned or flapping workers since switching over to this script. We’re using ubuntu, but it should be fairly universal.