Monit Ruby on Rails Sidekiq

Brian picture Brian · Nov 17, 2012 · Viewed 8k times · Source

I'm trying to set up Monit for Sidekiq. Here's what I have so far for my config file:

 check process sidekiq_site
  with pidfile /var/www/site/tmp/pids/sidekiq.pid
  start program = "bundle exec sidekiq -C /var/www/site/config/sidekiq.yml -P /var/www/site/tmp/pids/sidekiq.pid" with timeout 90 seconds
  if totalmem is greater than 200 MB for 2 cycles then restart # eating up memory?
  group site_sidekiq

The problem is I'm getting a message when I run monit reload that the program "bundle" does not exist.

Does anyone have a solution for this?

Answer

Danny picture Danny · Aug 9, 2013

After working on my own monit and sidekiq config, I can share what worked for me running ubuntu.

First, there exists a sidekiq upstart script for ubuntu if you are on that distro. There are scripts for sidekiq and for managing the workers: https://github.com/mperham/sidekiq/tree/master/examples/upstart/manage-one

I ran into a few errors with that default upstart script, as I am using rvm. Checking /var/logs/upstart/sidekiq-0.log shed some light on the problems. This line:

exec bin/sidekiq -i ${index} -e production -C config/sidekiq.yml -P tmp/pids/sidekiq-${index}.pid

needed to be changed to exec bundle exec sidekiq + the options

Then, for keeping everything in line with my rvm install, I changed the following:

#source $HOME/.rvm/scripts/rvm
source /usr/local/rvm/scripts/rvm

In /etc/monit/monitrc I reference the upstart scripts and have:

# sidekiq
check process sidekiq
  with pidfile /var/www/apps/myapp/current/tmp/pids/sidekiq-0.pid
  start program = "/usr/bin/sudo start sidekiq index=0"
  stop program = "/usr/bin/sudo stop sidekiq index=0"
  if totalmem is greater than 500 MB for 2 cycles then restart # eating up memory?
  if 3 restarts within 5 cycles then timeout