Why does my delayed_job fail without RVM?

I have delayed_job set, and I run a daemon to run 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) 

If I run the command with rvmsudo , it works fine.

If I just use the Ruby command without RVM, it fails, and this is the result. I have no idea why this is happening. Could you give me a hint?

 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>' 
+3
source share
2 answers

You have permission.

Simply put: you have work with the delay being performed under another user (proprably root due to the use of rvmsudo ), and daemon spawn is trying to kill it. You will receive Operation not permitted .

Try killing delayed_job first with rvmsudo, make sure it doesn't work (try ps aux ), and then try to run without rvmsudo .

It should work.

+5
source

First, take a look at the generic / pids / delayed _job.pid and see if the process is running. In my case, it looked like it was closed unclean, and the pid file remained in place. The deployment script tried to kill a non-existent process and gave this permission error.

I deleted delayed_job.pid and executed it.

+3
source

All Articles