Topic: How to run script with Daemons

In Rails 3.2.3 I have a delayed_delta script

#!/usr/bin/env ruby
#automatically called

#this is the current path where this is run in
dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))

daemon_options = {
  :multiple => false,
  :dir_mode => :normal,
  :dir => File.join(dir, 'tmp', 'pids'), #this puts the pid files in /rails_path/tmp/pids
  :backtrace => true

#this runs the first delayed job process
Daemons.run_proc('delayed_job_1', daemon_options) do
  if ARGV.include?('--')
    ARGV.slice! 0..ARGV.index('--')

  Dir.chdir dir
  RAILS_ENV = ARGV.first || ENV['RAILS_ENV'] || 'development'
  require File.join('config', 'environment')
    :min_priority => ENV['MIN_PRIORITY'],
    :max_priority => ENV['MAX_PRIORITY']

And when I run

bundle exec script/delayed_delta stop

I get

script/delayed_delta:19:in `<main>': uninitialized constant Daemons (NameError)

But daemons is indeed in my Gemfile

gem 'daemons', '1.1.8' # latest

This worked previously on 2.3.14 before the upgrade.

Re: How to run script with Daemons

You probably moved the 'require daemons' out of config/environment during the upgrade process and it's now handled by virtue of Gemfile.

Just put

require 'daemons'

at the top of your script.

Last edited by BradHodges (2012-05-10 14:53:49)

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.