Question

I have to patch some code, but can't figure out exactly how. So basically, I have a rack server which binds to a hostname and port. I woud like it to bind to a unix socket. Problem is, I can't figure out the exact option i have to give.

Rack::Server.new(:app => @app, :port => 3000).start 

does what is expected. I thought it would be something like this:

Rack::Server.new(:app => @app, :socket => "path/to/file").start

but this binds to the default port nevertheless. How can I do this?

Était-ce utile?

La solution 2

Apparently this is not possible. Rack-compatible servers usually support this feature, but Rack::Server "interface" does not make use of it (at least the latest version as of October 2013). Why not, is beyond me.

Autres conseils

I have found that if you pass a filename to the :Host option it binds to the unix socket and not a tcp socket.

The file name needs to look like this though:

/var/www/myapp/my_app.socket or ./my_app.socket

This will not work if it looks like a domain name like this:

my_app.socket

For example here is a rackup command that works in Rack 1.2:

rackup -s thin -E production -o ./my_app.socket faye.ru

Or this is how you do it from ruby:

require 'rack'
require 'thin'
Rack::Handler.get('thin').run(app, :Host => './my_app.socket')

# or this works also

require 'rack'
require 'thin'
Rack::Server.new(:app => app, :Host => './my_app.socket').start

NOTE: The uppercase H in :Host this is required.

I hope that helps!

Did you try :Socket or :File? Note that with Rack the options for the actual web server (webrick, thin, etc.) usually start with an uppercase character.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top