[Mongrel] Daemonizing a camping server

Matt Zukowski mzukowski at urbacon.net
Tue Mar 20 11:44:16 EDT 2007


Sorry, I jumped back into the conversation without seeing the
follow-ups, so my last post was a bit redundant.

But just to reiterate what Dimitri said earlier: putting the daemonize
call before the listener is probably not enough. You also have to make
sure that you do not open any IOs (files, etc.) until after the
daemonize call. For example, I had a log file open before daemonize and
ended up with 'IOError closed stream'

I do think though that there's probably some way to fix this on the
mongrel side. WEBRick seems to be able to daemonize itself without any
IO voodoo.

Matt Zukowski wrote:
> Putting the daemonize before the listener call fixes the problem for me
> as well.
> 
> Below is a skeleton camping app script that should reproduce the
> original problem. Just run it using the ruby interpreter.
> 
> This is on a Linux 2.6.x box (openSuSE 10.2) so it's definitely not just
> a BSD issue.
> 
> --------------------
> 
> require 'rubygems'
> require 'camping'
> require 'mongrel/camping'
> 
> Camping.goes :MyDaemon
> 
> module MyDaemon
>         module Controllers
>                 class Foo < R '/'
>                         def get
>                                 render :foo
>                         end
>                 end
>         end
> 
>         module Views
>                 def foo
>                         xhtml_strict { head { title "Test" }; body {
> "Blah" } }
>                 end
>         end
> end
> 
> if __FILE__ == $0
> 
>   config = Mongrel::Configurator.new :host => "0.0.0.0" do
>                 # putting daemonize here works
>                 #daemonize :log_file => '/tmp/mydaemon.log', :cwd =>
> File.dirname(File.expand_path(__FILE__))
>           listener :port => 9999 do
>                   uri '/', :handler =>
> Mongrel::Camping::CampingHandler.new(MyDaemon)
>                   setup_signals
>                 end
> 
>                 # putting it here doesn't :(
>                 daemonize :log_file => '/tmp/mydaemon.log', :cwd =>
> File.dirname(File.expand_path(__FILE__))
>         end
> 
>         config.run.join
> 
> end
> 
> 
> This e-mail message is privileged, confidential and subject to copyright. Any unauthorized use or disclosure is prohibited. 
> Le contenu du pr'esent courriel est privil'egi'e, confidentiel et soumis `a des droits d'auteur. Il est interdit de l'utiliser ou de le divulguer sans autorisation.
> 
> 
> _______________________________________________
> Mongrel-users mailing list
> Mongrel-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-users



More information about the Mongrel-users mailing list