I have a daemon which works within rails dev env but failed to startup within production env.
here is a sniffer of the daemon:
...
ENV["RAILS_ENV"] ||= "development"
require File.dirname(__FILE__) + "/../../config/environment"
ActionController::Base.perform_caching = false
....
logger = Logger.new(RAILS_ROOT + '/log/foo_queue.log')
server = Servolux::Server.new('FooWorkerPool',
:interval => 1,
:pid_file => RAILS_ROOT + '/tmp/pids/foo_queue.pid',
:logger => logger)
server.extend FooWorkerPool
daemon = Servolux::Daemon.new(:server => server,
:log_file => RAILS_ROOT + '/log/foo_queue.log')
daemon.startup
Servolux::Daemon#started? returned false in production env but the preforked worker actually started. when I add a debug line to Servolux::Daemon#started?:
logger.debug "logfile updated? #{@logfile_reader.updated?}"
@logfile_reader.updated?
Servolux::Daemon#started? returns true then the daemons start without problem.
I have written some tests in order to reproduce this problem, but I cannot get it to manifest. A few minor changes have been made to the Daemon class, and they might solve your problem. Would you try building a gem from the HEAD of the servolux repository and see if this issue still exists?
You will need to install the 'bones' gem in order to use the rake tasks for building the servolux gem ...
gem install bones
git clone git://github.com/TwP/servolux.git
cd servolux
rake gem
gem install pkg/servolux-0.9.0.a.gem
I have not much time to digging around this problem. I did test the edge servolux, the problem didn't go away.
It get worse when raise Server.interval(dev env have the same problem sometimes).
The Daemon#started? method will not return true until the "log/foo_queue.log" file is modified in some fashion. If the logger is buffering messages before writing to the log file, it is very possible that the timeout is being reached. This will cause Daemon#startup? to return false.
That's the best idea I have right now.
I found the problem may cause by LogfileReader#updated?.
The LogfileReader#updated? will always return false on it's first call if @look_for is nil.
I'm not fully understand the design philosophy of Servolux or the UNIX programming. I was wondering why we need LogfileReader, @piper.pid is not enough? And why we need Servolux::Threaded anyway. This things really bothers me, looking for your answer.