Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: kelly felkins
help with debugging daemons [ reply ]  
2006-12-09 00:26
[a different version of this message was previously posted on rails talk]

I'm trying to get a daemon to work on debian using daemons gem. I installed daemons via gems and I'm running version 1.0.3.

I used daemon_generator from
http://kylemaxwell.typepad.com/everystudent/2006/08/after_writing_r.html

I created a daemon called test and ran it on OSX with no problem,
meaning that

./script/daemons start
and
./script/daemons stop

both work fine.

I moved it to a debian system, modifed test.rb to use the production
environment, and I can't get it to work. I've tried a bunch of things.


On the debian system
./script/daemons start

sometimes works. I see the daemon running, I see the monitor daemon
running, and
messages are going into the production log file.

If I try to stop it with

./script/daemons stop

the test daemon stops but the monitor does *not* stop. Then I get a log file for the test daemon (see content below).

It appears that the monitor is not responding to the TERM signal -- it seems to gobble it up and
keep running. On the theory that something else in
rails may ALSO be setting a term trap we added this code in an attempt to expose the trap:

def watch(applications)
foo = trap('TERM', { })
bar = trap('TERM', foo)

foo turned out to be 'default' and was no help. However, IT STARTED WORKING. I don't know why.

I hope this is of use to someone in finding and fixing this problem.

-Kelly





# Logfile created on Thu Dec 07 15:33:33 -0800 2006 by
logger.rb/1.5.2.9
failed to allocate memory
stack level too deep
exception reentered
uninitialized constant Rails
no such file to load -- rails.rb
No such file or directory - [snip]/log/test.rb.pid
no such file to load -- openssl
no such file to load -- http-access2
no such file to load -- xmlscan/scanner
no such file to load -- xml/parser
no such file to load -- tmail/scanner_c.so
no such file to load -- tmail/base64.so
test.rb.log (END)

Here is lib/daemons/test.rb:
#!/usr/bin/env ruby

#You might want to change this
ENV["RAILS_ENV"] ||= "production"

require File.dirname(__FILE__) + "/../../config/environment"

$running = true;
Signal.trap("TERM") do
$running = false
end

while($running) do

# Replace this with your code
ActiveRecord::Base.logger << "This daemon is still running at
#{Time.now}.\n"

sleep 10
end

and here is the ctl file:

#!/usr/bin/env ruby
require 'rubygems'
require "daemons"
require 'yaml'
require 'erb'
require 'active_support'

options = YAML.load(
ERB.new(
IO.read(
File.dirname(__FILE__) + "/../../config/daemons.yml"
)).result).with_indifferent_access
options[:dir_mode] = options[:dir_mode].to_sym

Daemons.run File.dirname(__FILE__) + '/test.rb', options
# this is a comment