[Web-SIG] Starting Web Servers using socket FDs
Roberto De Ioris
roberto at unbit.it
Tue Jun 5 13:56:03 CEST 2012
Il giorno 05/giu/2012, alle ore 12:26, Tarek Ziadé ha scritto:
> On 6/5/12 11:46 AM, Roberto De Ioris wrote:
>> Gunicorn can already bind (or better, accept) from file descriptors specifying an environment variable.
> I don't think you can start gunicorn using a file descriptor, or I failed to do it. The best I was able to do was to create a small wsgi server
> using Gunicorn as a lib.
> Gunicorn uses an environment variable when it respawns workers but it does not offer it as a public option as far as I understand how it works
benoit has already answered about that
>> uWSGI supports by-default the inheritance of file descriptor 0 for fcgi-like startup,
>> and working on generic file descriptor or inet/upstart/systemd socket activation.
> I did not find a way to start it using a provided fd -- they are plethora of options though, maybe I missed it
it is automatic if the fd is the zero one, otherwise you have to "authenticate" it adding a --socket/--http-socket/--fastcgi-socket directive
mapping to the address (this is required for avoiding uWSGI inheriting unrelated sockets, like the ones created by ssh-agents and whatever you want).
For example if you map fd 17 to 192.168.1.1:4040 you have to run uwsgi with
it will find fd 17 mapped to a socket, and it will know the socket is authorized to be used.
Other components take the special fd://<n> syntax (like the various routers) but i do not think you are intersted in them
>> The vast majority of modern systems expects the file descriptor number on an environment variable:
>> upstart: UPSTART_FDS
>> systemd: LISTEN_FDS
> Yes, this seem fairly standard.
>> Circus, could follow the same behaviour, but i do not know if a standard will be required for that.
> The goal of the standard is just to be able to place any wsgi server out there and have it working out of the box.
if this is your objective i suggest you to follow the inetd/fastcgi style approach and use file descriptor 0 as the communication socket.
Flup and uWSGI will work over this automatically. Gunicorn will work simply adding GUNICORN_FD=0
Adding another env-var will mean each server will need to add a condition for that (like upstart and systemd)
Roberto De Ioris
JID: roberto at jabber.unbit.it
More information about the Web-SIG