1
votes

I've got a problem getting delayed_job script to work.

The delayed_job rake tasks "rake jobs:work" works fine in development and in production environment. But when I try to start it up with the script I get the following error:

user:~/rails1/current$ RAILS_ENV=production script/delayed_job start
/home/user/rails1/shared/bundle/ruby/1.9.1/gems/delayed_job-4.0.0/lib/delayed/command.rb:73:in `mkdir': File exists - /home/user/rails1/releases/20131218094848/tmp/pids (Errno::EEXIST)
    from /home/user/rails1/shared/bundle/ruby/1.9.1/gems/delayed_job-4.0.0/lib/delayed/command.rb:73:in `daemonize'
    from script/delayed_job:5:in `<main>'

As far as I know there is this code snippet in the delayed_job lib file command.rb (https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/command.rb)

def daemonize
      dir = @options[:pid_dir]
      Dir.mkdir(dir) unless File.exists?(dir)

      if @worker_count > 1 && @options[:identifier]
        raise ArgumentError, 'Cannot specify both --number-of-workers and --identifier'
      elsif @worker_count == 1 && @options[:identifier]
        process_name = "delayed_job.#{@options[:identifier]}"
        run_process(process_name, dir)
      else
        worker_count.times do |worker_index|
          process_name = worker_count == 1 ? "delayed_job" : "delayed_job.#{worker_index}"
          run_process(process_name, dir)
        end
      end
    end

which is causing my error.

As the error message says, the directory tmp/pids exists. But in the code there is an "unless" clause which says, that it shouldn't be created in case it exists. So why does the script tries to make the directory?

I've generated the script in development environment. Is it sensitive to the environment? This is the script:

#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize

Does anybody have a clue? just for your information: the daemons gem, which delayed_job needs, is in my gemfile.

UPDATE: I tried the start script now locally on my dev machine and there it works. But it still fails on my production machine. So the rake task "rake jobs:work" works on my dev machine and on the prodution server, but the script in script/delayed_job works only on my local dev machine.

2
When does it work in production and when doesn't it? That part isn't fully clear to me. Is it possible that it works when your start it manually, and that it doesn't when you deploy through Capistrano? - janfoeh
It works only through the rake task. Both, in development and in production. But the script doesn't work. But I tried the script only on the production server because on my local machine I work on an mounted ntfs partition with ubuntu. And there I don't have execution rights for scripts. I have to shift it on the ubuntu partition to try it locally. Will do it now and update the post! - coderuby
What script doesn't work? - janfoeh
the delayed_job script in script/delayed_job doesn't work, which you use with RAILS_ENV=production script/delayed_job start to start delayed_job as a service. I copied my rails app over to the ubuntu partition to change the execution rights of the delayed_job script. On my local development machine it starts well. But on my production server I still get the error as mentioned in the post. - coderuby

2 Answers

2
votes

I found the solution. The tmp/pids was a symlink created through my hoster's capistrano recipe. It linked to a shared folder. But the corresponding directory wasn't there. Creating it resolved the problem!

0
votes

To add to this, you will want to keep tmp in your .gitignore, so just add an empty file to the directory and do a

git add tmp/pids/empty -f

to get the directory structure into your version control.