From morgant at makkintosshu.com Fri Aug 1 15:09:03 2008 From: morgant at makkintosshu.com (Morgan Aldridge) Date: Fri, 1 Aug 2008 18:09:03 -0400 Subject: [launchd-dev] Attempting to develop a launch plist for sysmon Message-ID: A few years ago I wrote a Mac OS X StartupItem for sysmon and I've been attempting to write a launchd plist for it now that I've migrated my monitoring server to Leopard Server (currently 10.5.3). Here's my /Library/LaunchDaemons/com.makkintosshu.sysmon.plist (owned by root:wheel with permissions of 750): Label com.makkintosshu.sysmon ProgramArguments /usr/local/bin/sysmond -d OnDemand KeepAlive RunAtLoad I use both the OnDemand and KeepAlive keys in the hopes of supporting both Tiger & Leopard with this file. Will I run into any issues there (I've currently only tested with Leopard Server)? Also, it seems to work correctly (sysmond loads, loads it's config file, and binds to its TCP port fine; plus if you kill the process launchd starts it up again) if I run `sudo launchctl load -w /Library/LaunchDaemons/com.makkintosshu.sysmon.plist` after boot, but if I leave it loaded (or, at least, if I don't disable it using `sudo launchctl unload -w /Library/LaunchDaemons/com.makkintosshu.sysmon.plist`) at boot, sysmond acts as if it didn't have any config files to load and it usually takes an unload & load of the launchd plist to get it to function normally. Any ideas as to what might cause this? Will I have to start investigating sysmond's source to see if it's a dependency checking issue? Shouldn't the file system be available upon loading the job and only network services might be unavailable? Thanks in advance, Morgan Aldridge --- morgant at makkintosshu.com http://www.makkintosshu.com/ From nlwan at nps.edu Mon Aug 4 12:51:09 2008 From: nlwan at nps.edu (Nathan Wan) Date: Mon, 4 Aug 2008 12:51:09 -0700 Subject: [launchd-dev] Attempting to develop a launch plist for sysmon In-Reply-To: References: Message-ID: <55EC561750ED4F93A7A91D5C613B7D30@reeves> I also have a question about this. I have been looking at the man page for launchd.plist on 10.4, and it does not list a KeepAlive key. Does that mean that it won't work? It doesn't seem to be working. Is there another way to keep a daemon running another way? Thanks Nathan -----Original Message----- From: launchd-dev-bounces at lists.macosforge.org [mailto:launchd-dev-bounces at lists.macosforge.org] On Behalf Of Morgan Aldridge Sent: Friday, August 01, 2008 3:09 PM To: launchd-dev at lists.macosforge.org Subject: [launchd-dev] Attempting to develop a launch plist for sysmon A few years ago I wrote a Mac OS X StartupItem for sysmon and I've been attempting to write a launchd plist for it now that I've migrated my monitoring server to Leopard Server (currently 10.5.3). Here's my /Library/LaunchDaemons/com.makkintosshu.sysmon.plist (owned by root:wheel with permissions of 750): Label com.makkintosshu.sysmon ProgramArguments /usr/local/bin/sysmond -d OnDemand KeepAlive RunAtLoad I use both the OnDemand and KeepAlive keys in the hopes of supporting both Tiger & Leopard with this file. Will I run into any issues there (I've currently only tested with Leopard Server)? Also, it seems to work correctly (sysmond loads, loads it's config file, and binds to its TCP port fine; plus if you kill the process launchd starts it up again) if I run `sudo launchctl load -w /Library/LaunchDaemons/com.makkintosshu.sysmon.plist` after boot, but if I leave it loaded (or, at least, if I don't disable it using `sudo launchctl unload -w /Library/LaunchDaemons/com.makkintosshu.sysmon.plist`) at boot, sysmond acts as if it didn't have any config files to load and it usually takes an unload & load of the launchd plist to get it to function normally. Any ideas as to what might cause this? Will I have to start investigating sysmond's source to see if it's a dependency checking issue? Shouldn't the file system be available upon loading the job and only network services might be unavailable? Thanks in advance, Morgan Aldridge --- morgant at makkintosshu.com http://www.makkintosshu.com/ _______________________________________________ launchd-dev mailing list launchd-dev at lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev From eskimo1 at apple.com Tue Aug 5 01:46:55 2008 From: eskimo1 at apple.com (Quinn) Date: Tue, 5 Aug 2008 09:46:55 +0100 Subject: [launchd-dev] Attempting to develop a launch plist for sysmon In-Reply-To: References: Message-ID: At 18:09 -0400 1/8/08, Morgan Aldridge wrote: >I use both the OnDemand and KeepAlive keys in the hopes of supporting >both Tiger & Leopard with this file. Will I run into any issues there >(I've currently only tested with Leopard Server)? As long as you still need to support 10.4.x you'd be better off just using "OnDemand". It's supported, albeit deprecated, on 10.5. At 12:51 -0700 4/8/08, Nathan Wan wrote: >I also have a question about this. I have been looking at the man page for >launchd.plist on 10.4, and it does not list a KeepAlive key. Does that mean >that it won't work? It doesn't seem to be working. Is there another way to >keep a daemon running another way? "KeepAlive" will not work on 10.4.x. "OnDemand" is your only choice. It's not as flexible, but it will do the job. At 18:09 -0400 1/8/08, Morgan Aldridge wrote: >Any ideas as to what might cause this? Will I have to start >investigating sysmond's source to see if it's a dependency checking >issue? Shouldn't the file system be available upon loading the job and >only network services might be unavailable? My guess is that this is related to networking. Startup items, since 10.4, have automatically been given a dependency on networking for compatibility reasons. If you convert to launchd, you lose that dependency and it's likely you come up /way/ before the networking stack. Lots of traditional UNIX code doesn't handle that well. Just for the sake of debugging this, have you tried adding "NetworkState" to your property list (in the "KeepAlive" dictionary, as documented by ). This will prevent you from coming up until the network is up. It's not the long-term solution to this problem, but it would allow you determine whether the problem is networking or something else. S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware From palshuth at gmail.com Tue Aug 5 11:17:44 2008 From: palshuth at gmail.com (Peter Alshuth) Date: Tue, 5 Aug 2008 14:17:44 -0400 Subject: [launchd-dev] GUI Agent issue under Tiger Message-ID: <8de47e2a0808051117o4d49286alc9260d4b49a94f0d@mail.gmail.com> Hi all, I have a setup with (user) agents that are communicating with one daemon. Everything works well under 10.5 but if I run it under Tiger I got all the problems: I have a warning/password box in my agent (running as a background program with a "limited UI" for each user). I can click at a button but I cannot type anything in the password field under Tiger (works fine in Leopard). I read something about a login/logout hook for 10.3 or 10.4 but I thought this is not needed if I support only 10.4 and up. Apparently, my agents are not running under a GUI per-session bootstrap in 10.4 any more. How can I resolve this problem? I really don't want to use a different solution for 10.4 and creating another background task that will launch my UI agent (and the question here is how to deal with the bootstrap context). Is there any special flag in the plist file (like the aqua session keyword for 10.5) that I have to use for 10.4 only? The TN2083 points our that the global window server can be reached if the agent UID matches the console user, but if I stop and start the agent (with launchctl un/load myplistfile) all other launches will not allow the app from connecting to the window server any more. Again, all the problems I have are under Tiger 10.4.11 and not Leopard. Thanks for any help, Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-dev/attachments/20080805/a6724390/attachment.html From zarzycki at apple.com Tue Aug 5 18:22:08 2008 From: zarzycki at apple.com (Dave Zarzycki) Date: Tue, 5 Aug 2008 18:22:08 -0700 Subject: [launchd-dev] GUI Agent issue under Tiger In-Reply-To: <8de47e2a0808051117o4d49286alc9260d4b49a94f0d@mail.gmail.com> References: <8de47e2a0808051117o4d49286alc9260d4b49a94f0d@mail.gmail.com> Message-ID: Peter, GUI agent support was/is dead-on-arrival in Tiger (and fixed in Leopard, as you have observed). Sorry, davez On Aug 5, 2008, at 11:17 AM, Peter Alshuth wrote: > Hi all, > > I have a setup with (user) agents that are communicating with one > daemon. Everything works well under 10.5 but if I run it under Tiger > I got all the problems: > > I have a warning/password box in my agent (running as a background > program with a "limited UI" for each user). I can click at a button > but I cannot type anything in the password field under Tiger (works > fine in Leopard). I read something about a login/logout hook for > 10.3 or 10.4 but I thought this is not needed if I support only 10.4 > and up. Apparently, my agents are not running under a GUI per- > session bootstrap in 10.4 any more. How can I resolve this problem? > I really don't want to use a different solution for 10.4 and > creating another background task that will launch my UI agent (and > the question here is how to deal with the bootstrap context). Is > there any special flag in the plist file (like the aqua session > keyword for 10.5) that I have to use for 10.4 only? The TN2083 > points our that the global window server can be reached if the agent > UID matches the console user, but if I stop and start the agent > (with launchctl un/load myplistfile) all other launches will not > allow the app from connecting to the window server any more. > > Again, all the problems I have are under Tiger 10.4.11 and not > Leopard. > > Thanks for any help, > Peter > _______________________________________________ > launchd-dev mailing list > launchd-dev at lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev From eskimo1 at apple.com Wed Aug 6 02:31:42 2008 From: eskimo1 at apple.com (Quinn) Date: Wed, 6 Aug 2008 10:31:42 +0100 Subject: [launchd-dev] GUI Agent issue under Tiger In-Reply-To: References: <8de47e2a0808051117o4d49286alc9260d4b49a94f0d@mail.gmail.com> Message-ID: At 18:22 -0700 5/8/08, Dave Zarzycki wrote: >GUI agent support was/is dead-on-arrival in Tiger (and fixed in >Leopard, as you have observed). TN2083 documents this problem and your options. S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware From morgant at makkintosshu.com Thu Aug 7 09:55:06 2008 From: morgant at makkintosshu.com (Morgan Aldridge) Date: Thu, 7 Aug 2008 12:55:06 -0400 Subject: [launchd-dev] Attempting to develop a launch plist for Message-ID: On Tue, 5 Aug 2008 09:46:55 +0100, Quinn wrote: > > As long as you still need to support 10.4.x you'd be better off just > using "OnDemand". It's supported, albeit deprecated, on 10.5. Well, the StartupItem still works under Tiger, so I'll just drop support for that in the launchd plist. The "KeepAlive" functionality is much more worthwhile to me than getting rid of the StartupItem under Tiger. Incidentally--and a bit off-topic--is there an easy way to get the Mac OS X/Darwin version number from a bash script so I can install either the StartupItem of launchd plist? I think I saw one once, but the only thing that immediately comes to mind is to parse the output of `hostinfo` and I don't like that idea. I can ask on darwin-dev if that's more appropriate. > My guess is that this is related to networking. Startup items, since > 10.4, have automatically been given a dependency on networking for > compatibility reasons. If you convert to launchd, you lose that > dependency and it's likely you come up /way/ before the networking > stack. Lots of traditional UNIX code doesn't handle that well. I'll try to look at the sysmond source and see what checks the original author was doing in terms of the networking side of things. You're probably right that it's likely very little and/or doesn't handle it gracefully. > Just for the sake of debugging this, have you tried adding > "NetworkState" to your property list (in the "KeepAlive" dictionary, > as documented by ). This will prevent > you from coming up until the network is up. It's not the long-term > solution to this problem, but it would allow you determine whether > the problem is networking or something else. I had looked at that key, but hadn't tried it yet. I'll give it a shot and see what results I get. I'm assuming--please correct me if I'm wrong--that that will kill the sysmond process if the network goes down? If so, it's definitely not a long term solution as sysmon is a network monitoring utility. ;) Morgan Aldridge --- morgant at makkintosshu.com http://www.makkintosshu.com/ From bradleyjames at gmail.com Sun Aug 10 20:55:07 2008 From: bradleyjames at gmail.com (Brad Reynolds) Date: Sun, 10 Aug 2008 20:55:07 -0700 Subject: [launchd-dev] Accessing keychain in a launchd process Message-ID: <916769c80808102055p643b0ea6g468f1d8e6b677f99@mail.gmail.com> I have a ruby script that shells out a call similar to the following: `security find-generic-password -ga test /Users/brad/Library/Keychains/login.keychain` When run from the command line I was prompted to give access to the keychain item for the 'security' command (this security of this concerns me but is out of scope for the question). After granting access via Keychain Access I can run the script and it no longer prompts for the retrieval of the password. When invoked from launchctl I see the following in Console: "security: SecKeychainFindGenericPassword: User interaction is not allowed." I tried adding launchd and launchctl to the list of programs that have access to this password but I get the same error. Any ideas on what the program might be when run from launchctl? -bradr From eskimo1 at apple.com Mon Aug 11 03:28:55 2008 From: eskimo1 at apple.com (Quinn) Date: Mon, 11 Aug 2008 11:28:55 +0100 Subject: [launchd-dev] Accessing keychain in a launchd process In-Reply-To: <916769c80808102055p643b0ea6g468f1d8e6b677f99@mail.gmail.com> References: <916769c80808102055p643b0ea6g468f1d8e6b677f99@mail.gmail.com> Message-ID: At 20:55 -0700 10/8/08, Brad Reynolds wrote: >Any ideas on what the program might be when run from launchctl? What context is your "launchd process" running in? Is it a daemon or an agent? If it's an agent, what type of agent (see Table 1 in TN2083 for the list of options)? I would only expect this to work from a GUI launchd agent. Daemons and other agents run outside of the GUI login context, and thus can't safely display UI. S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware From bradleyjames at gmail.com Mon Aug 11 20:26:41 2008 From: bradleyjames at gmail.com (Brad Reynolds) Date: Mon, 11 Aug 2008 20:26:41 -0700 Subject: [launchd-dev] Accessing keychain in a launchd process In-Reply-To: References: <916769c80808102055p643b0ea6g468f1d8e6b677f99@mail.gmail.com> Message-ID: <916769c80808112026j2231192fra40b336ad478c828@mail.gmail.com> Thanks for the reply Quinn. I haven't seen that tech note. I've got some reading to do. But to clarify, I don't necessarily want it to run in a GUI context. I'm just wanting to authorize this script, when run via launchd, to access the keychain. A symptom of the my current problem is that it can't display the GUI. This occurs because the script doesn't have access to the keychain. I'd like to give it access beforehand so that it is authorized and the GUI is avoided altogether. When I run the script from the command line it doesn't prompt for the password since I've given it access. But when run from launchd it tries to prompt, thus the problem. I'll give the document a read and if I can't figure it out I'll reply again. Thanks. -bradr On Mon, Aug 11, 2008 at 3:28 AM, Quinn wrote: > At 20:55 -0700 10/8/08, Brad Reynolds wrote: >>Any ideas on what the program might be when run from launchctl? > > What context is your "launchd process" running in? Is it a daemon or > an agent? If it's an agent, what type of agent (see Table 1 in > TN2083 for the list of options)? > > > > I would only expect this to work from a GUI launchd agent. Daemons > and other agents run outside of the GUI login context, and thus can't > safely display UI. > > S+E > -- > Quinn "The Eskimo!" > Apple Developer Relations, Developer Technical Support, Core OS/Hardware > _______________________________________________ > launchd-dev mailing list > launchd-dev at lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev > From benjaminburke at me.com Tue Aug 12 23:36:34 2008 From: benjaminburke at me.com (Benjamin Burke) Date: Wed, 13 Aug 2008 02:36:34 -0400 Subject: [launchd-dev] WatchPaths Indicator of triggering path? References: <8CA70744-0895-430D-BAC3-4020D54D446C@me.com> Message-ID: <5AE18BE8-9DF1-41FF-95A3-978CB02065F7@me.com> Hi, When an agent is run as the result of a watched path being modified, does launchd provide the agent with the path that triggered it? For example, imagine that I have the following plist which identifies 3 watchpaths: Label com.example.test ProgramArguments /Users/tester/patchWatcher.pl WatchPaths /some/path /return/of/the/path /revenge/of/path Is there some way that launchd tells my program which of the 3 watch paths triggered the event? Is there some hidden "%s" program argument or something like that. I checked the environment variables and didn't see anything. I checked the man pages and couldn't find anything. Second, hopefully easier question: Do the terms "launch services" and "launchd" refer to the same thing? Thanks, Ben Burke From kvv at apple.com Wed Aug 13 00:37:53 2008 From: kvv at apple.com (Kevin Van Vechten) Date: Wed, 13 Aug 2008 00:37:53 -0700 Subject: [launchd-dev] WatchPaths Indicator of triggering path? In-Reply-To: <5AE18BE8-9DF1-41FF-95A3-978CB02065F7@me.com> References: <8CA70744-0895-430D-BAC3-4020D54D446C@me.com> <5AE18BE8-9DF1-41FF-95A3-978CB02065F7@me.com> Message-ID: <387F207A-AF45-43B4-AE10-8F60EDCEA36E@apple.com> On Aug 12, 2008, at 11:36 PM, Benjamin Burke wrote: > When an agent is run as the result of a watched path being modified, > does launchd provide the agent with the path that triggered it? For > example, imagine that I have the following plist which identifies 3 > watchpaths: [...] > WatchPaths > > /some/path > /return/of/the/path > /revenge/of/path > No, I don't think the path that triggered the launch is communicated to the process. Seems like a reasonable enhancement request, but the files may be modified after the process is launched and it's the agent's responsibility to watch for that. > Second, hopefully easier question: Do the terms "launch services" and > "launchd" refer to the same thing? LaunchServices refers to the high level framework for opening applications and documents with applications. On Leopard, LaunchServices uses launchd to create new processes. - Kevin From bradleyjames at gmail.com Sun Aug 17 09:46:36 2008 From: bradleyjames at gmail.com (Brad Reynolds) Date: Sun, 17 Aug 2008 09:46:36 -0700 Subject: [launchd-dev] Accessing keychain in a launchd process In-Reply-To: <916769c80808112026j2231192fra40b336ad478c828@mail.gmail.com> References: <916769c80808102055p643b0ea6g468f1d8e6b677f99@mail.gmail.com> <916769c80808112026j2231192fra40b336ad478c828@mail.gmail.com> Message-ID: <916769c80808170946i750a3f04s80e67c11ba1c4177@mail.gmail.com> The problem was that I wasn't specifying the correct sessionType when loading the agent via launchctl (i.e. launchctl load -S Aqua myagent.plist). Once I did that I had the appropriate context to access the keychain in. Thanks for the help! -bradr On Mon, Aug 11, 2008 at 8:26 PM, Brad Reynolds wrote: > Thanks for the reply Quinn. I haven't seen that tech note. I've got > some reading to do. > > But to clarify, I don't necessarily want it to run in a GUI context. > I'm just wanting to authorize this script, when run via launchd, to > access the keychain. A symptom of the my current problem is that it > can't display the GUI. This occurs because the script doesn't have > access to the keychain. I'd like to give it access beforehand so that > it is authorized and the GUI is avoided altogether. When I run the > script from the command line it doesn't prompt for the password since > I've given it access. But when run from launchd it tries to prompt, > thus the problem. > > I'll give the document a read and if I can't figure it out I'll reply > again. Thanks. > > -bradr > > On Mon, Aug 11, 2008 at 3:28 AM, Quinn wrote: >> At 20:55 -0700 10/8/08, Brad Reynolds wrote: >>>Any ideas on what the program might be when run from launchctl? >> >> What context is your "launchd process" running in? Is it a daemon or >> an agent? If it's an agent, what type of agent (see Table 1 in >> TN2083 for the list of options)? >> >> >> >> I would only expect this to work from a GUI launchd agent. Daemons >> and other agents run outside of the GUI login context, and thus can't >> safely display UI. >> >> S+E >> -- >> Quinn "The Eskimo!" >> Apple Developer Relations, Developer Technical Support, Core OS/Hardware >> _______________________________________________ >> launchd-dev mailing list >> launchd-dev at lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev >> > From benjaminburke at me.com Mon Aug 18 11:56:46 2008 From: benjaminburke at me.com (Benjamin Burke) Date: Mon, 18 Aug 2008 14:56:46 -0400 Subject: [launchd-dev] WatchPaths Indicator of triggering path? In-Reply-To: <387F207A-AF45-43B4-AE10-8F60EDCEA36E@apple.com> References: <8CA70744-0895-430D-BAC3-4020D54D446C@me.com> <5AE18BE8-9DF1-41FF-95A3-978CB02065F7@me.com> <387F207A-AF45-43B4-AE10-8F60EDCEA36E@apple.com> Message-ID: On Aug 13, 2008, at 3:37 AM, Kevin Van Vechten wrote: > On Aug 12, 2008, at 11:36 PM, Benjamin Burke wrote: >> When an agent is run as the result of a watched path being modified, >> does launchd provide the agent with the path that triggered it? For >> example, imagine that I have the following plist which identifies 3 >> watchpaths [...] > > No, I don't think the path that triggered the launch is communicated > to the process. Seems like a reasonable enhancement request, but > the files may be modified after the process is launched and it's the > agent's responsibility to watch for that. Thanks. I finally got around to submitting this as an enhancement request (radar #6156218). I tried to come up with a patch myself, but I keep crashing in job_start_child... I'm afraid that I'm a bit out of my depth at the moment. From tim at sbdev.net Tue Aug 19 02:01:48 2008 From: tim at sbdev.net (Tim Schooley) Date: Tue, 19 Aug 2008 10:01:48 +0100 Subject: [launchd-dev] LaunchAgent Logging path. Message-ID: <20080819100148.828e11ec.tim@sbdev.net> Hi all! I can't seem to get my LaunchAgent to log to a user-specific location. For example, the following doesn't work (no log file is created): StandardOutPath ~/mylog.log Is there any way for each instance of the LaunchAgent to have its own log file? Thanks for any help! Kind regards, Tim From zarzycki at apple.com Tue Aug 19 08:27:29 2008 From: zarzycki at apple.com (Dave Zarzycki) Date: Tue, 19 Aug 2008 08:27:29 -0700 Subject: [launchd-dev] LaunchAgent Logging path. In-Reply-To: <20080819100148.828e11ec.tim@sbdev.net> References: <20080819100148.828e11ec.tim@sbdev.net> Message-ID: <07D689C8-6771-4476-A826-8B060598C823@apple.com> Tim, Globbing ("man 3 glob") is not yet supported for StandardOutPath or StandardErrorPath. Please strongly consider using the syslog(3) or asl_log(3) family of API. davez On Aug 19, 2008, at 2:01 AM, Tim Schooley wrote: > Hi all! > > I can't seem to get my LaunchAgent to log to a user-specific location. > > For example, the following doesn't work (no log file is created): > > StandardOutPath > ~/mylog.log > > Is there any way for each instance of the LaunchAgent to have its > own log > file? > > Thanks for any help! > > Kind regards, > > Tim > > _______________________________________________ > launchd-dev mailing list > launchd-dev at lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev From trodemaster at gmail.com Tue Aug 19 12:02:50 2008 From: trodemaster at gmail.com (Blake Garner) Date: Tue, 19 Aug 2008 12:02:50 -0700 Subject: [launchd-dev] make sure process starts before login window Message-ID: <55a5c7c50808191202j5d8e6aa8s7e40b674137290c9@mail.gmail.com> I'm looking for suggestions or examples on how to make sure a script runs before login window starts. Any ideas on how to make that happen within launchd? Thanks, Blake From eskimo1 at apple.com Tue Aug 19 14:49:29 2008 From: eskimo1 at apple.com (Quinn) Date: Tue, 19 Aug 2008 22:49:29 +0100 Subject: [launchd-dev] make sure process starts before login window In-Reply-To: <55a5c7c50808191202j5d8e6aa8s7e40b674137290c9@mail.gmail.com> References: <55a5c7c50808191202j5d8e6aa8s7e40b674137290c9@mail.gmail.com> Message-ID: At 12:02 -0700 19/8/08, Blake Garner wrote: >I'm looking for suggestions or examples on how to make sure a script >runs before login window starts. Any ideas on how to make that happen >within launchd? It depends on what you mean by "before login window starts". Most folks who ask this question want to run before the user logs in [1], either before or after their home directory is mounted, and want to hold up login while they do their stuff. If that's the case then the best approach is to use an Authorization Plug-in. If you'd like to explore this option, drop me a line. I have a draft technote that I can send your way. OTOH if you really want to run before loginwindow is /started/ then things get a /lot/ harder. The problem is that in the launchd world we boot the system via demand pull. That is, we launch loginwindow and then, as loginwindow requests services, we start those services. So the only way to run before loginwindow is to actually patch the system to not launch loginwindow in the first place. You could do this by munging but... yeah, that gets very ugly very fast. It might be appropriate for a managed site but it's certainly not something you'd want to do in shrinkwrap software. S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware [1] Including automatic logins. From tim at sbdev.net Wed Aug 20 01:20:33 2008 From: tim at sbdev.net (Tim Schooley) Date: Wed, 20 Aug 2008 09:20:33 +0100 Subject: [launchd-dev] LaunchAgent causing bug message in logs? Message-ID: <20080820092033.b2c103f6.tim@sbdev.net> Hi all, My LaunchAgent appears to cause the following message to be displayed in the log file when it is loaded via launchctl (also note that the agent is for Aqua sessions only): com.apple.launchd[553] (com.company.agent): Bug: launchd_core_logic.c:5025 (23585):22: false Normally, I would pull the source from the site, and grep for stuff to hunt down the cause of this. But I can't find a way of pulling the SVN source :( I did have a look through the source browser, but without knowing which version of the code I'm using, I'm a little bit stuck. Should this message worry me/you? Kind regards, Tim From zarzycki at apple.com Wed Aug 20 07:48:58 2008 From: zarzycki at apple.com (Dave Zarzycki) Date: Wed, 20 Aug 2008 07:48:58 -0700 Subject: [launchd-dev] LaunchAgent causing bug message in logs? In-Reply-To: <20080820092033.b2c103f6.tim@sbdev.net> References: <20080820092033.b2c103f6.tim@sbdev.net> Message-ID: <4A8AA886-FA29-4298-8CBF-53A0A543CAF3@apple.com> Tim, Are you sure that you copied/pasted the log line exactly? Version 23585 of launchd doesn't have anything on line 5025 of launchd_core_logic.c that would generate this message. In any case, if you could provide a copy of your property-list file, we could probably diagnose this faster. davez On Aug 20, 2008, at 1:20 AM, Tim Schooley wrote: > Hi all, > > My LaunchAgent appears to cause the following message to be > displayed in the > log file when it is loaded via launchctl (also note that the agent > is for > Aqua sessions only): > > com.apple.launchd[553] (com.company.agent): Bug: > launchd_core_logic.c:5025 > (23585):22: false > > Normally, I would pull the source from the site, and grep for stuff > to hunt > down the cause of this. But I can't find a way of pulling the SVN > source :( > > I did have a look through the source browser, but without knowing > which > version of the code I'm using, I'm a little bit stuck. > > Should this message worry me/you? > > Kind regards, > > Tim > > _______________________________________________ > launchd-dev mailing list > launchd-dev at lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev From tim at sbdev.net Wed Aug 20 07:56:54 2008 From: tim at sbdev.net (Tim Schooley) Date: Wed, 20 Aug 2008 15:56:54 +0100 Subject: [launchd-dev] LaunchAgent causing bug message in logs? In-Reply-To: <4A8AA886-FA29-4298-8CBF-53A0A543CAF3@apple.com> References: <20080820092033.b2c103f6.tim@sbdev.net> <4A8AA886-FA29-4298-8CBF-53A0A543CAF3@apple.com> Message-ID: <20080820155654.7f435b39.tim@sbdev.net> Hi Dave, On Wed, 20 Aug 2008 07:48:58 -0700, Dave Zarzycki wrote: > Tim, > > Are you sure that you copied/pasted the log line exactly? All minus the com.mycompany.agent bit (I'm just protecting my job by hiding internal details). > Version > 23585 of launchd doesn't have anything on line 5025 of > launchd_core_logic.c that would generate this message. In any case, if > you could provide a copy of your property-list file, we could probably > diagnose this faster. Righto: Label com.mycompany.agent OnDemand RunAtLoad KeepAlive SuccessfullExit LimitLoadToSessionType Aqua ProgramArguments MyProg Hope this helps. Please let me know if there is anything else I can do to help. Kind regards, Tim From tim at sbdev.net Wed Aug 20 08:20:29 2008 From: tim at sbdev.net (Tim Schooley) Date: Wed, 20 Aug 2008 16:20:29 +0100 Subject: [launchd-dev] LaunchAgent causing bug message in logs? In-Reply-To: References: <20080820092033.b2c103f6.tim@sbdev.net> <4A8AA886-FA29-4298-8CBF-53A0A543CAF3@apple.com> <20080820155654.7f435b39.tim@sbdev.net> Message-ID: <20080820162029.317a8070.tim@sbdev.net> Hi Dave, On Wed, 20 Aug 2008 08:11:12 -0700, Dave Zarzycki wrote: > The above contains a typo. SuccessfulExit contains one 'l', not two. > Also, please note that by setting OnDemand to false, that makes > RunAtLoad to true redundant. The same is true of the conditional > KeepAlive (it also is redundant). Please also note that OnDemand was > deprecated in favor of KeepAlive == true (and therefore making launchd > more consistent about the default value of boolean keys). Thanks for the comments - I've updated the plist accordingly. > If you want to file a bug on this, we'd appreciate it. I'll get on the case. Kind regards, Tim From tim at sbdev.net Wed Aug 20 08:30:49 2008 From: tim at sbdev.net (Tim Schooley) Date: Wed, 20 Aug 2008 16:30:49 +0100 Subject: [launchd-dev] LaunchAgent causing bug message in logs? In-Reply-To: <20080820162029.317a8070.tim@sbdev.net> References: <20080820092033.b2c103f6.tim@sbdev.net> <4A8AA886-FA29-4298-8CBF-53A0A543CAF3@apple.com> <20080820155654.7f435b39.tim@sbdev.net> <20080820162029.317a8070.tim@sbdev.net> Message-ID: <20080820163049.a384dbc8.tim@sbdev.net> Hi again, On Wed, 20 Aug 2008 16:20:29 +0100, Tim Schooley wrote: > > If you want to file a bug on this, we'd appreciate it. > > I'll get on the case. It actually appears to have gone, after updating the plist file. So it was probably complaining about a contradiction of keys or something (?). Cheers, Tim From eskimo1 at apple.com Wed Aug 20 08:42:47 2008 From: eskimo1 at apple.com (Quinn) Date: Wed, 20 Aug 2008 16:42:47 +0100 Subject: [launchd-dev] make sure process starts before login window In-Reply-To: References: <55a5c7c50808191202j5d8e6aa8s7e40b674137290c9@mail.gmail.com> Message-ID: At 22:49 +0100 19/8/08, Quinn wrote: >You could do this by munging but... yeah, that gets very >ugly very fast. And just to prove my point, apparently the /etc/ttys hack doesn't work on 10.5 and later. The equivalent hack is munging "/System/Library/LaunchDaemons/com.apple.loginwindow.plist". Not that this is any more sensible (-: S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware From shawnce at gmail.com Wed Aug 27 08:08:01 2008 From: shawnce at gmail.com (Shawn Erickson) Date: Wed, 27 Aug 2008 08:08:01 -0700 Subject: [launchd-dev] Stopping and uninstalling a LaunchDaemon job Message-ID: Looking for opinion on the best way to manage the uninstall of a launchd job that lives under /Library/LaunchDaemon. The uninstall process is currently planned to be triggered by an button/option displayed on one of the tabs of our system preferences plug-in. If the user clicks this we get authorization rights and attempt to do the uninstall that is needed. We have no issues using the rights we are granted to remove files owned by root, etc. but we cannot use launchctl to stop the LaunchDaemon because the uninstall task runs as the current user and not as root (aka doesn't see the top level launchd instance). Note this is a temporary issue in an alpha version of our product since we plan to begin utilizing an IPC mechanism to have our preference plug-in, etc. connect with our launch daemon. When this is up an going we can message the daemon directly to get it to do aspects of the uninstall and shutdown (since it is running as root). In other words this is just a quick uninstall solution for alpha and something that will be replaced... so not looking for something to fancy. -Shawn From eskimo1 at apple.com Wed Aug 27 08:15:55 2008 From: eskimo1 at apple.com (Quinn) Date: Wed, 27 Aug 2008 16:15:55 +0100 Subject: [launchd-dev] Stopping and uninstalling a LaunchDaemon job In-Reply-To: References: Message-ID: At 8:08 -0700 27/8/08, Shawn Erickson wrote: >We have no issues using the rights we are granted to remove files >owned by root, etc. but we cannot use launchctl to stop the >LaunchDaemon because the uninstall task runs as the current user and >not as root (aka doesn't see the top level launchd instance). I'm confused. To remove a file from /Library/LaunchDaemons you have to be running as root. Why can't you sublaunch launchctl from that context? S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware From shawnce at gmail.com Wed Aug 27 08:24:34 2008 From: shawnce at gmail.com (Shawn Erickson) Date: Wed, 27 Aug 2008 08:24:34 -0700 Subject: [launchd-dev] Stopping and uninstalling a LaunchDaemon job In-Reply-To: References: Message-ID: On Wed, Aug 27, 2008 at 8:15 AM, Quinn wrote: > At 8:08 -0700 27/8/08, Shawn Erickson wrote: >>We have no issues using the rights we are granted to remove files >>owned by root, etc. but we cannot use launchctl to stop the >>LaunchDaemon because the uninstall task runs as the current user and >>not as root (aka doesn't see the top level launchd instance). > > I'm confused. To remove a file from /Library/LaunchDaemons you have > to be running as root. Why can't you sublaunch launchctl from that > context? Sorry the guy that has been playing around with this isn't in just yet so I don't know the exact specifics but... It is my understanding he is using authorization services to run a script and that script is removing files, etc. just fine but launchctl running from under that script cannot see the top level launchctl instance to remove the launch daemon job. I believe he used id in the script as it logged the current user. I will pull up the code he is playing with, if I can find it, or wait until he gets in... -Shawn From eskimo1 at apple.com Wed Aug 27 08:36:43 2008 From: eskimo1 at apple.com (Quinn) Date: Wed, 27 Aug 2008 16:36:43 +0100 Subject: [launchd-dev] Stopping and uninstalling a LaunchDaemon job In-Reply-To: References: Message-ID: At 8:24 -0700 27/8/08, Shawn Erickson wrote: >Sorry the guy that has been playing around with this isn't in just yet >so I don't know the exact specifics but... It is my understanding he >is using authorization services to run a script and that script is >removing files, etc. just fine but launchctl running from under that >script cannot see the top level launchctl instance to remove the >launch daemon job. I believe he used id in the script as it logged the >current user. OK, this sounds like one of the standard gotchas with AuthorizationExecutionWithPrivileges; it runs the resulting program with EUID == 0 but RUID inherited from the process that called AEWP , and launchctl is getting confused by the RUID. If you were writing real code I would recommend: 1. don't use a script, use a C-based tool 2. in that tool call setuid(0) to force the RUID to 0 However, given that you're just putting in a temporary hack then I'll recommend the following trick: $ chroot -u 0 / launchctl which converts an EUID == 0 / RUID != 0 context into a EUID == RUID == 0. Sneaky huh? IMPORTANT: Please don't leave these hacks in your production code. In my experience "temporary + work == permanent". S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware From shawnce at gmail.com Wed Aug 27 09:11:13 2008 From: shawnce at gmail.com (Shawn Erickson) Date: Wed, 27 Aug 2008 09:11:13 -0700 Subject: [launchd-dev] Stopping and uninstalling a LaunchDaemon job In-Reply-To: References: Message-ID: On Wed, Aug 27, 2008 at 8:36 AM, Quinn wrote: > At 8:24 -0700 27/8/08, Shawn Erickson wrote: >>Sorry the guy that has been playing around with this isn't in just yet >>so I don't know the exact specifics but... It is my understanding he >>is using authorization services to run a script and that script is >>removing files, etc. just fine but launchctl running from under that >>script cannot see the top level launchctl instance to remove the >>launch daemon job. I believe he used id in the script as it logged the >>current user. > > OK, this sounds like one of the standard gotchas with > AuthorizationExecutionWithPrivileges; it runs the resulting program > with EUID == 0 but RUID inherited from the process that called AEWP > , and launchctl is getting confused by the > RUID. Ah that likely explains what he saw. Thanks > If you were writing real code I would recommend: > > 1. don't use a script, use a C-based tool > > 2. in that tool call setuid(0) to force the RUID to 0 > > However, given that you're just putting in a temporary hack then I'll > recommend the following trick: > > $ chroot -u 0 / launchctl > > which converts an EUID == 0 / RUID != 0 context into a EUID == RUID > == 0. Sneaky huh? Interesting. Thanks again. > IMPORTANT: Please don't leave these hacks in your production code. > In my experience "temporary + work == permanent". Yup they have a way of doing that luckily this component is throw away, at least in this form. -Shawn From kcrwfrd at gmail.com Wed Aug 27 11:28:27 2008 From: kcrwfrd at gmail.com (Crawford Kyle) Date: Wed, 27 Aug 2008 14:28:27 -0400 Subject: [launchd-dev] Restrict so only one instance runs Message-ID: <7E2D37AE-1C47-4020-A6E8-7128365F1F90@gmail.com> Hello, I often need to schedule scripts to run at an interval, but I don't know how long that script will take to complete and I don't want the script to run again at its normal interval unless the script isn't running. I've done this with pid files and grepping through ps lists to exit the script if another instance is running, but I was wondering if there is something built into launchd to handle this. I tried combining LaunchOnlyOnce with StartInterval, but with LaunchOnlyOnce, it seems that the job gets unloaded as soon as it runs, so the interval becomes pretty meaningless. Is there a way to do this with launchd? Should there be a way to do this with launchd? Thanks, Kyle From zarzycki at apple.com Wed Aug 27 12:29:19 2008 From: zarzycki at apple.com (Dave Zarzycki) Date: Wed, 27 Aug 2008 12:29:19 -0700 Subject: [launchd-dev] Restrict so only one instance runs In-Reply-To: <7E2D37AE-1C47-4020-A6E8-7128365F1F90@gmail.com> References: <7E2D37AE-1C47-4020-A6E8-7128365F1F90@gmail.com> Message-ID: <9C2E6588-9126-4CDD-A3B8-A71271E3AD90@apple.com> On Aug 27, 2008, at 11:28 AM, Crawford Kyle wrote: > Hello, > > I often need to schedule scripts to run at an interval, but I don't > know how long that script will take to complete and I don't want the > script to run again at its normal interval unless the script isn't > running. > > I've done this with pid files and grepping through ps lists to exit > the script if another instance is running, but I was wondering if > there is something built into launchd to handle this. > > I tried combining LaunchOnlyOnce with StartInterval, but with > LaunchOnlyOnce, it seems that the job gets unloaded as soon as it > runs, so the interval becomes pretty meaningless. > > Is there a way to do this with launchd? Should there be a way to do > this with launchd? What you want is implicit with launchd. LaunchOnlyOnce will eventually get renamed to "HopefullyNeverExits" Just setup a StartInterval and you're set. If the job is still running, launchd will not start a second copy. davez From kcrwfrd at gmail.com Wed Aug 27 16:42:07 2008 From: kcrwfrd at gmail.com (Crawford Kyle) Date: Wed, 27 Aug 2008 19:42:07 -0400 Subject: [launchd-dev] Restrict so only one instance runs In-Reply-To: <9C2E6588-9126-4CDD-A3B8-A71271E3AD90@apple.com> References: <7E2D37AE-1C47-4020-A6E8-7128365F1F90@gmail.com> <9C2E6588-9126-4CDD-A3B8-A71271E3AD90@apple.com> Message-ID: On Aug 27, 2008, at 3:29 PM, Dave Zarzycki wrote: > > On Aug 27, 2008, at 11:28 AM, Crawford Kyle wrote: > >> Hello, >> >> I often need to schedule scripts to run at an interval, but I don't >> know how long that script will take to complete and I don't want the >> script to run again at its normal interval unless the script isn't >> running. >> >> I've done this with pid files and grepping through ps lists to exit >> the script if another instance is running, but I was wondering if >> there is something built into launchd to handle this. >> >> I tried combining LaunchOnlyOnce with StartInterval, but with >> LaunchOnlyOnce, it seems that the job gets unloaded as soon as it >> runs, so the interval becomes pretty meaningless. >> >> Is there a way to do this with launchd? Should there be a way to do >> this with launchd? > > > What you want is implicit with launchd. LaunchOnlyOnce will > eventually get renamed to "HopefullyNeverExits" Just setup a > StartInterval and you're set. If the job is still running, launchd > will not start a second copy. Thanks Dave. I must be missing something. Here is my job plist. The shell script is just a test that logs to system log. I see a message in system log only once though. And the job no longer shows in launchctl list after it runs. I tried this with and without OnDemand. Label com.company.test ProgramArguments /etc/testscript.sh StartInterval 30 LaunchOnlyOnce From zarzycki at apple.com Wed Aug 27 17:07:19 2008 From: zarzycki at apple.com (Dave Zarzycki) Date: Wed, 27 Aug 2008 17:07:19 -0700 Subject: [launchd-dev] Restrict so only one instance runs In-Reply-To: References: <7E2D37AE-1C47-4020-A6E8-7128365F1F90@gmail.com> <9C2E6588-9126-4CDD-A3B8-A71271E3AD90@apple.com> Message-ID: On Aug 27, 2008, at 4:42 PM, Crawford Kyle wrote: > > On Aug 27, 2008, at 3:29 PM, Dave Zarzycki wrote: > >> >> On Aug 27, 2008, at 11:28 AM, Crawford Kyle wrote: >> >>> Hello, >>> >>> I often need to schedule scripts to run at an interval, but I don't >>> know how long that script will take to complete and I don't want the >>> script to run again at its normal interval unless the script isn't >>> running. >>> >>> I've done this with pid files and grepping through ps lists to exit >>> the script if another instance is running, but I was wondering if >>> there is something built into launchd to handle this. >>> >>> I tried combining LaunchOnlyOnce with StartInterval, but with >>> LaunchOnlyOnce, it seems that the job gets unloaded as soon as it >>> runs, so the interval becomes pretty meaningless. >>> >>> Is there a way to do this with launchd? Should there be a way to do >>> this with launchd? >> >> >> What you want is implicit with launchd. LaunchOnlyOnce will >> eventually get renamed to "HopefullyNeverExits" Just setup a >> StartInterval and you're set. If the job is still running, launchd >> will not start a second copy. > > Thanks Dave. I must be missing something. Here is my job plist. > The shell script is just a test that logs to system log. > > I see a message in system log only once though. And the job no > longer shows in launchctl list after it runs. > > I tried this with and without OnDemand. > > > "> > > > Label > com.company.test > ProgramArguments > > /etc/testscript.sh > > StartInterval > 30 > LaunchOnlyOnce > > > Delete the "LaunchOnlyOnce" key. davez From kcrwfrd at gmail.com Wed Aug 27 18:21:27 2008 From: kcrwfrd at gmail.com (Crawford Kyle) Date: Wed, 27 Aug 2008 21:21:27 -0400 Subject: [launchd-dev] Restrict so only one instance runs In-Reply-To: References: <7E2D37AE-1C47-4020-A6E8-7128365F1F90@gmail.com> <9C2E6588-9126-4CDD-A3B8-A71271E3AD90@apple.com> Message-ID: <08B0C655-8939-40DE-A4C4-79C984626D93@gmail.com> On Aug 27, 2008, at 8:07 PM, Dave Zarzycki wrote: > Delete the "LaunchOnlyOnce" key. > > davez That default behavior really threw me off. Doh. Thanks Dave : ) From ian at slumbrparty.com Thu Aug 28 01:12:19 2008 From: ian at slumbrparty.com (Ian) Date: Thu, 28 Aug 2008 01:12:19 -0700 Subject: [launchd-dev] can i do this with launchd? (on-demand auto-restart daemons) Message-ID: <31003eee0808280112m343ac955hfc273c1918e63444@mail.gmail.com> i am interested in writing a cocoa front end to hellanzb. it is a python program that has a daemon mode. you interact with it via a tcp socket. i want to use launchd to control the daemon. 1. it should start when the cocoa GUI is started (either manually or via a startup item) 2. if the daemon dies for whatever reason, launchd should restart it 3. if the GUI is closed, the daemon should be shut off without having it restart. thank you for your help. ian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-dev/attachments/20080828/17c19088/attachment.html From dave-ml at dribin.org Thu Aug 28 21:36:04 2008 From: dave-ml at dribin.org (Dave Dribin) Date: Thu, 28 Aug 2008 23:36:04 -0500 Subject: [launchd-dev] No pboard server? Message-ID: <37F8DB7C-7FF0-4C70-8699-45DE1E864280@dribin.org> Hi all, This is sort of a last ditch effort before I re-install.... A few hours ago, copy and paste stopped working on my MBP (running 10.5.4). Sure enough pboard was dead. I decided to reboot, just in case anything else got messed up. Now it will not start at all. Running "launchctl list" does not show it, and if I try and explicitly list it, I get the following error message: % launchctl list com.apple.pboard launch_msg(): Socket is not connected I get the same error message if I try to load com.apple.pboard.plist. I've also noticed that Apache and ssh-agent also are no longer starting, either, so something is definitely wonky with some of the system daemons. There are probably other critical daemons not starting, I imagine, too. Note: there's plenty of free disk space (32 GB). Any other idea? I'm nearly ready to re-install at this point. Thanks, -Dave From dave-ml at dribin.org Thu Aug 28 22:18:54 2008 From: dave-ml at dribin.org (Dave Dribin) Date: Fri, 29 Aug 2008 00:18:54 -0500 Subject: [launchd-dev] No pboard server? In-Reply-To: <37F8DB7C-7FF0-4C70-8699-45DE1E864280@dribin.org> References: <37F8DB7C-7FF0-4C70-8699-45DE1E864280@dribin.org> Message-ID: <3CB1A1EE-357E-4B0D-AC5D-8F4AAFCC3E96@dribin.org> On Aug 28, 2008, at 11:36 PM, Dave Dribin wrote: > Hi all, > > This is sort of a last ditch effort before I re-install.... A few > hours ago, copy and paste stopped working on my MBP (running 10.5.4). > Sure enough pboard was dead. I decided to reboot, just in case > anything else got messed up. Now it will not start at all. Running > "launchctl list" does not show it, and if I try and explicitly list > it, I get the following error message: > > % launchctl list com.apple.pboard > launch_msg(): Socket is not connected Well, somehow /private/tmp went missing. Recreated it, and now all is fine. I've no idea how that happened. Anyhow, please disregard this last message. One thing, though... isn't there some script that clears out /private/ tmp at startup? Perhaps it should also check to make sure it exists? Actually, it looks like /etc/rc used to do just that on 10.4. Where does this happen on 10.5 now? launchd itself? I didn't see anything in the source. -Dave From eskimo1 at apple.com Fri Aug 29 03:28:39 2008 From: eskimo1 at apple.com (Quinn) Date: Fri, 29 Aug 2008 11:28:39 +0100 Subject: [launchd-dev] can i do this with launchd? (on-demand auto-restart daemons) In-Reply-To: <31003eee0808280112m343ac955hfc273c1918e63444@mail.gmail.com> References: <31003eee0808280112m343ac955hfc273c1918e63444@mail.gmail.com> Message-ID: At 1:12 -0700 28/8/08, Ian wrote: >can i do this with launchd? Yes. This is exactly the sort of thing that launchd excels at. >1. it should start when the cocoa GUI is started (either manually or >via a startup item) The best way to handle this is to have the daemon launch when a client connects to its TCP socket. You do this by setting up the "Sockets" dictionary in your launchd property list file. launchd will open and listen to the socket on your behalf. When a connection comes in, launchd will run your daemon and pass the listening socket to it. When your daemon quits, launchd will resume listening on the socket. The SampleD sample code shows this basic process. >2. if the daemon dies for whatever reason, launchd should restart it Typically you only want launchd to restart the daemon if someone has connected to the TCP socket. That's the default behaviour. However, you can arrange for other behaviour by way of the "KeepAlive" property. See for details. >3. if the GUI is closed, the daemon should be shut off without >having it restart. When the GUI quits the TCP connection to the daemon will close. When the daemon has no open connections, it should quit (after some debounce period). The only real wrinkle in this is Python. When writing a launchd daemon you have to "check in" with launchd to get access to your listening socket. That requires use of the API. AFAIK there's no direct Python binding to that. It's a simple C API, so if you're familiar with glue Python to C it shouldn't present a serious obstacle. Otherwise, you might investigate wrapping your Python code within PyObjC so you can do the launchd check in from C and then do all the real work from Python. S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware From ian at slumbrparty.com Fri Aug 29 11:31:28 2008 From: ian at slumbrparty.com (Ian) Date: Fri, 29 Aug 2008 11:31:28 -0700 Subject: [launchd-dev] can i do this with launchd? (on-demand auto-restart daemons) In-Reply-To: References: <31003eee0808280112m343ac955hfc273c1918e63444@mail.gmail.com> Message-ID: <2B42997D-C6C2-41C2-9F38-8CBDC39E9A8E@slumbrparty.com> thank you for the thorough response. i'll investigate more about the python thing. since it is an existing codebase, i'll have to look into the last two options. thanks, ian On Aug 29, 2008, at 3:28 AM, Quinn wrote: > At 1:12 -0700 28/8/08, Ian wrote: >> can i do this with launchd? > > Yes. This is exactly the sort of thing that launchd excels at. > >> 1. it should start when the cocoa GUI is started (either manually or >> via a startup item) > > The best way to handle this is to have the daemon launch when a > client connects to its TCP socket. You do this by setting up the > "Sockets" dictionary in your launchd property list file. launchd > will open and listen to the socket on your behalf. When a connection > comes in, launchd will run your daemon and pass the listening socket > to it. When your daemon quits, launchd will resume listening on the > socket. > > The SampleD sample code shows this basic process. > > > >> 2. if the daemon dies for whatever reason, launchd should restart it > > Typically you only want launchd to restart the daemon if someone has > connected to the TCP socket. That's the default behaviour. However, > you can arrange for other behaviour by way of the "KeepAlive" > property. See for details. > >> 3. if the GUI is closed, the daemon should be shut off without >> having it restart. > > When the GUI quits the TCP connection to the daemon will close. When > the daemon has no open connections, it should quit (after some > debounce period). > > The only real wrinkle in this is Python. When writing a launchd > daemon you have to "check in" with launchd to get access to your > listening socket. That requires use of the API. AFAIK > there's no direct Python binding to that. It's a simple C API, so if > you're familiar with glue Python to C it shouldn't present a serious > obstacle. Otherwise, you might investigate wrapping your Python code > within PyObjC so you can do the launchd check in from C and then do > all the real work from Python. > > S+E > -- > Quinn "The Eskimo!" > > Apple Developer Relations, Developer Technical Support, Core OS/ > Hardware > _______________________________________________ > launchd-dev mailing list > launchd-dev at lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev From dave-ml at dribin.org Fri Aug 29 11:40:15 2008 From: dave-ml at dribin.org (Dave Dribin) Date: Fri, 29 Aug 2008 13:40:15 -0500 Subject: [launchd-dev] No pboard server? In-Reply-To: <3CB1A1EE-357E-4B0D-AC5D-8F4AAFCC3E96@dribin.org> References: <37F8DB7C-7FF0-4C70-8699-45DE1E864280@dribin.org> <3CB1A1EE-357E-4B0D-AC5D-8F4AAFCC3E96@dribin.org> Message-ID: On Aug 29, 2008, at 12:18 AM, Dave Dribin wrote: > One thing, though... isn't there some script that clears out /private/ > tmp at startup? Perhaps it should also check to make sure it exists? > Actually, it looks like /etc/rc used to do just that on 10.4. Where > does this happen on 10.5 now? launchd itself? I didn't see anything > in the source. I just confirmed that if /private/tmp is not present on boot, it does not get re-created and then Bad Things happen (one of which is no pboard daemon). I'm still not seeing where /private/tmp gets cleared on boot for 10.5. Best I can come up with is /etc/periodic/daily/110.clean-tmps. -Dave From dave-ml at dribin.org Fri Aug 29 14:13:49 2008 From: dave-ml at dribin.org (Dave Dribin) Date: Fri, 29 Aug 2008 16:13:49 -0500 Subject: [launchd-dev] No pboard server? In-Reply-To: References: <37F8DB7C-7FF0-4C70-8699-45DE1E864280@dribin.org> <3CB1A1EE-357E-4B0D-AC5D-8F4AAFCC3E96@dribin.org> Message-ID: <3E453280-0E7D-40F9-98BF-E2F5FE6BC347@dribin.org> On Aug 29, 2008, at 1:40 PM, Dave Dribin wrote: > I just confirmed that if /private/tmp is not present on boot, it does > not get re-created and then Bad Things happen (one of which is no > pboard daemon). And bug filed: -Dave From eskimo1 at apple.com Fri Aug 29 11:35:10 2008 From: eskimo1 at apple.com (Quinn) Date: Fri, 29 Aug 2008 19:35:10 +0100 Subject: [launchd-dev] can i do this with launchd? (on-demand auto-restart daemons) In-Reply-To: <2B42997D-C6C2-41C2-9F38-8CBDC39E9A8E@slumbrparty.com> References: <31003eee0808280112m343ac955hfc273c1918e63444@mail.gmail.com> <2B42997D-C6C2-41C2-9F38-8CBDC39E9A8E@slumbrparty.com> Message-ID: At 11:31 -0700 29/8/08, Ian wrote: >thank you for the thorough response. i'll investigate more about the >python thing. since it is an existing codebase, i'll have to look >into the last two options. My experience is that Python makes it pretty easy to access C APIs. You can write a full blown Python module to do the job, or just bodgy something together using the "ctypes" module. S+E -- Quinn "The Eskimo!" Apple Developer Relations, Developer Technical Support, Core OS/Hardware From ian at slumbrparty.com Fri Aug 29 14:31:12 2008 From: ian at slumbrparty.com (Ian) Date: Fri, 29 Aug 2008 14:31:12 -0700 Subject: [launchd-dev] can i do this with launchd? (on-demand auto-restart daemons) In-Reply-To: References: <31003eee0808280112m343ac955hfc273c1918e63444@mail.gmail.com> <2B42997D-C6C2-41C2-9F38-8CBDC39E9A8E@slumbrparty.com> Message-ID: <24200092-EBD0-49F7-B6C7-0962A9B05953@slumbrparty.com> my concern is if i want to write a CLI UI in addition to the GUI, then the CLI cant maintain an open TCP connection. i may just have the agent run at login and just not do anything. this simplifies things a lot cause then i just have to make a plist file. On Aug 29, 2008, at 11:35 AM, Quinn wrote: > At 11:31 -0700 29/8/08, Ian wrote: >> thank you for the thorough response. i'll investigate more about the >> python thing. since it is an existing codebase, i'll have to look >> into the last two options. > > My experience is that Python makes it pretty easy to access C APIs. > You can write a full blown Python module to do the job, or just bodgy > something together using the "ctypes" module. > > > > S+E > -- > Quinn "The Eskimo!" > > Apple Developer Relations, Developer Technical Support, Core OS/ > Hardware > _______________________________________________ > launchd-dev mailing list > launchd-dev at lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev