daemons error -- probably a simple fix

I followed the instructions at http://railscasts.com/episodes/129-custom-daemon
for creating a daemon. Simple enough, right? Wrong...

For some reason, I keep getting an error when running the daemon even
if I remove all my custom code from the generated code. Anybody know
what I'm doing wrong??

The error and the daemon code is at http://pastie.org/456601 as well
as below:

I forgot to mention that I checked and the file mentioned in the error
is in that directory. Not sure why Rails thinks it's missing...

I've found a solution that works for me -- not sure if it's the
"right" way to fix this but it does the job.

I changed the directory settings in config/daemons.yml to:
dir_mode: normal
dir:

(used to be dir_mode: script and dir: ../../log)

I then expanded some of the paths used in mailer_ctl, and inserted
some code to populate the "dir" option (which was blank in the YML
file) with the expanded path of the log directory if the "dir_mode"
option is set to "normal".

#!/usr/bin/env ruby

require 'rubygems'
require "daemons"
require 'yaml'
require 'erb'

I tried this, but it still does not work. It seems that I always have
the following error whenever I require rails environment. And the
weird thing is that if I start the daemon first time using
"RAILS_ENV=development lib/daemons/mydaemon_ctl start" it works fine.
And then i stop the daemon using "RAILS_ENV=development lib/daemons/
mydaemon_ctl stop", it stops. But there is memory leak, possibly
because of the following exceptions. If I start the daemon again, it
does not work anymore. Please help.

The following is the error message. All of the uninitialized constants
in the following error message are actually my Model classes.

# Logfile created on May 25, 2009 by /
*** below you find the most recent exception thrown, this will be
likely (but not certainly) the exception that made the application
exit abnormally ***
#<NameError: uninitialized constant CorporationReferralCategory>
*** below you find all exception objects found in memory, some of them
may have been thrown in your application, others may just be in memory
because they are standard exceptions ***
#<NoMemoryError: failed to allocate memory>
#<SystemStackError: stack level too deep>
#<fatal: exception reentered>
#<NameError: uninitialized constant Calculator>
#<Errno::ENOENT: No such file or directory - /workspace/CA/BETA_3/
EconveyancePro/log/sphinx_index_daemon.rb.pid>
#<Errno::EEXIST: File exists - /workspace/CA/BETA_3/EconveyancePro/db/
sphinx/development>
#<Errno::EEXIST: File exists - /workspace/CA/BETA_3/EconveyancePro/db/
sphinx/development>
#<Errno::EEXIST: File exists - /workspace/CA/BETA_3/EconveyancePro/db/
sphinx/development>
#<Errno::EEXIST: File exists - /workspace/CA/BETA_3/EconveyancePro/db/
sphinx/development>
#<Errno::EEXIST: File exists - /workspace/CA/BETA_3/EconveyancePro/db/
sphinx/development>
#<Errno::EEXIST: File exists - /workspace/CA/BETA_3/EconveyancePro/db/
sphinx/development>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant Realtor>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant CticInterestQuestion>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant IndividualApplicationSetting>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant DocJob>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant TrustAccount>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant UtilitySearchFee>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant FctAccumulationAmount>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant Processor>
#<TypeError: can't dup TrueClass>
#<NameError: uninitialized constant CorporationReferralCategory>