Prayer Letters


November 2006

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    

My Online Status

« About my ministry | Main | Interview with Mat Weiss »

September 06, 2006



Ah. Well, I guess I'll switch then :P


We used railscron and it works reasonably well. With a few tweaks, it doesn't crash on our system any more. Not bad for a first attempt Kyle.

I agree that a general daemon framework is better though, so we may give the daemon_gen a try. Of course, it seems strange that a campus ministry would be creating daemons.


FYI, you can see it in action at

Aaron Blohowiak

Ahh, this is great.

one issue with this way of doing things is that you must wait the sleep time to expire before the process actually dies. This is not good if you want your task to happen only once a day.

you can overcome this with the following:

term_check_duration = 10 #10 seconds
interval_in_seconds = 3600 # 1 hour

while($running) do

# Replace this with your code
if(skipped_total > interval_in_seconds)
skipped_total = 0
ActiveRecord::Base.logger << "This daemon is still running at #{}.\n"

sleep term_check_duration
skipped_total += term_check_duration

i haven't checked that code yet, but i think that should do the trick.

does your config/deploy.rb now contain something like the following?

desc "Stop daemons before deploying"
task :before_deploy do
run "#{current_path}/script/daemons stop"

desc "Start daemons after deploying"
task :after_deploy do
run "#{current_path}/script/daemons start"

thanks for the hard work!

Kyle Maxwell


The TERM signal causes the sleep to abort early, so the extra trickery you suggest is not needed.

The capistrano recipe looks similar to what I use.


Is daemon_generator *nix only? When I tried it on my Windows machine, I got the error:
lib/daemons/monitor.rb:61:in `fork': the fork() function is unimplemented on this machine (NotImplementedError)


Kyle Maxwell

Yeah, it's *nix only.


I probably have done something wrong but I can't get script/generate daemon to work. I'm on Ubuntu 6.06.

I did:
sudo gem install daemons (succeeded)
rails app
cd app
script/generate daemon test

The generate statement fails with Couldn't find 'daemon' generator.

Did I miss something? I haven't installed any generators before - just used the stock rails generators.

Loren Johnson

I'm having the same problem as Andrew Carter above. Gem installed fine and then when I go to generate I get "Couldn't find 'daemon' generator" error.

Is there any solution to this? I am running in OS/X on Locomotive but will be deploying to a straight Unix box...

I'm baffled.

Dan Reverri

I am also running into the problem of not having a deamon generator.

I think gem might be installing:

Loren Johnson

Got ahold of Matt and got my problem figured-out. It seems I was missing a very critical step of installing his plugin. I think the daemon gem pre-existed this application and Matt's work is found in the following plugin installation after the daemon gem is hooked-up:

rails test
sudo gem install daemons
cd test
ruby script/plugin install
ruby script/generate daemon tester
ruby script/daemons start

That got me there in a jiffy.

Thanks Matt and I hope that this helps someone else.

Loren Johnson

OOPS... the comment got fouled.. Here is the all critical line... replace the straight url above with this full command

ruby script/plugin install

Loren Johnson

OOPS... the comment got fouled.. Here is the all critical line... replace the straight url above with this full command

"ruby script/plugin install"


This seems to be working for me but when i go to stop the daemon I see this in my error log. The daemon doesn't seem to die gracefully. Can someone please let me know how to silence this. This is in my /log/#daemon#.rb.log.

failed to allocate memory
stack level too deep
exception reentered
no such file to load -- daemons
no such file to load -- openssl
no such file to load -- active_support
uninitialized constant Rails
no such file to load -- rails.rb
no such file to load -- tmail/
No such file or directory - /home/pb/sites/test/log/
no such file to load -- net/https
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/


I'm also having a problem running on OS X with Locomotive 2.0.8

This is what I get after creating the test daemon:

# Logfile created on Thu Jan 25 02:19:31 GMT 2007 by logger.rb/
no such file to load -- daemons
failed to allocate memory
stack level too deep
exception reentered
no such file to load -- active_support

Kyle Maxwell

Hi all,
Apparently, daemon_generator doesn't like Rails 1.2. I'll try to issue a fix soon.



Any news on the fix? :)


Stupid me, I see it now ;p


Kyle, I'm looking for to using daemon generator but am having similar problems to those posted above:

no such file to load -- daemons
failed to allocate memory
... etc etc

I'm on Rails 1.2.2 and using daemon_generator 1.0.5.



Mark Loeser

Anyone having the error with:

failed to allocate memory
stack level too deep
exception reentered

The problem is in your actual daemon script you wrote you have a signal handler for TERM. The variable gets changed from running to false, but the script keeps running because it is still sleeping. The simple solution is to just get rid of the signal handler and make it an infinite loop.

Hope this helps.


Same story, it's not working for me on Rails 1.2:

failed to allocate memory
stack level too deep
exception reentered

My entire customization of the generated code was adding a require statement on top, - one that I use a lot throughout the app.


Hi every1,

I was able to install the generator, generate a daemon but apparently i am not able to start it. I get
script/daemons:2:in ``': No such file or directory - script/../lib/daemons/test_ctl start (Errno::ENOENT)
from script/daemons:2
from script/daemons:2

Am I missing something. Any help is appreciated.

Thank you

Lee Fyock

The bad thing about taking out the signal handler (which does seem to prevent the errors from occurring) is that any code after the loop doesn't run. In my case, that's only logging to indicate that the daemon terminated, so I can live with that.

Also, I'm not sure that you're guaranteed that the entire block will execute as a block, if the term signal comes in during processing of that block, which could be bad for some uses.

The errors only seem to occur at daemon startup, but then everything seems OK after that. Is that not the case?

Is there a less-simple but better solution?


Lee Fyock

Further googling shows in the Daemons docs for start_proc at :
175: # This part is needed to remove the pid-file if the application is killed by
176: # daemons or manually by the user.
177: # Note that the applications is not supposed to overwrite the signal handler for
178: # 'TERM'.

So, it looks like d_g shouldn't be generating code that traps TERM.

I'm trying to assess how dangerous it is for my purposes to have my routine just punted in the middle of execution when I restart the daemon. Most of its time will be spent sleeping, and it's probably no different than restarting the web server that's busy doing stuff...

Lee Fyock

For posterity...I'm now looking at OpenWFEru's scheduler, which looks pretty nice.

The comments to this entry are closed.