I am trying to run delayed_job using monit, but its failing to run as rvm's paths (local rvm installation per user basis) are not available to the command. My application is a rails2 app with bundler. Monit is not able to find bundler. Does anyone have any suggestions as to how i can tell about the rvm paths to monit?
I am getting the error
[rails@x-rws1 current]$ monit start delayed_job -c config/delayed_job.monitrc
'delayed_job' start: /usr/bin/env
'delayed_job' failed to start
no such file to load -- bundler
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/rails/public_html/myapp/current/config/../config/preinitializer.rb:3
/home/rails/public_html/myapp/current/config/boot.rb:28:in `load'
/home/rails/public_html/myapp/current/config/boot.rb:28:in `preinitialize'
/home/rails/public_html/myapp/current/config/boot.rb:10:in `boot!'
/home/rails/public_html/myapp/current/config/boot.rb:123
/home/rails/public_html/myapp/current/config/environment.rb:12:in `require'
/home/rails/public_html/myapp/current/config/environment.rb:12
/home/rails/public_html/myapp/current/script/delayed_job:3:in `require'
/home/rails/public_html/myapp/current/script/delayed_job:3
My config/delayed_job.monitrc
set daemon 120
check process delayed_job with pidfile /home/rails/public_html/myapp/shared/pids/delayed_job.pid
start program = "/usr/bin/env RAILS_ENV=staging /home/rails/public_html/myapp/current/script/delayed_job start"
stop program = "/usr/bin/env RAILS_ENV=staging /home/rails/public_html/myapp/current/script/delayed_job stop"
and script/delayed_job executable
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize
If you already have properly working monit with other services and just need to add delayed_job daemon for rvm environment you can try to use this conf file (it works for me)
/etc/monit/conf.d/delayed_job.conf (i have ubuntu server)
check process delayed_job with pidfile /{project_folder}/tmp/pids/delayed_job.pid
start program = "RAILS_ENV=production rvm -S /{project_folder}/script/delayed_job start"
stop program = "RAILS_ENV=production rvm -S /{project_folder}/script/delayed_job stop"
Here rvm -S
command let script run under current rvm ruby environment
You can try to start daemon with
$ RAILS_ENV=production rvm -S /{project_folder}/script/delayed_job start
command and if daemon will start (check it with changing last word to 'status') than you have good chances with delayed_job.conf file
And do not forget to check if pid file had created in tmp/pids/
folder too
'rvm -S' didn't work for me.
The instructions on http://matthew.mceachen.us/blog/howto-make-system-wide-rvm-installations-work-with-cron-monit-delayed_job-and-passenger-1021.html did.
check process delayed_job.0
with pidfile /u/apps/adgrok/shared/pids/delayed_job.0.pid
start program = "/usr/local/bin/rvm-shell -c 'RAILS_ENV=production /u/apps/adgrok/current/script/delayed_job start -i 0'" as uid deploy and gid deploy
stop program = "/usr/local/bin/rvm-shell -c 'RAILS_ENV=production /u/apps/adgrok/current/script/delayed_job stop -i 0'" as uid deploy and gid deploy
if 2 restarts within 15 cycles then timeout
There is also a noteworthy reference to a thread of discussion with the author of RVM about monit : http://groups.google.com/group/rubyversionmanager/browse_thread/thread/d1a6c1f6396a8bf6/51afece4c8943912?#51afece4c8943912
来源:https://stackoverflow.com/questions/6298061/rvm-monit-delayed-job