我安装了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>'
答案 0 :(得分:5)
您有权限问题。
简单地说:你有一个延迟的工作在另一个用户下运行(由于使用root
而可预测rvmsudo
),并且守护程序spawn试图杀死它。您将获得Operation not permitted
。
首先尝试使用rvmsudo终止delayed_job,确保它没有运行(尝试ps aux
),然后尝试在没有rvmsudo
的情况下启动。
它应该有用。
答案 1 :(得分:3)
首先,看看shared / pids / delayed_job.pid,看看进程是否正在运行。在我的情况下,看起来它被关闭了不洁,并且pid文件留在原地。部署脚本试图杀死不存在的进程并且正在提供该权限错误。
我删除了delayed_job.pid并成功部署。