A revised launchd plist for fetchmail

It turns out that my previous plist for launching fetchmail doesn’t work so well after updating to OS X 10.4.2.

When there is no mail to collect fetchmail races through checking my mail accounts in less than sixty seconds, triggering a series of errors:

launchd: nepenthes.Fetchmail: exited with exit code: 1
launchd: nepenthes.Fetchmail: 8 more failures without living at least 60 seconds will cause job removal

and so on until:

launchd: nepenthes.Fetchmail: exited with exit code: 1
launchd: nepenthes.Fetchmail: too many failures in succession

At which point launchd stops running fetchmail. (Fetchmail’s exit code one means “There was no mail awaiting retrieval”.) So I returned to having launchd start fetchmail once in daemon mode, and used “set daemon” in my .fetchmailrc to specify the mail checking interval, using this 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>GroupName</key>
	<string>wheel</string>
	<key>Label</key>
	<string>nepenthes.Fetchmail</string>
	<key>OnDemand</key>
	<false/>
	<key>Program</key>
	<string>/usr/bin/fetchmail</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/bin/fetchmail</string>
		<string>-a</string>
		<string>-D</string>
		<string>nepenthes.dev</string>
		<string>-f</string>
		<string>/var/root/.fetchmailrc</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>UserName</key>
	<string>root</string>
</dict>
</plist>

File attached if you’d like to Download

There is a problem with this however - due to launchd’s asynchronous launch of processes at boot time fetchmail will often start trying to retrieve mail before postfix and thus the local smtp service is available to receive them. As long as you’re using fetchmail’s default mailbox check behavior and not the “–flush” option or its shorthand equivalent “-F”, then this will only result in an error message and the mail will be retrieved on the next check.

None the less, I’ve submitted a bug to Apple’s bug tracker as requested by the very helpful launchd creator Dave Zarzycki.