dreamcat4 at gmail.com
Mon Aug 23 03:56:42 PDT 2010
On Mon, Aug 23, 2010 at 10:41 AM, Quinn "The Eskimo!" <eskimo1 at apple.com> wrote:
> 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.
> 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.
Thank you for that insight Quinn. That makes a lot easier to take this
suggestion to nginx forums and make a patch. Unfortunately its rather
more of a task to go around every other OSS project asking the same
sort of thing.
Interestingly, someone else (Fazekas Miklos) reworked SampleD program,
so that it just unloads itself from launchd. Which avoids the bug
raised by my original script. The unloading process can be used as a
way to tell launchd to free the socket(s) of the job so they are freed
and made available.
Commentary about how it works at -
> 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.
Nginx can be configured with 'daemon off;' and 'master_process off;'
in the nginx.conf. Those options make the nginx process(es) behave
much more friendly to launchd. But they arent enabled in the default
> Quinn "The Eskimo!" <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> launchd-dev mailing list
> launchd-dev at lists.macosforge.org
More information about the launchd-dev