Geek

What the Hell Is Up With MacOS Periodic Jobs?

Yesterday, Feb. 25 at 13:19, my Mac ran periodic monthly. I thought it odd that this would run on the 25th rather than the 1st of the month, and in the afternoon rather than late at night, so I dug a little deeper.

It looks as though Apple now deprecates cron in favor of launchd agents. Okay, fine. Yeah, I see that there are three periodic jobs:

> launchctl list | grep periodic-
-	-9	com.apple.periodic-monthly
13804	0	com.apple.periodic-weekly
-	-9	com.apple.periodic-daily

launchctl print system/com.apple.periodic-monthly shows details about the monthly job:

event triggers = {
        com.apple.periodic-monthly => {
                keepalive = 0
                service = com.apple.periodic-monthly
                ...
                descriptor = {
                        "Repeating" => true
                        "GracePeriod" => 14400
                        "Interval" => 2629746
                        ...

Nowhere does it say to run this job at a particular time on a particular day. Rather, as far as I can tell, it wants to run every 2629746 seconds. What’s that?

launchctl print system/com.apple.periodic-daily shows

"Interval" => 86400

which makes perfect sense, since 86400 is 60 × 60 × 24, the number of seconds in a day. And com.apple.periodic-weekly runs every 60 × 60 × 24 × 7 = 604800 seconds.

But 2629746, the monthly interval, is 43829.1 minutes = 730.485 hours = 30.4368 days. What the hell is that?

I note that the average month length in a year is 365/12 = 30.4166 days, which is close. And what with leap years, the average year is really 365.25 days long; 365.25/12 = 30.4375, which is close to the periodic-monthly interval. So maybe Apple took the length of the average century, when all leap days, century non-leap days, and millennial non-non-leap days are taken into account, and divided by the number of months in a century? Or something else? Who knows?

Maybe Apple has decided that it doesn’t matter when accounting and log-rotation jobs run, and that it’s okay for them to drift. Fine. Except that the simplest and easiest documented way of adding your own periodic jobs is to add a file to /etc/periodic/daily, /etc/periodic/weekly, or /etc/periodic/monthly. And people might want resource-intensive cleanup jobs to run in the middle of the night, and for reports to run on the first of the month. So what the hell, Apple?