本文介绍了为什么没有RVM我的delay_job失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 delayed_job ,然后启动守护程序以使用以下Ruby脚本运行作业:

I have a delayed_job installed, and I start the daemon to run the jobs with this Ruby script:

require 'rubygems'
require 'daemon_spawn'
$: << '.'

RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))

class DelayedJobWorker < DaemonSpawn::Base
  def start(args)
    ENV['RAILS_ENV'] ||= args.first || 'development'
    Dir.chdir RAILS_ROOT
    require File.join('config', 'environment')

    Delayed::Worker.new.start
  end

  def stop
    system("kill `cat #{RAILS_ROOT}/tmp/pids/delayed_job.pid`")
  end
end

DelayedJobWorker.spawn!(:log_file => File.join(RAILS_ROOT, "log", "delayed_job.log"),
                    :pid_file => File.join(RAILS_ROOT, 'tmp', 'pids', 'delayed_job.pid'),
                    :sync_log => true,
                    :working_dir => RAILS_ROOT)

如果我使用 rvmsudo 运行该命令,它将运行良好。

If I run the command with rvmsudo it works perfectly.

如果我只是使用没有RVM的Ruby命令,它失败了,这就是输出。我不知道为什么会这样。

If I simply use the Ruby command without RVM it fails and this is the output. I have no idea why this happens. Could you give me some clue?

user@mysystem:~/redeal.it/application$ ruby script/delayed_job start production
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/daemon-spawn-0.4.2/lib/daemon_spawn.rb:16:in `kill': Operation not permitted (Errno::EPERM)
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/daemon-spawn-0.4.2/lib/daemon_spawn.rb:16:in `alive?'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/daemon-spawn-0.4.2/lib/daemon_spawn.rb:125:in `alive?'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/daemon-spawn-0.4.2/lib/daemon_spawn.rb:176:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/daemon-spawn-0.4.2/lib/daemon_spawn.rb:176:in `select'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/daemon-spawn-0.4.2/lib/daemon_spawn.rb:176:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/daemon-spawn-0.4.2/lib/daemon_spawn.rb:165:in `spawn!'
from script/delayed_job:37:in `<main>'


推荐答案

您有权限问题。

简单地说:您的作业在另一个用户(可能是 root )下运行,因为使用了 rvmsudo ),守护程序spawn试图将其杀死。您将获得不允许的操作

Putting it simply: You have a delayed job running under another user (proprably root due to using rvmsudo), and daemon spawn is trying to kill it. You will get an Operation not permitted.

尝试先使用rvmsudo杀死delay_job,确保其未运行(尝试 ps aux ),然后尝试开始时没有 rvmsudo

Try killing delayed_job first with rvmsudo, make sure it is not running (try ps aux) and then try to start without rvmsudo.

应该可以。

这篇关于为什么没有RVM我的delay_job失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 22:08