Disabling of launchd job if program is missing
Hello, in my program I use quite a simple launchd jobs to perform some tasks. This job is configured to run some tool when certain conditions are met. All works fine except one case. When user deletes this tool (e.g. after incorrect uninstall of program), then launchd fails to find tool and therefore fails to run my job. The following error is logged: 25/04/2010 23:26:11 com.apple.launchd.peruser.501[224] (<job label>[89736]) posix_spawn(<path to tool>, ...): No such file or directory The problem is that after this launchd keep trying to run this job. Why it just don't disable this job? If this is desired behavior, is it possible to configure it somehow to disable job if it's tool is missing? This is not just my software problem. Lots of other programs have such issues. -- Thanks, Vera Tkachenko
If Launchd doesnt cover it, then can be fixed by doing some extra work. For example: 1) If you call a runner script from your launchd job, instead of invoking the tool directly, then you can write in the runner script a proceedure to uninstall or disable the job (and associated script file, plist file), for the special case when tool is not found. Otherwise if tool is found then execute it normally. The runner script should be installed to an less apparent location such as application support folder, etc. 2) Another possibility is to give users an uninstall option in the .pkg installer. That should delete the remaining plist file and disable the launchd service. They can run the uninstaller to remove remaining files after a failed installation. 3) Develop a menu item in GUI app to install / uninstall the launchd service. That is a better mechanism for most users. A menu item is something relatively easy to point to in your help / support documentation. On Tue, Jul 6, 2010 at 10:29 AM, Vera Tkachenko <ivira@macpaw.com> wrote:
Hello,
in my program I use quite a simple launchd jobs to perform some tasks. This job is configured to run some tool when certain conditions are met. All works fine except one case. When user deletes this tool (e.g. after incorrect uninstall of program), then launchd fails to find tool and therefore fails to run my job.
The following error is logged: 25/04/2010 23:26:11 com.apple.launchd.peruser.501[224] (<job label>[89736]) posix_spawn(<path to tool>, ...): No such file or directory
The problem is that after this launchd keep trying to run this job. Why it just don't disable this job? If this is desired behavior, is it possible to configure it somehow to disable job if it's tool is missing? This is not just my software problem. Lots of other programs have such issues.
-- Thanks, Vera Tkachenko
_______________________________________________ launchd-dev mailing list launchd-dev@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev
On Tue, Jul 6, 2010 at 10:29 AM, Vera Tkachenko <ivira@macpaw.com> wrote:
When user deletes this tool (e.g. after incorrect uninstall of program), then launchd fails to find tool and … the following error is logged:
com.apple.launchd.peruser.501[224] (<job label>[89736]) posix_spawn(<path to tool>, ...): No such file or directory
Every ten seconds!
Why it just don't disable this job?
That's a "damned good question".
is it possible to configure it somehow to disable job if it's tool is missing?
Certainly one would expect a simple algorithm which would cause it to back off and then warn the user and give up after awhile, not continue to try every ten seconds until eternity.
This is not just my software problem. Lots of other programs have such issues.
Yes. On 2010 Jul 06, at 04:27, Dreamcat4 wrote:
If Launchd doesnt cover it,
That's the problem. launchd does not cover it.
then can be fixed by doing some extra work. For example:
1) … Instead of invoking the tool directly, … runner script … installed to an less apparent location …
Well, that might be better but the runner script could be deleted too.
2) … uninstall option in the .pkg installer …
3) … Menu item in GUI app to uninstall the launchd service.
Indeed, when I thought about this problem a few weeks ago, an uninstaller was the only I could think of. However, many Mac users don't look for nor expect that an uninstaller is necessary. Sure you can make it easy to find, as suggested by Dreamcat4, but it's still a pain. And for people who uninstall your app without running the uninstaller, you should make a separate uninstaller script download available to to them. It's a pain. I believe that this is the classic problem of "painting yourself into a corner". When you write an app using launchd, launchd becomes part of your app, and it should have some cleanup mechanism built into it. Could/should we file a bug on this? Should we file on the Apple Bug Reporter or is launchd not supported by Apple because it's "open source"? Jerry
On Jul 6, 2010, at 2:29 AM, Vera Tkachenko wrote:
Hello,
in my program I use quite a simple launchd jobs to perform some tasks. This job is configured to run some tool when certain conditions are met. All works fine except one case. When user deletes this tool (e.g. after incorrect uninstall of program), then launchd fails to find tool and therefore fails to run my job.
The following error is logged: 25/04/2010 23:26:11 com.apple.launchd.peruser.501[224] (<job label>[89736]) posix_spawn(<path to tool>, ...): No such file or directory
You should provide the user with an uninstaller so as to minimize the chances of screwing up the uninstall.
The problem is that after this launchd keep trying to run this job. Why it just don't disable this job?
launchd doesn't know that the needed resource won't come online in the future, so it keeps trying. We used to automatically disable jobs if they failed to run a certain number of times. This didn't really help anyone and in fact made life harder if your binary lived on a network volume that didn't get mounted right away. Basically, launchd expects you to have your ducks in a row and will patiently wait for you to get them there.
If this is desired behavior, is it possible to configure it somehow to disable job if it's tool is missing? This is not just my software problem. Lots of other programs have such issues.
If this is a concern for you, I'd suggest using a trampoline program. But it's worth finding out just how many of your customers run into this problem and whether you can expose the correct uninstall procedure in an easy-to-discover manner. -- Damien Sorresso BSD Engineering Apple Inc.
On 2010 Jul 06, at 10:57, Damien Sorresso wrote:
launchd doesn't know that the needed resource won't come online in the future, so it keeps trying. We used to automatically disable jobs if they failed to run a certain number of times. This didn't really help anyone and in fact made life harder if your binary lived on a network volume that didn't get mounted right away.
Thank you for the history, Damien. Indeed, in some cases, as in the example you mentioned, we wouldn't want launchd to simply forget the job after a few tries. But even in your example case, say if the user is working "off line" for five hours, they're going to see this message logged in their Console every ten seconds -- that's 5*60*6 = 1800 log messages. Of course, using a trampoline program and an uninstaller are solutions, and are currently required by developers. But since we all need to do the same thing, some "LaunchFail" parameters in launchd.plist(5) would be very helpful. For example, there might be several "backoff" algorithms from which to choose, with parameters to set, and a parameter stating whether and how to notify the user. Would anyone else like me to file a bug? Jerry
On Tue, Jul 6, 2010 at 7:54 PM, Jerry Krinock <jerry@ieee.org> wrote:
On 2010 Jul 06, at 10:57, Damien Sorresso wrote:
launchd doesn't know that the needed resource won't come online in the future, so it keeps trying. We used to automatically disable jobs if they failed to run a certain number of times. This didn't really help anyone and in fact made life harder if your binary lived on a network volume that didn't get mounted right away.
Thank you for the history, Damien. Indeed, in some cases, as in the example you mentioned, we wouldn't want launchd to simply forget the job after a few tries. But even in your example case, say if the user is working "off line" for five hours, they're going to see this message logged in their Console every ten seconds -- that's 5*60*6 = 1800 log messages.
Of course, using a trampoline program and an uninstaller are solutions, and are currently required by developers. But since we all need to do the same thing, some "LaunchFail" parameters in launchd.plist(5) would be very helpful. For example, there might be several "backoff" algorithms from which to choose, with parameters to set, and a parameter stating whether and how to notify the user. Would anyone else like me to file a bug?
Having a backoff algorithm is a cool idea. However (and I have investigated this very thoroughly): Any worthwhiile backoff scheme would be significantly more complex to implement and serve as more of a luxury than a necessity. Theres not as much call for it. Usually those things can be programmed around in some other way that is "not-as-good-but-still-good-enough". However for the "trampoline" mechanism or whatever you want to callit. That would definately be well worth adding to launchd. With a boolean plist key to enable / disable it. Absolutely great stuff. It's the best solution for the OP's problem and stops everyone else having to write awkward uninstaller programs too. Of course, that would (at earliest) only come into effect OS X 10.7. Question: Patches welcome?
Jerry
_______________________________________________ launchd-dev mailing list launchd-dev@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev
participants (4)
-
Damien Sorresso
-
Dreamcat4
-
Jerry Krinock
-
Vera Tkachenko