launchd Caveats: StartCalendarInterval and Sleeping

After a couple hours of testing, and searching on Google I’ve come to the realization (and subsequent confirmation) that the reason my launchd periodic task doesn’t always run on time (but sometimes hours late) is that the process is tied to a timer and not a specific time of the day like you specify in the plist.

So if your computer is asleep for 3 hours, the process will run 3 hours later unless you restart your computer which will fix the timer issue, until the next time you sleep.

I really hope this is fixed in Leopard, and have subsequently filed a bug report. (Radar 5091911 - link will only work for Apple employees)

So in summary, don’t depend on StartCalendarInterval to run your launchd process at the time you’ve said unless you know the computer has restarted since the last time it was put to sleep.

Note: This was fixed in Leopard. Unsure if it was fixed in 10.4.11 as I don’t use Tiger anymore.

launchd : cron with less suck?

So while figuring out launchd I came across the revelation that launchd will run any tasks it is given at it’s prescribed time, or the next time available (eg. the computer is asleep or turned off). I now remember hearing that when 10.4 Tiger was first released but had completely forgot it. Since Apple has the periodic tasks running in launchd instead of cron in Tiger, this makes the often touted reason to run Onyx moot and useless.

The system runs the scripts when it can (when it’s supposed to, or when you turn your computer on next), and doesn’t just “not run them” as cron would.

Running the periodic scripts sounds just as helpful as “Repairing Permissions” now, but I may be underestimating the value of the placebo effect.

Source: man launchd.plist

  StartCalendarInterval <dictionary of integers>
  
  This optional key causes the job to be started every calendar interval as
  specified. Missing arguments are considered to be wildcard. The semantics are much
  like crontab(5).  
  Unlike cron which skips job invocations when the computer is asleep, launchd will start the job the next time the computer wakes up.   
  If multiple intervals transpire before the computer is woken, those events will be
  coalesced into one event upon wake from sleep.

So for replacing cron? launchd kicks ass. I’m disappointed it took me until 10.4.9’s release for me to truly start finding out the power of launchd.

Carnarvon Lake

Note: Pictures so far are only on Flickr: Carnarvon Lake Set

Having never been backpacking before I wasn’t sure what to expect when invited for a backpacking trip up to Carnarvon Lake[1] at the Southern tip of Kanasakis Country.

Three friends, my brother and I left Calgary around 7:30 AM so we could start our 10K hike in by 10:00 AM or so. Having arrived fine at our parking spot on Cat creek we unloaded and began our hike that would see roughly 500 metres in elevation gain, most in the last 300 metres or so.

The hike itself includes 3 creek crossing (one mid thigh, one mid calf and one mid toe.[2]), so a good pair of sandals was recommended. Unfortunately mine sucked and while extremely useful for the crossing caused me to develop 3 blisters on each foot pretty quickly. The joys of being a city boy not used to travelling on cow trails and logging trails.[3]

Your first 9 kilometres or so yield some good rolling terrain with a general uphill feel giving good vantage points and a good view as you go around one of the foothills to get to the headwall. The headwall is broken into two sections, with the first section allowing you to follow a couple hundred metre path or do what those who don’t know about the path; scramble up the scree about 100m.

The scramble up the scree took us an hour and wasn’t fun as you went from safe spot to safe spot trying to stick to any vegetation available. Once we got up to the path it was apparent that the path would have shaved off 50 minutes and saved several litres of sweat from each person. It should be noted that not being protected the wind had picked up and was appreciable keeping the beating sun from overheating us.

From there we made our way up the path to the second section where chains have been attached to the rocks to make the scramble up a heck of a lot easier. It’s possible without the chains, but the chains offer some safety and give you a path to follow. Another 15 minutes climbing rocks we hit the top of the headwall.

At this point, I was exhausted and just happy to be at the top so I could get some water and some respite from the climb. Coming over the headwall we faced a hundred kilometre or so wind battering us as the wind came through the 3 valleys behind the lake, across the lake and down into the valley below. Another 15 minute hike around the lake brought us to where we would make camp, on the lee side of a ridge reducing the wind considerably.

From there after shedding all our gear and setting up the tents we were able to head to the lake and relax. All in all the 10k hike had taken us about 6 hours, longer then expected largely to the unexpected hour long scramble up the scree. My friend Earl (who was leading us) was right however. The 6 hour hike was definitely worth the view, bot at the headwall and the ridge above the lake which a couple of steps from that was the continental divide and British Columbia.

After getting a few pictures of Mount Armstrong from the ridge we headed back down to get some food (reheat some pasta) and get some sleep.

It’s been a really long time since I’ve seen stars that bright, but my biggest regret was being as tired as I was, I didn’t see much.

The following morning we immediately headed to the headwall to get some shots of the valley below before the cloud cover burned off and the sun rose any higher in the sky. (8:30 AM) Afterwards which we headed back to camp to get some light breakfast ready (jerky and cereal bars). For the next few hours (until 1) we then hiked into BC getting several shots of the Purcells, and heading up one of the mountains checking for an unnamed lake further up.

Coming down was much easier then coming up, although the wind was going roughly a hundred again, and giving the lake some really nice looking whitecaps. It only took about 4 and a half hours to get down and back to the car, and in all we saw a total of 11 people or so going up and back down. (A group of three on horseback passed us on the trail to go fishing on the way up, a group of two were there when we arrived fishing, the conservation officer who was using a bike to do the trail, and a group of two we saw on Sunday who hiked up as we were leaving for BC, and hiked down while we ate lunch.)

Would I do it again? Yes, but I can’t do it every weekend. I’m just not cut out for it. Yet? Was it a lot of fun? Yes. If you’re looking for something a wee bit challenging and know about doing backcountry backpacking it’s definitely a place to visit.

Just take a look at the pictures on Flickr for a more visual idea.

1 - It’s on a trail off the Cat Creek trailhead. (Google Maps Link)
2 - Obviously this would be higher if it wasn’t done in late July.
3 - No excuses. I wasn’t as fit as I thought, but I did it fine.