I''m having no luck trying to daemonize mongrel running a camping server. When mongrel daemonizes, I get: /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:723:in `accept'': closed stream (IOError) from /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:293:in `join'' ... (This was after I disabled the unhandled exception catchall in the mongrel code -- otherwise it would just spew "!!!UNHANDLED EXCEPTION -- TELL ZED HE''S A MORON" ... or something to that effect). Here''s how I''m daemonizing the server. I scraped this together from the code in mongrel_rails as well as rv: settings = {:host => "0.0.0.0", :log_file => ''foo.log'', :cwd => $MYSERVER_HOME} config = Mongrel::Configurator.new settings do listener :port => 12345 do uri ''/foo'', :handler => Mongrel::Camping::CampingHandler.new(CASServer) setup_signals end daemonize :log_file => ''foo.log'', :cwd => $MYSERVER_HOME end config.run config.join The server works just fine if I comment out the "daemonize" call, but doesn''t work at all when daemonized. Any ideas? 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.
I didn''t get any responses to my previous post about this, so I figure maybe I''m not explaining myself clearly enough. My problem is fairly simple. I''m trying to run a Camping server as a background (daemon) process. I''m using Mongrel configurator''s "daemonize()" method to do this. However, when I daemonize the server, I got a huge spew of: !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. See below for details on what I''m doing, how I''m doing it, and what I think is the culprit (hint: IOError in mongrel.rb line 723). Thanks, Matt. Matt Zukowski wrote:> I''m having no luck trying to daemonize mongrel running a camping server. > > When mongrel daemonizes, I get: > > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:723:in > `accept'': closed stream (IOError) > from > /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:293:in > `join'' > ... > > (This was after I disabled the unhandled exception catchall in the > mongrel code -- otherwise it would just spew "!!!UNHANDLED EXCEPTION -- > TELL ZED HE''S A MORON" ... or something to that effect). > > Here''s how I''m daemonizing the server. I scraped this together from the > code in mongrel_rails as well as rv: > > settings = {:host => "0.0.0.0", :log_file => ''foo.log'', :cwd => > $MYSERVER_HOME} > > config = Mongrel::Configurator.new settings do > listener :port => 12345 do > uri ''/foo'', :handler => Mongrel::Camping::CampingHandler.new(CASServer) > setup_signals > end > daemonize :log_file => ''foo.log'', :cwd => $MYSERVER_HOME > end > > config.run > config.join > > > The server works just fine if I comment out the "daemonize" call, but > doesn''t work at all when daemonized. > > Any ideas? > > > 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
On Wed, 14 Mar 2007 11:23:41 -0400 Matt Zukowski <mzukowski at urbacon.net> wrote:> I didn''t get any responses to my previous post about this, so I figure > maybe I''m not explaining myself clearly enough. My problem is fairly > simple. I''m trying to run a Camping server as a background (daemon) > process. I''m using Mongrel configurator''s "daemonize()" method to do > this. However, when I daemonize the server, I got a huge spew of:Sorry Matt, I''ve been travelling a lot lately and missed this.> !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON.It says tell ZED not the mongrel-users mailing list. :-) Anyway, the exception is a weird one since it''s saying that you''ve opened this port and then it''s closed right away. You''ll have to give me sample code and the platform information so I can replicate it better. I''m thinking it might be something strange about this platform when a client closes right at the accept point. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/
Hey Zed, On 3/15/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote:> On Wed, 14 Mar 2007 11:23:41 -0400 > Matt Zukowski <mzukowski at urbacon.net> wrote:> Sorry Matt, I''ve been travelling a lot lately and missed this. > > > !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. > > It says tell ZED not the mongrel-users mailing list. :-) > > Anyway, the exception is a weird one since it''s saying that you''ve > opened this port and then it''s closed right away. You''ll have to give > me sample code and the platform information so I can replicate it > better. I''m thinking it might be something strange about this platform > when a client closes right at the accept point.Was there any follow-up here? Anyways, I''ve got the same problem as Matt. My OS is FreeBSD (6.2-RELEASE); the problem happens with and without accf_http loaded; below is a minimal test script to reproduce the problem and a sample of the log output. Be sure to kill the process shortly after starting it, or you''ll fill the partition where the log is written. - Dimitri --- begin script "test.rb" --- #!/usr/bin/env ruby require ''mongrel'' $mongrel_debug_client = true Mongrel::Configurator.new do listener do uri "/", :handler => Mongrel::DirHandler.new(".") end daemonize( :cwd => "/tmp", :log_file => "/tmp/test.log" ) run end.join --- end script "test.rb" --- --- begin log --- !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. ~/.gems/gems/mongrel-1.0.1/lib/mongrel.rb:723:in `accept'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel.rb:723:in `run'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'' ./test.rb:12:in `cloaker_'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:51:in `call'' ~/.gems/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:51:in `initialize'' ./test.rb:7:in `new'' ./test.rb:7 --- end log ---
Alright, solved my problem. Don''t know if it''ll help Matt, as well. The key is in the documentation comment for daemonize: # You must call this *before* frameworks that open files # as otherwise the files will be closed by this function. Looking at the examples/builder.rb script, I see that daemonize is indeed called before listener (perhaps this should be made more explicit in the docs). So, below is a working test script. The one other thing I added, was to specify the port to listen on. :) Oh, no pid file is created, no matter if I give :pid_file to the Configurator.new call or to the daemonize call as in builder.rb. - Dimitri --- begin script "test.rb" --- #!/usr/bin/env ruby require ''mongrel'' $mongrel_debug_client = true Mongrel::Configurator.new( :port => 9000 ) do daemonize( :cwd => "/tmp", :log_file => "/tmp/test.log" ) listener do uri "/", :handler => Mongrel::DirHandler.new(".") end run end.join --- end script "test.rb" ---
On Tue, 20 Mar 2007 14:17:07 +0100 "Dimitri Aivaliotis" <aglarond at gmail.com> wrote:> Hey Zed, > > On 3/15/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote: > > On Wed, 14 Mar 2007 11:23:41 -0400 > > Matt Zukowski <mzukowski at urbacon.net> wrote: > > > Sorry Matt, I''ve been travelling a lot lately and missed this. > > > > > !!!!!! UNHANDLED EXCEPTION! closed stream. TELL ZED HE''S A MORON. > > > > It says tell ZED not the mongrel-users mailing list. :-) > > > > Anyway, the exception is a weird one since it''s saying that you''ve > > opened this port and then it''s closed right away. You''ll have to give > > me sample code and the platform information so I can replicate it > > better. I''m thinking it might be something strange about this platform > > when a client closes right at the accept point. > > Was there any follow-up here? Anyways, I''ve got the same problem as > Matt. My OS is FreeBSD (6.2-RELEASE); the problem happens with and > without accf_http loaded; below is a minimal test script to reproduce > the problem and a sample of the log output. Be sure to kill the > process shortly after starting it, or you''ll fill the partition where > the log is written.No, I downloaded the latest 6.2 fbsd so I can try to debug this, but I''ve got a lot going on right now. Really it seems fbsd has decided to change the semantics of accept so that you get an errno when the client closes before the accept completes. Hey, if you could change the statement that prints out that message to also print out what exception class and then shoot me the new stack trace that''d help quite a bit. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/
On Tue, 20 Mar 2007 14:53:39 +0100 "Dimitri Aivaliotis" <aglarond at gmail.com> wrote:> Alright, solved my problem. Don''t know if it''ll help Matt, as well. > The key is in the documentation comment for daemonize: > > # You must call this *before* frameworks that open files > # as otherwise the files will be closed by this function.Aha! Classic PEBKAC eh? :-)> > Oh, no pid file is created, no matter if I give :pid_file to the > Configurator.new call or to the daemonize call as in builder.rb.Make sure you give a full path for all your files you configure. If not, let me know and I''ll check it out. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/
On 3/20/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote:> No, I downloaded the latest 6.2 fbsd so I can try to debug this, but > I''ve got a lot going on right now. Really it seems fbsd has decided to > change the semantics of accept so that you get an errno when the client > closes before the accept completes. > > Hey, if you could change the statement that prints out that message to > also print out what exception class and then shoot me the new stack > trace that''d help quite a bit.I''ve got the exception class now: IOError, but the stack trace remains the same. How else should I change the following to give you the information you need? rescue Object => exc STDERR.puts "!!!!!! UNHANDLED EXCEPTION! #{exc.class}. TELL ZED HE''S A MORON." STDERR.puts $!.backtrace.join("\n") if $mongrel_debug_client end - Dimitri
On 3/20/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote:> On Tue, 20 Mar 2007 14:53:39 +0100 > "Dimitri Aivaliotis" <aglarond at gmail.com> wrote: > > > Alright, solved my problem. Don''t know if it''ll help Matt, as well. > > The key is in the documentation comment for daemonize: > > > > # You must call this *before* frameworks that open files > > # as otherwise the files will be closed by this function. > > Aha! Classic PEBKAC eh? :-)Yep. Could you change the docs slightly to prevent other idiots like myself from falling into the same trap? Something like the following right after what''s quoted above: # (This includes +listener+ blocks - call daemonize before you set up your listeners.)> > > > Oh, no pid file is created, no matter if I give :pid_file to the > > Configurator.new call or to the daemonize call as in builder.rb. > > Make sure you give a full path for all your files you configure. If > not, let me know and I''ll check it out.I am using full paths: :pid_file => "/tmp/test.pid" What other info can I give you to help debug this? - Dimitri
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.
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
On 3/20/07, Dimitri Aivaliotis <aglarond at gmail.com> wrote:> On 3/20/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote: > > > No, I downloaded the latest 6.2 fbsd so I can try to debug this, but > > I''ve got a lot going on right now. Really it seems fbsd has decided to > > change the semantics of accept so that you get an errno when the client > > closes before the accept completes. > > > > Hey, if you could change the statement that prints out that message to > > also print out what exception class and then shoot me the new stack > > trace that''d help quite a bit. > > I''ve got the exception class now: IOError, but the stack trace remains > the same. How else should I change the following to give you the > information you need? > > rescue Object => exc > STDERR.puts "!!!!!! UNHANDLED EXCEPTION! #{exc.class}. > TELL ZED HE''S A MORON." > STDERR.puts $!.backtrace.join("\n") if $mongrel_debug_client > end > > - DimitriTry something like this: STDERR.puts exc.backtrace.join("\n") - rob
On 3/20/07, Rob Sanheim <rsanheim at gmail.com> wrote:> > Try something like this: > > STDERR.puts exc.backtrace.join("\n")Sorry if I''m being obtuse, but in this case exc == $! This doesn''t help me to get more of a stack trace. - Dimitri
Yes, but you have that if clause on the end in your code - are you sure that evaluates to true? - rob On 3/21/07, Dimitri Aivaliotis <aglarond at gmail.com> wrote:> On 3/20/07, Rob Sanheim <rsanheim at gmail.com> wrote: > > > > > Try something like this: > > > > STDERR.puts exc.backtrace.join("\n") > > Sorry if I''m being obtuse, but in this case > > exc == $! > > This doesn''t help me to get more of a stack trace. > > - Dimitri > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >
On Tue, 20 Mar 2007 16:21:44 +0100 "Dimitri Aivaliotis" <aglarond at gmail.com> wrote:> On 3/20/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote: > > On Tue, 20 Mar 2007 14:53:39 +0100 > > "Dimitri Aivaliotis" <aglarond at gmail.com> wrote:> > Make sure you give a full path for all your files you configure. If > > not, let me know and I''ll check it out. > > I am using full paths: :pid_file => "/tmp/test.pid" > > What other info can I give you to help debug this?Did you get this resolved Dimitri? I lost your reply in my queue. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/
On 3/26/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote:> On Tue, 20 Mar 2007 16:21:44 +0100 > "Dimitri Aivaliotis" <aglarond at gmail.com> wrote: > > > On 3/20/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote: > > > On Tue, 20 Mar 2007 14:53:39 +0100 > > > "Dimitri Aivaliotis" <aglarond at gmail.com> wrote: > > > > Make sure you give a full path for all your files you configure. If > > > not, let me know and I''ll check it out. > > > > I am using full paths: :pid_file => "/tmp/test.pid" > > > > What other info can I give you to help debug this? > > Did you get this resolved Dimitri? I lost your reply in my queue. >No, not yet. The pid file is still not created. I also don''t see it when running the ''builder.rb'' example. If you don''t have the time, I understand. It''s not such a big deal to me at the moment, but in the future, I would like to be able to send signals to the daemonized processes via the pid file. - Dimitri
On Wed, 28 Mar 2007 10:13:33 +0200 "Dimitri Aivaliotis" <aglarond at gmail.com> wrote:> On 3/26/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote: > > On Tue, 20 Mar 2007 16:21:44 +0100 > > "Dimitri Aivaliotis" <aglarond at gmail.com> wrote: > > > > Did you get this resolved Dimitri? I lost your reply in my queue. > > > > No, not yet. The pid file is still not created. I also don''t see it > when running the ''builder.rb'' example. > > If you don''t have the time, I understand. It''s not such a big deal to > me at the moment, but in the future, I would like to be able to send > signals to the daemonized processes via the pid file.Well, everyone else seems to be getting PID files no problem, so you have to investigate what is different about your system that could cause it. Try running it as different users, from different locations, in different directories, etc. until you find out what causes it. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/
On 3/28/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote:> Well, everyone else seems to be getting PID files no problemThis was my clue here. It seems that everyone else is using mongrel_rails - I''m not. I''m trying to setup Mongrel::Configurator to run just mongrel. The builder example threw me off because it will not generate a pid file, no matter what system I run it on. I''ve attached a patch that fixes this. Could you consider applying it? The solution is to pass :pid_file to Mongrel::Configurator.new and not daemonize, as indicated in the example. You also need to explicitly call write_pid_file because it''s not actually called anywhere within Mongrel::Configurator itself (looking at mongrel_rails helped here). Thanks, - Dimitri -------------- next part -------------- A non-text attachment was scrubbed... Name: builder.rb.diff Type: application/octet-stream Size: 700 bytes Desc: not available Url : http://rubyforge.org/pipermail/mongrel-users/attachments/20070329/4afd7993/attachment.obj
On Thu, 29 Mar 2007 23:36:53 +0200 "Dimitri Aivaliotis" <aglarond at gmail.com> wrote:> On 3/28/07, Zed A. Shaw <zedshaw at zedshaw.com> wrote: > > > Well, everyone else seems to be getting PID files no problem > > This was my clue here. It seems that everyone else is using > mongrel_rails - I''m not. I''m trying to setup Mongrel::Configurator to > run just mongrel. The builder example threw me off because it will > not generate a pid file, no matter what system I run it on. I''ve > attached a patch that fixes this. Could you consider applying it?Ohhhhhh, you didn''t say that, from what I read it seemed like you were running mongrel_rails. Yes, the builder is out of sync so thanks for he patch.> The solution is to pass :pid_file to Mongrel::Configurator.new and not > daemonize, as indicated in the example. You also need to explicitly > call write_pid_file because it''s not actually called anywhere within > Mongrel::Configurator itself (looking at mongrel_rails helped here).I''ll put this on in the next release. Thanks again. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/