Belated Praise for Launchd
This is way behind the times, but I recently had to automate a task on Mac OS X, and decided to deploy it using launchd
instead of cron
. I expected to find it an XML-enabled cron
clone, or worse. I was happily very wrong.
The Good
The first surprise was a set of relatively good man pages. They don't contain every single detail, but some experimentation and some stack exchange got the job done.
Launchd
improves on cron
for deployment: one file per job is an improvement over the crontab
. I have implemented a similar system over cron
before, where you drop individual crontab
-formatted files into a directory, and they're all picked up and added into the user's crontab
file. It's nice to get that for free with launchd
.
Apple also implemented far more event triggers than cron
, which only implements a clock. Launchd
replaces crond
, inetd
, and most importantly to me, filesystem event triggers.
There are also configuration elements for a few practices that were commonly done in code. For example, stdout
and stderr
redirection to a file, so you don't have to do that sort of magic in your program. You can configure the working directory or chroot
of your program instead of being dumped into /
, which is nice. And, if it's running under the system, you can configure the user and group that the program should use.
All this means that one can write a very simple bash script instead of a cron-specific, boilerplate-filled mess. It's easy to make it so the script can be run interactively when needed, without adding too many options.
The Bad
Mac OS X's default configuration file format is the plist. It's XML and it takes a good long time to say anything. I'm not crazy about it, compared with formats that are friendlier to type. Grudgingly I'll admit it's not too painful to use XCode to make them, since you don't have to remember the boilerplate or schema.
The Ugly?
I don't have enough experience yet with it to have anything ugly to report. It's quite possible I'll never get enough experience with it, as I expect to write more code for servers than clients, and I historically have preferred non-Darwin unixes for server duties.
But I can say that I will miss some of the flexibility of launchd
the next time I find myself using cron
to schedule a job when I really want a filesystem-based trigger.