Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Run Anacron via launchd System 10.4
Tiger only hintI used to run Anacron on my laptop in 10.3, so that I could run the daily, weekly, and monthly maintenance tasks at appropriate intervals, but without having to have the laptop awake at any specific time. Anacron allows you to specify that specific tasks run every N days, and every time it runs, it checks each job to see if it's been long enough since the last run, and runs it if appropriate. This worked out quite well -- I had Anacron tasks set up to run the daily script every day, the weekly every seven days, and the monthly every 30 days. I had cron set to fire up Anacron every 15 minutes, and all was well.

Until 10.4, anyway. 10.4 introduced launchd, which replaces cron, and Apple no longer started cron as part of the boot process [Editor's aside: See the comments; cron is installed and running, but differently]. I had a lot of maintenance tasks that I was running with Anacron via cron, though. While it would have been easy enough to make an old-style StartupItem to launch cron, I wanted to do the right thing.

Anyway, after experimenting with plutil and launchctl a bit, I figured out how to get launchd to run Anacron every 15 minutes. It isn't all that complicated, if you're familiar with XML, but in the interest of sparing other people the hassle, I'm documenting it in my blog -- the details are also in the remainder of this hint...

Presuming you've used Fink to install Anacron, you can cause launchd to run Anacron every 15 minutes by creating a file called net.sourceforge.fink.anacron.plist in /Library/LaunchDaemons, with this content.

Once you've created the file, all you need to do is use launchctl to load it, by typing this in the Terminal:
sudo launchctl load /Library/LaunchDaemons/net.sourceforge.fink.anacron.plist
Or you can just reboot. To change the interval, change the 300 in the code snippet to whatever number of seconds you want launchd to wait between invocations. If you don't want it automatically running as soon as you boot up in addition to every 300 seconds, delete these two lines:
 <key>RunAtLoad</key>
 <true/>
If you didn't use Fink, change the /sw/sbin/anacron directory to the path where you installed anacron. Finally, if you get an error message when you try to load the file with launchctl, you can use plutil to check the syntax by typing plutil lint org.debian.anacron.plist -- if it isn't exactly correct, launchd will complain and refuse to load your job.
    •    
  • Currently 1.60 / 5
  You rated: 2 / 5 (5 votes cast)
 
[12,484 views]  

10.4: Run Anacron via launchd | 8 comments | Create New Account
Click here to return to the '10.4: Run Anacron via launchd' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Run Anacron via launchd
Authored by: rflo on May 19, '05 10:56:48AM

There is an easy-to-install package of Anacron for MacOS 10.4 at <http://www.18james.com/anacron-tiger.html>. It will update previous versions or install a new version as appropriate.

---
Ronald Florence



[ Reply to This | # ]
10.4: Run Anacron via launchd
Authored by: matamatangi on May 19, '05 11:16:20AM
Cron is indeed started at boot: cat /System/Library/LaunchDaemons/com.vix.cron.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.vix.cron</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/sbin/cron</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>WatchPaths</key>
        <array>
                <string>/etc/crontab</string>
        </array>
        <key>QueueDirectories</key>
        <array>
                <string>/var/cron/tabs</string>
        </array>
</dict>
</plist>
------ I believe the system cron *entries* may not survive the update, but those are easy enough to recreate. Plus, you really shouldn't add stuff to the system crontab, but rather to root's crontab (sudo crontab -e).

[ Reply to This | # ]
10.4: Run Anacron via launchd
Authored by: jpbjpbjpbjpb on May 19, '05 12:55:41PM

Yeah, there's a plist file for cron, but on my laptop, ps showed that cron wasn't actually getting loaded, or at least it wasn't running.

I installed as an upgrade, though, not a clean install, but that shouldn't have made a difference.



[ Reply to This | # ]
10.4: Run Anacron via launchd
Authored by: fungus on May 19, '05 04:18:10PM
Of course it isn't running. launchd is smart enough to only run it when there actually is a crontab for it to use. from launchd.plist(5) manpage:
WatchPaths
<array of strings>
This optional key causes the job to be started if any one of the listed paths are modified.
QueueDirectories
<array of strings>
Much like the WatchPaths option, this key will watch the paths for modi- fications. The difference being that the job will only be started if the path is a directory and the directory is not empty.


[ Reply to This | # ]
launchd does the job (at least it should)
Authored by: housemaister on May 20, '05 09:32:01AM

With Tiger Apple also changed the processing of the daily, weekly and monthly scripts. These scripts should be executed by the launchd after a restart (in the morning) if they weren't executed in the night. (so anacron or XJanitor wouldn't be needed anymore for these task)
Normaly it should also work if you put youre mac to sleep during the night, but this isn't done. I have the information that Apple Engineers are aware of this bug and working on it; but I'm not sure if it is implemented in the 10.4.1 Update; no confimation of this yet.
Btw, launchd is so smart and runs these script with a very low priority so that it doesen't disturb you while you are heavily using youre machine.



[ Reply to This | # ]
launchd does the job (at least it should)
Authored by: rocteur on May 21, '05 07:19:05AM

This is NOT the case on this Tiger 10.4.1

I've had the system for 2 weeks now and in /var/log, all I have is a daily.out from 5 days ago, no weekly.out ... There should be.

Is there something one must do to make launchd do this automatically ?



[ Reply to This | # ]
launchd does the job (at least it should)
Authored by: rocteur on May 21, '05 07:27:46AM

man launchd.conf

So it looks like you have to set up a launchd.conf I'll check it out.

BTW, what a stupid man page, it does not give the format of the file ???

man launchd.conf
launchd.conf(5) BSD File Formats Manual launchd.conf(5)

NAME
launchd.conf -- launchd configuration file

SYNOPSIS
$HOME/.launchd.conf
/etc/launchd.conf

DESCRIPTION
launchd.conf contains a list of subcommands to run via launchctl when
launchd starts.

FILES
$HOME/.launchd.conf Your launchd configuration file.
/etc/launchd.conf The system's launchd configuration file.

SEE ALSO
launchctl(1), launchd(8), launchd.plist(5)

Darwin January 10, 2005 Darwin



[ Reply to This | # ]
10.4: no launchd.conf
Authored by: chueewowee on Oct 31, '06 06:12:17AM

i get info from man launchd.conf, stating in SYNOPSIS that it resides:$Home/.launchd.conf
/etc/launchd.conf


however i have no such files there in fact.
I want to stop LaunchD crashing at start up. I deleted .DS_Store in System/Library/Launchdaemons and in /var/cron/tabs/
yet to see if it helps.

perhaps you have a suggestion. in any case what is the meaning of no launchd.conf file? should i just create an empty file ?



[ Reply to This | # ]