Dan Mazzini
Dan Mazzini

Reputation: 1001

Ruby daemons with Rails 3.1 works with "run", doesn't work with "start" in production env

I have a custom daemon in my Rails 3.1 app. The daemon works in my development environment if I call

ruby script/daemon.rb start

In my production environment, if I use the same command, the daemon is started, but it shuts down immediately and without any trace in my log. If, on the other hand, I run the daemon using

ruby script/daemon.rb run

it works. Why? And - where can I find a log of what happens?

My daemon script is like this:

require 'daemons'
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))

Daemons.run_proc('mydaemon') do
  logger = ActiveSupport::BufferedLogger.new(
    File.join(Rails.root, "log", "mydaemon.log"),Logger::INFO)
  Rails.logger = logger
  ActiveRecord::Base.logger = logger

  loop do
    MyClass.dosomething
    sleep(5)
  end
end

Upvotes: 2

Views: 1051

Answers (1)

moritz
moritz

Reputation: 25757

Check out the documentation for the daemons gem: http://daemons.rubyforge.org/classes/Daemons.html#M000005

Specifically, have a look at the :log_output option.

Upvotes: 1

Related Questions