4

我已经delayed_job安装了一个,我启动了守护进程来使用这个 Ruby 脚本运行作业:

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它将完美运行。

如果我只是使用没有 RVM 的 Ruby 命令,它会失败,这就是输出。我不知道为什么会这样。你能给我一些线索吗?

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>'
4

2 回答 2

5

您有权限问题。

简而言之:您有一个在另一个用户下运行的延迟作业(可能是root由于 using rvmsudo),而守护进程 spawn 正试图杀死它。你会得到一个Operation not permitted.

尝试先使用 rvmsudo 杀死延迟作业,确保它没有运行(尝试ps aux),然后尝试不使用rvmsudo.

它应该工作。

于 2012-07-01T04:53:46.393 回答
4

首先,查看 shared/pids/delayed_job.pid 并查看进程是否正在运行。在我的情况下,它看起来像是被关闭而不干净,并且 pid 文件被留在原处。部署脚本试图杀死不存在的进程并给出该权限错误。

我已经删除了delayed_job.pid 并且部署成功了。

于 2012-11-29T11:06:33.673 回答