在ubuntu的monit下运行delayed_job [英] running delayed_job under monit with ubuntu
问题描述
我正在努力让延迟工作在3.0.9(红宝石1.9.2)下工作。我成功运行的唯一方法是手动录制rake jobs:work命令。
但是我希望在Rails应用程序启动时能自动启动。
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.
我已经在ubuntu下安装了monit,并配置了它以启动位于以下位置的文件我的应用失败看起来像:
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"
我在delay_job脚本文件中添加了环境设置:
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
当我运行命令 sudo monit start delay_job时,出现以下错误:
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)
所以我想这是因为sudo使用了错误版本的ruby envi ronment
然后尝试了以下解决方案:
rvm monit delay_job
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
通过在启动程序/停止程序行中添加rvm -S。
但它仍然失败,并显示以下错误:找不到rvm命令
by adding rvm -S in the start program / stop program lines. But it still failing with the error : rvm command not found
我的rvm目录位于我的主目录/home/me/.rvm
my rvm dir is located in my home dir /home/me/.rvm
我试图在( sudo更改路径-为什么中找到解决方法?)通过添加
/usr/bin/env PATH=/home/me/.rvm/bin:$PATH
命令 sudo monit start delay_job成功!工人开始了。
但是问题是:当我启动sudo /etc/init.d/monit start并查看系统日志时,我仍然得到'delayed_job'无法启动
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
所以我不知道如何进行更多调查,如何获得更多有关monit的错误。
So I don't know how to investigate more, how to get more verbose errors for monit.
推荐答案
我终于成功解决了这个问题。
我是这样修改监视文件的:
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'"
我有还降低了daemons gem的等级,因为最新版本似乎存在问题。因此,我现在使用的是 daemons v 1.0.10
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
我还修改了日志文件/ home / me / myapp / log的权限/delayed_job.log,因为它似乎是在我的root用户之前创建的,而我的用户无法访问它(我在用 me用户测试命令 script / delayed_job start时遇到问题)
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)
这篇关于在ubuntu的monit下运行delayed_job的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!