Re: Socket (demand) based launchd daemons
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com You can use wait == true then. http://trac.macosforge.org/projects/launchd/browser/trunk/launchd/doc/sample... http://trac.macosforge.org/projects/launchd/browser/trunk/launchd/doc/sample... davez On Jan 23, 2008, at 10:26 AM, Perry Smith wrote: Thanks. On Jan 23, 2008, at 10:57 AM, Dave Zarzycki wrote: <key>Sockets</key> <dict> <key>Listeners</key> <dict> <key>SockServiceName</key> <integer>12345</integer> </dict> </dict> <key>inetdCompatibility</key> <dict> <key>Wait</key> <false/> </dict> davez On Jan 23, 2008, at 8:17 AM, Perry Smith wrote: Thank you, Perry Smith _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/zarzycki%40apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... However, if you really want to go down this route, please review the 'sampled' project: I saw that but was afraid it would respawn the server with each http request. The socket will be used only briefly but the server is going to keep running. Really... this piece of code isn't set up to be launched in this manner. Maybe I should just keep what I have and launch it at boot time and be happy. But, if I continue on: I'm looking at launch.h and reading. I was toying with an idea of writing a program, call it "get_sockets". The script would run get_sockets and get_sockets would print on stdout something that could be easily parsed. Like the key for each socket and then the fd number for that key. I'm making great leaps of assumptions here on what the launch_data is going to look like so I may be way off base. Given that you're using a scripting language, your best option is to leverage launchd's inetd compatibility. By doing so, you'll get automatic concurrency (at the cost of inefficiency) and implicit compatibility with other operating systems that supply [x]inetd. Assuming that your program is TCP based, then this should be sufficient: Once you make that change, you'll find the socket on stdin/stdout/ stderr at launch. This question has come up for me before and I suspect it will again. The example this time is the web "server" that serves the Ruby "rdoc" documentation. You start it with "gem server". It has a few options like which port which has a default. I have a launchd plist file that simply starts this up at boot. But, mostly so I can show off to my friends (if I had any :-), I'd like to start it up the first time I browse to that port. The man page for launchd.plist says that the process has to "check in" using the launch(3) API. "man 3 launch" gives me back nothing. So I am lost as to what API's there are. But, even if I could find them, thats really just half the problem. The real problem is I'm looking for a way to transfer the file descriptor from launchd to the gem server using a script. (I can't modify gem just to do this -- well, I suppose I could but that only defers the problem until next time this comes up). So, how is this done? Or... if I need to write some code, thats fine. But, where do I start? This email sent to zarzycki@apple.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Dave Zarzycki