[launchd-dev] inetdCompatibility

Quinn "The Eskimo!" eskimo1 at apple.com
Mon Aug 23 02:41:20 PDT 2010


On 19 Aug 2010, at 11:48, Dreamcat4 wrote:

> Wheras Nginx is a more streamlined and optimized kind of webserver,
> which would be too slow for operating in that inetd kind of way. Nginx
> just wants to be launched and be kept running after the first
> incoming connection.

The correct approach to this problem is to have launchd open the listening sockets on behalf of nginx and then have nginx check in with launchd when it starts up.  As part of this checkin process, it can acquire the listening socket and, from there, start servicing connections.  The SampleD sample code shows how to do this.

<http://developer.apple.com/mac/library/samplecode/SampleD/>

It's typically quite easy to modify daemon code to work in this way.  I took a look at the nginx  source code and it seems to have one bottleneck routine for opening its listening sockets (ngx_open_listening_sockets).  You can replace that routine with the code to check in with launchd and away you go.

Except, of course, that launchd daemons must follow the rules outlined in the bulleted list at the top of <x-man-page://5/launchd.plist>.  However, usually that just means disabling code if you're running in launchd mode.

S+E
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware




More information about the launchd-dev mailing list