Im using Monit to monitor a ruby script that uses Ruby daemons gem, which launches a separate process with PID - following the instructions from Monitor ruby processes with Monit
In order to execute the ruby script I need to include RVM in the Monit start
and stop
strings, so I have access to all the gems.
However when .monitrc
executes I get the following error:
$rvm_path (/usr/local/rvm) does not exist./home/william/.rvm/scripts/rvm: line 174: rvm_is_a_shell_function: command not found
/home/william/.rvm/scripts/rvm: line 185: __rvm_teardown: command not found
'myserver_1' failed to start
Aborting event
I added PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm
to the start
and stop
command strings to try and include RVM. However still it doesn't work
Config file .monitrc
:
....
check process myserver_1
with pidfile /home/william/ruby/barclays/myapp.rb.pid
start = "/bin/bash -c 'PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm && ruby /home/william/ruby/barclays/daemonloader.rb start'"
stop = "/bin/bash -c 'PATH=$PATH:/home/william/.rvm/bin && . /home/william/.rvm/scripts/rvm && ruby /home/william/ruby/barclays/daemonloader.rb stop'"
....
Thanks for your help.
EDIT
Ive got a feeling the problem is related to environment variables. Quoting from this page
You should also know that for security reasons Monit purges the environment and only sets a spartan PATH variable that contains /bin, /usr/bin, /sbin and /usr/sbin. If your program or script dies, the reason could be that it expects certain environment variables or to find certain programs via PATH. If this is the case you should set the environment variables you need directly in the start or stop script called by monit.
Finally, Monit uses the system call execv to execute a program or a script. This means that you cannot write shell commands directly in the start, stop or exec statements. To do this, you must do as above; start a shell and issue your commands there. For example:
start program = "/bin/bash -c 'my shell command && my other command'"
Use this:
/path/to/rvm/bin/rvm in /path/to/project do ...
Replace the paths with proper directories for rvm and project and the ...
with the commands to stop/start - try:
/usr/bin/env "HOME=/home/william rvm_path=/home/william/.rvm
/home/william/.rvm/bin/rvm in /home/william/ruby/project do
ruby daemonloader.rb start"
This command will load RVM, cd
into project path, load ruby for this ruby and execute given command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With