我安装了 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>'
最佳答案
您有权限问题。
简而言之:您有一个在另一个用户下运行的延迟作业(由于使用 root
可能是 rvmsudo
),并且守护进程 spawn 试图杀死它。你会得到一个 Operation not permitted
。
首先尝试使用 rvmsudo 终止延迟作业,确保它没有运行(尝试 ps aux
),然后尝试在没有 rvmsudo
的情况下启动。
它应该工作。