Home › Forums › OS X Server and Client Discussion › Questions and Answers › launchd StartInterval
- This topic has 4 replies, 2 voices, and was last updated 17 years, 3 months ago by
cshooshan.
-
AuthorPosts
-
January 11, 2008 at 3:50 am #371082
cshooshan
ParticipantGood day!
I am stumped. I have a launchd plist that has a StartInterval set for 86400 (once per day). I do not want to convert to a StartCalendarInterval but I would like to shift the execution time by approximately twelve hours. I cannot figure out where launchd stores the time for the next execution of a particular StartInterval plist or all jobs. Some posts refer to a “diary,” but I have found no such thing.
I have tried launchctl stop
followed by launchctl start but there is no change to the time it runs each day. Any ideas?
Thanks,
CharlieJanuary 15, 2008 at 2:13 am #371119khiltd
ParticipantIf there is such a private file I’m certain Apple wouldn’t want you mucking around with it. Why [i]can’t[/i] you use a StartCalendarInterval tag for this?
January 15, 2008 at 10:06 pm #371121cshooshan
ParticipantBecause StartInterval is all I need and there should be a way to seed a job with a specific start time. Certainly unloading and loading the “job” should restart the timer but it does not.
And, as far as Apple not wanting me to muck around with it, the whole launchd process is fairly involved (no Apple GUI for launchd plist editing — Lingon is good if you need it) — if I can edit “jobs,” I think Apple would think me capable of touching other config files related to launchd.
And, mostly, I want to know how it works.
— Charlie
January 17, 2008 at 2:35 pm #371147khiltd
ParticipantI see a number of flaws in your reasoning here:
1. StartInterval is clearly [b]not[/b] all you need if what you need is to specify a start time. StartInterval specifies, obviously, an interval, not any particular point in time.
2. Schedulers are generally not written to be oven timers. In order to provide accuracy and reliability, it makes far more sense to calculate times based on offsets from absolute reference points. That way you more or less just check to see if the current number of seconds since Unix Epoch is an even multiple of a job’s interval and you’re done calculating. I don’t know for a fact that this logic is employed by launchd, but it wouldn’t surprise me if it were. If you need your job to run the instant it’s loaded, that’s what the RunAtLoad tag is for.
3. XML files are only used in situations where human readability is a concern, and in most cases, it is not. Just because you can edit “jobs” doesn’t mean you can do anything useful with any given file. If people were any good at sight-reading arbitrarily formatted computer files then data recovery services would be a whole lot cheaper.
4. launchd is open source, so anyone who is interested can find out how it works. In briefly looking over the relevant portions it’s apparent that launchd relies upon BSD’s kqueue methods for its scheduling and watchpath functionality. I’ve not looked at [b]that[/b] code at all, but even if we do assume that the kernel does in fact waste time writing its timers’ intervals out to a “diary” file on disk rather than simply storing them in volatile memory, it’d be a fairly safe bet that these files would not be safe for human consumption and should be left alone.
January 19, 2008 at 3:33 am #371161cshooshan
ParticipantHowdy!
Your points are well taken. Since it my inderstanding that afp548.com is intended for mutual education and benefit, you have done well by me.
When you said,”launchd is open source, so anyone who is interested can find out how it works. In briefly looking over the relevant portions it’s apparent that launchd relies upon BSD’s kqueue methods for its scheduling and watchpath functionality,” it really helped since I had missed the kqueue connection. I’ve read a lot now and more fully respect its complexity. Thanks for the education.
Here’s the deal. I thought I only needed StartInterval because right now I want this thing to run once a day and I don’t care very much what time it runs — I just want to avoid 9:00 a.m. to noon. In the future, I will probably run it from 2x to 4x per day. So, StartInterval seemed good for me. I just made the “mistake” of loading it at 10:00 a.m. the first time. So, now it runs every day at 10:00 a.m. I thought, gee, shouldn’t I be able to “seed” the start time outside my 3 hour no-run window. The answer seems to be, “No!”
I also assumed that there was a way to query launchd to find out the next time something running with StartInterval would trigger. I guess not (I am currently writing the time to a text file at the end of my script to verify run times).
Again, thank you very much,
Charlie -
AuthorPosts
- You must be logged in to reply to this topic.
Comments are closed