The "daemons must live for at least 60 seconds" factoid

View: New views
6 Messages — Rating Filter:   Alert me  

The "daemons must live for at least 60 seconds" factoid

by Jonathan del Strother :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's a commonly repeated piece of folklore that if your launchdaemon
completes in under 60 seconds, launchd will assume it has crashed and
will re-launch it.  I have a LaunchAgent with a 2 minute
StartInterval, which exits quickly if there are no available jobs for
it to work on.  launchd tends to run it once due to the StartInterval,
then again 15 seconds later - presumably because it didn't live for at
least 60 seconds.  Adding "sleep(60)" to the end of my LaunchAgent
seems to prevent it from launching the 2nd time around.

 However, I can't find any actual documentation that mentions this,
and I'm sure I've heard somewhere that it was a Tiger bug/feature
only, due to be fixed in Leopard - this appears to not be the case.
It seems an odd feature, too - why relaunch something that exited with
a successful status code?

Is there any official documentation of this behaviour?

-Jonathan del Strother
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev

Re: The "daemons must live for at least 60 seconds" factoid

by Kevin Van Vechten-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In general, launchd does not relaunch processes which exit successfully.

It would help if you shared the relevant portions of your launchd plist.

Kevin

On Aug 19, 2009, at 5:16 AM, Jonathan del Strother wrote:

> It's a commonly repeated piece of folklore that if your launchdaemon
> completes in under 60 seconds, launchd will assume it has crashed and
> will re-launch it.  I have a LaunchAgent with a 2 minute
> StartInterval, which exits quickly if there are no available jobs for
> it to work on.  launchd tends to run it once due to the StartInterval,
> then again 15 seconds later - presumably because it didn't live for at
> least 60 seconds.  Adding "sleep(60)" to the end of my LaunchAgent
> seems to prevent it from launching the 2nd time around.
>
> However, I can't find any actual documentation that mentions this,
> and I'm sure I've heard somewhere that it was a Tiger bug/feature
> only, due to be fixed in Leopard - this appears to not be the case.
> It seems an odd feature, too - why relaunch something that exited with
> a successful status code?
>
> Is there any official documentation of this behaviour?
>
> -Jonathan del Strother

_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev

Re: The "daemons must live for at least 60 seconds" factoid

by Quinn-9 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In addition to what Kevin said...

At 13:16 +0100 19/8/09, Jonathan del Strother wrote:
>It's a commonly repeated piece of folklore that if your launchdaemon
>completes in under 60 seconds, launchd will assume it has crashed and
>will re-launch it.

I think this folklore is a bit mixed up.  It's not that launchd
assumes that the job crashed, and thus relaunches it, it's that
launchd will /prevent/ it from being launched again too quickly.  In
modern versions of launchd (10.5 and later?) the value changed (to 10
seconds) and you can control the value on a job-by-job basis with the
ThrottleInterval key (see <x-man-page://5/launchd.plist> for details).

S+E
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev

Re: The "daemons must live for at least 60 seconds" factoid

by Jonathan del Strother :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the reply - turns out that it's being relaunched because
launchd thinks one of the watch paths changed.  I'm not sure why - to
the best of my knowledge it's been read from, but not written to - but
at least it clears up one mystery.  It's actually monitoring a sqlite
database - maybe sqlite is invisibly writing to it behind the scenes,
I'll see if I can find anything with instruments...


On Wed, Aug 19, 2009 at 6:16 PM, Kevin Van Vechten<kvv@...> wrote:

> In general, launchd does not relaunch processes which exit successfully.
>
> It would help if you shared the relevant portions of your launchd plist.
>
> Kevin
>
> On Aug 19, 2009, at 5:16 AM, Jonathan del Strother wrote:
>
>> It's a commonly repeated piece of folklore that if your launchdaemon
>> completes in under 60 seconds, launchd will assume it has crashed and
>> will re-launch it.  I have a LaunchAgent with a 2 minute
>> StartInterval, which exits quickly if there are no available jobs for
>> it to work on.  launchd tends to run it once due to the StartInterval,
>> then again 15 seconds later - presumably because it didn't live for at
>> least 60 seconds.  Adding "sleep(60)" to the end of my LaunchAgent
>> seems to prevent it from launching the 2nd time around.
>>
>> However, I can't find any actual documentation that mentions this,
>> and I'm sure I've heard somewhere that it was a Tiger bug/feature
>> only, due to be fixed in Leopard - this appears to not be the case.
>> It seems an odd feature, too - why relaunch something that exited with
>> a successful status code?
>>
>> Is there any official documentation of this behaviour?
>>
>> -Jonathan del Strother
>
>
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev

Re: The "daemons must live for at least 60 seconds" factoid

by Quinn-9 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 14:33 +0100 20/8/09, Jonathan del Strother wrote:
>It's actually monitoring a sqlite
>database - maybe sqlite is invisibly writing to it behind the scenes,
>I'll see if I can find anything with instruments...

It's likely that <x-man-page://1/fs_usage> will also be instructive
in this case.

S+E
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev

Parent Message unknown Re: The "daemons must live for at least 60 seconds" factoid

by Jonathan del Strother :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Aug 20, 2009 at 2:41 PM, Quinn<eskimo1@...> wrote:
> At 14:33 +0100 20/8/09, Jonathan del Strother wrote:
>>
>> It's actually monitoring a sqlite
>> database - maybe sqlite is invisibly writing to it behind the scenes,
>> I'll see if I can find anything with instruments...
>
> It's likely that <x-man-page://1/fs_usage> will also be instructive in this
> case.
>

Yeah, fs_usage shows sqlite is accessing the file with "open F=3
(RWC___)" - I guess that's O_RDWR|O_CREAT?  Is that enough to trigger
launchd's watch paths?
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev