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
/usr/local/lib/ruby/gems/1.9/gems/bundler-1.2.3/bin/bundle
or even prefix that path with path to ruby. Use commandwhich bundle
to find full path. – Tho