Last Updated: February 25, 2016
·
2.559K
· mremond

monit and rvm deployment

Integrating monit to monitor Ruby daemon script in an RVM context has always been a nightmare. I always have to spend hours trying to find the right magic command to start my script in the proper context, without any meaningful feedback from monit.

There is a few thing you have to know to ease that task.

Monit runs with a very basic environment defined

You will have a very short path and no $HOME for example.

The simplest thing to test your command is thus to test your start command with this basic environment. You can use the following:

sudo su
env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/sh

Use rvm-shell

rvm environment depends on Bash. If your source your rvm script as usual from sh it will fail.
The solution is to use rvm-shell command from your rvm environment.

Properly set your environment variable

Do not forget that in monit context there will be no RAILS_ENV and no HOME variable. Do not forget to set them if you need them.

Here is an example of a valid start command for monit:

/usr/local/bin/rvm-shell -c 'cd /home/myuser/myapp/current; RAILS_ENV=production bundle exec script/daemon_monitor start &' 

2 Responses
Add your response

Thanks for sharing this!

over 1 year ago ·

Thanks a Ton.

over 1 year ago ·