"Lin Jen-Shin (aka godfat 真常)" <[email protected]> wrote:
> Hi,
>
> A couple days ago, I was trying to run Unicorn for Ramaze,
> and found that `Unicorn.run' didn't share the same interface
> with other Rack handlers, i.e. `options[:Host]' and `options[:Port]'
>
> Because of this, I can't just use:
>
> Rack::Handler.register('unicorn', 'Unicorn')
>
> And invoke this:
>
> Ramaze.start(:adapter => 'unicorn', :port => 8080)
>
> To address this, I added a simple wrapper in
> Innate (which is the core of Ramaze):
>
> http://github.com/godfat/innate/commit/9d607f41fdeeca366a9a07155e685ae2605c7025
>
> In short, simply hack the config to:
>
> {:listeners => ["#{config[:Host]}:#{config[:Port]}"]}
>
> Should we adapt to this interface in Unicorn::Configurator,
> or provide an additional Rack handle to adapt to this,
> or maintain this Rack handler in Rack repository, just like the others?
> http://github.com/rack/rack/tree/master/lib/rack/handler
I think making Unicorn.run add to :listeners if :Host or :Port are set
will work. I'm not sure if launching Unicorn directly from `rackup' can
ever work right without being too intrusive to the other servers, so
having a Unicorn Rack handler in distributed with Rack would't make
sense. Unicorn needs to capture ARGV (before option parsing) and parse
its own config file, neither of which is doable out-of-the-box with
rackup.
Does something like this work? (not tested).
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 0f2b597..d4a00e0 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -17,6 +17,14 @@ module Unicorn
class << self
def run(app, options = {})
+ # compatibility with other interfaces (Ramaze)
+ host = options.delete(:Host)
+ port = options.delete(:Port)
+ if host || port
+ port ||= Const::DEFAULT_PORT
+ host ||= Const::DEFAULT_HOST
+ (options[:listeners] ||= []) << "#{host}:#{port}"
+ end
HttpServer.new(app, options).start.join
end
end
On the other hand, does Innate make it possible to do transparent
upgrades (since rackup does not)? I'll look into it a bit more later...
--
Eric Wong
_______________________________________________
mongrel-unicorn mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/mongrel-unicorn