enenkey
enenkey

Reputation: 1271

running delayed_job under monit with ubuntu

I'm struggling to get delayed_job working under rails 3.0.9 (ruby 1.9.2). The only way I have succeeded to run is to tape manualy the command rake jobs:work. But I want that to be automatically started when the rails application is starting.

I have installed monit under ubuntu and I configured it to launch a file located in my app. This fails looks like:

check process delayed_job with pidfile /home/me/myapp/tmp/pids/delayed_job.pid
start program = "/home/me/myapp/script/delayed_job start"
stop program = "/home/me/myapp/script/delayed_job stop" 

And I added the environment setting in the delayed_job script file:

#!/usr/bin/env ruby

    ENV['RAILS_ENV'] = "development"
    require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
    require 'delayed/command'
    Delayed::Command.new(ARGV).daemonize

When I run the command "sudo monit start delayed_job" I get the following error:

/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- bundler/setup (LoadError)

So I guess it is because sudo is using a wrong version of ruby environment I tried then the solution of: rvm monit delayed_job

by adding rvm -S in the start program / stop program lines. But it still failing with the error : rvm command not found

my rvm dir is located in my home dir /home/me/.rvm

I tried to find workarounds in (sudo changes PATH - why?) to change the PATH environment variable by adding

/usr/bin/env PATH=/home/me/.rvm/bin:$PATH

The command "sudo monit start delayed_job" succeeded! and the worker started. But the issue is: When I launch sudo /etc/init.d/monit start and when I look to the syslog I still get 'delayed_job' failed to start

So I don't know how to investigate more, how to get more verbose errors for monit.

Upvotes: 2

Views: 2023

Answers (2)

Gaston Morixe
Gaston Morixe

Reputation: 847

This i s the only line that worked for me that read the ENV properly

start program = "/usr/local/rvm/bin/rvm-shell -c 'cd /var/www/[APP]/current/; RAILS_ENV=production bundle exec bin/delayed_job start'"

Hope it helps!

Upvotes: 1

enenkey
enenkey

Reputation: 1271

I have finally succeeded to solve this issue. I modified the monit file like this:

check process delayed_job with pidfile /home/me/myapp/tmp/pids/delayed_job.pid
start program = "/bin/su - me -c 'cd /home/me/myapp/; script/delayed_job start'"
stop program = "/bin/su - me -c 'cd /home/me/myapp/; script/delayed_job stop'"

I have also downgraded the daemons gem because it seems that there are problems with the latest version. So I'm using now daemons v 1.0.10

I also modified the rights of the log file /home/me/myapp/log/delayed_job.log, because it seems that is was created before my root and my user had no access to it (I had problems to test the command "script/delayed_job start" with "me" user)

Upvotes: 2

Related Questions