title: Rails Daemon stays in development mode
body: <p>I have a Rails application with a daemon that checks a mailbox for any new emails. I am using the <a href="http://github.com/look/fetcher/tree/master" rel="nofollow noreferrer">Fetcher</a> plugin for this task. The daemon file looks like this:</p>
  
  <pre><code>#!/usr/bin/env ruby
  require File.dirname(__FILE__) + '/../config/environment.rb'
  
  class MailFetcherDaemon &lt; Daemon::Base
  
    @config = YAML.load_file("#{RAILS_ROOT}/config/mail.yml")
    @config = @config['production'].to_options
  
    @sleep_time = @config.delete(:sleep_time) || 20
    def self.start
      puts "Starting MailFetcherDaemon"
      # Add your own receiver object below
      @fetcher = Fetcher.create({:receiver =&gt; MailProcessor}.merge(@config))
    ...
  </code></pre>
  
  <p>So I have it grab the new emails, parse them and create a resource from the parsed data. But when it tries to save the resource an exception is thrown. This is because the script  is automatically assigned the development environment. So it is using my development database configuration instead of the production environment (which is the config that I want). </p>
  
  <p>I have tried starting the script with:</p>
  
  <pre><code> rails-root$ RAILS_ENV=production; script/mail_fetcher start
  </code></pre>
  
  <p>but to no avail. It seems like when I load the environment.rb file it just defaults to the development environment and loads development.rb and the development database configuration from database.yml.</p>
  
  <p>Thoughts? Suggestions?</p>
  
  <p>Thanks</p>