2012-07-01 179 views
3

我安裝了delayed_job,我開始守護進程來運行這個Ruby腳本的工作:爲什麼我的delayed_job在沒有RVM的情況下失敗?

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命令,它會失敗,這是輸出。我不知道爲什麼會發生這種情況。你能給我一些線索嗎?

[email protected]:~/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>' 

回答

5

您有權限問題。

簡單地說:你有一個延遲的作業在另一個用戶下運行(由於使用rvmsudo,原來是root),而守護進程產生的是試圖殺死它。你會得到一個Operation not permitted

嘗試先用rvmsudo查殺delayed_job,確保它未運行(嘗試ps aux),然後嘗試在沒有rvmsudo的情況下啓動。

它應該工作。

+0

謝謝,現在它的工作 – mottalrd

3

首先,看看shared/pids/delayed_job.pid,看看進程是否在運行。就我而言,它看起來像是關閉了不乾淨,pid文件留在原地。部署腳本試圖殺死不存在的進程,並給出了該權限錯誤。

我已刪除delayed_job.pid並部署成功。

+0

好thx幫了我很多! – jethroo

相關問題