On my box trap(:INT){ s.shutdown } takes some time to complete.
Im wondering how one can shut it down fast and safe.
Is this an ok way to shut it down?
trap(:INT) do
fork{ s.shutdown }
exit!
end
btw: Any clues how to quickly restart webrick ?
···
--
Simon Strandgaard
Is this an ok way to shut it down?
btw: Any clues how to quickly restart webrick ?
I'm pretty interested in the answer to both of these questions :). The WEBrick servlet will be the preferred development platform from the next version of Rails (with really nice integrated breakpoint support and more!), so we're looking to make the experience as nice as possible.
(Yes, you can and should still deploy production apps on Apache)
···
--
David Heinemeier Hansson,
http://www.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://macromates.com/ -- TextMate: Code and markup editor (OS X)
http://www.loudthinking.com/ -- Broadcasting Brain
Simon Strandgaard <neoneye@adslhome.dk> writes:
On my box trap(:INT){ s.shutdown } takes some time to complete.
Im wondering how one can shut it down fast and safe.
Is this an ok way to shut it down?
trap(:INT) do
fork{ s.shutdown }
exit!
end
I'm not sure why you would need the fork.
I just do this, and it dies very quickly.
%w[ SIGHUP SIGINT SIGQUIT SIGTERM ].each {
>sig>
trap(sig) {
# I forget whether or not the reference to the server
# needs to be stored in a global in order for it to
# be seen here. I do it anyway, just in case.
$s.shutdown
}
}
btw: Any clues how to quickly restart webrick ?
I use the 'runit' system to manage a lot of my daemons, including the
one I use for webrick. Check it out here:
http://smarden.org/runit
I can completely restart my webrick daemon in about 5-10 seconds using
the 'runsvctrl' program that's part of this system.
I trap SIGHUP and SIGTERM above in addition to SIGINT because I can
easily send these signals to the daemon via 'runsvctrl'. I also throw
SIGQUIT in there because some systems switch the meaning of SIGQUIT and
SIGINT, and I always forget which ones do which.
···
--
Lloyd Zusman
ljz@asfast.com
God bless you.
David Heinemeier Hansson wrote:
Is this an ok way to shut it down?
btw: Any clues how to quickly restart webrick ?
I'm pretty interested in the answer to both of these questions :). The WEBrick servlet will be the preferred development platform from the next version of Rails (with really nice integrated breakpoint support and more!), so we're looking to make the experience as nice as possible.
(Yes, you can and should still deploy production apps on Apache)
I haven't done any exhaustive research into this topic, but this is what I've observed, along with my speculative conclusions:
1) When the last request to WEBrick results in an exception, I can shutdown WEBrick and it terminates quite snappily.
2) When the last request to WEBrick is successful (with no raised exception), WEBrick can take up to a minute to actually terminate.
I *suspect* that this has something to do with the browser keeping the connection to WEBrick alive. Perhaps WEBrick can't shut down as long as there is an active connection, and it has to wait for that connection to time out? Can anyone comment on how feasible this might be?
- Jamis
···
--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis
Hi,
In message <41A26F33.4030303@email.byu.edu>,
···
`Jamis Buck <jgb3@email.byu.edu>' wrote:
I *suspect* that this has something to do with the browser keeping the
connection to WEBrick alive. Perhaps WEBrick can't shut down as long as
there is an active connection, and it has to wait for that connection to
time out? Can anyone comment on how feasible this might be?
The attached patch adds a hook to wait till a request
arrives. But I don't know whether "io/wait" is usable on
every platform.
BTW, the keep-alive feature is disabled when the following
parameter is given.
:HTTPVersion => WEBrick::HTTPVersion.new("1.0")
--
gotoyuzo
Index: lib/webrick/httpserver.rb
RCS file: /var/cvs/src/ruby/lib/webrick/httpserver.rb,v
retrieving revision 1.8
diff -u -p -F^[^A-Za-z0-9_+-]*\(class\|module\|def\)[^A-Za-z0-9_+-] -r1.8 httpserver.rb
--- lib/webrick/httpserver.rb 21 Mar 2004 13:17:24 -0000 1.8
+++ lib/webrick/httpserver.rb 22 Nov 2004 23:47:05 -0000
@@ -15,6 +15,7 @@ require 'webrick/httprequest'
require 'webrick/httpresponse'
require 'webrick/httpservlet'
require 'webrick/accesslog'
+require 'io/wait'
module WEBrick
class HTTPServerError < ServerError; end
@@ -46,6 +47,13 @@ def run(sock)
req = HTTPRequest.new(@config)
server = self
begin
+ timeout = @config[:RequestTimeout]
+ while timeout > 0
+ break if sock.wait(0.5)
+ timeout = 0 if @status != :Running
+ timeout -= 0.5
+ end
+ raise HTTPStatus::EOFError if timeout <= 0
req.parse(sock)
res.request_method = req.request_method
res.request_uri = req.request_uri