Slashdot Mirror


Does launchd Beat cron?

Blamemyparents writes "For those who aren't Appleheads, you may not have heard that with Tiger, Apple swapped out old Unix standby cron for their own creation, launchd (Apple mentions it on their OS X page and has the man page for it up as well). Seems like it's a bit nerdy, but this changes a LOT about how *nix systems have done things for many years. Launchd is Apple's replacement for quite a few utilities, including launching and quitting quite a few different things, and getting info from the system and other running processes. This page from Ars Technica talks a bit more in depth about it. Apple has open sourced the thing, and is apparently hoping all the unix kids will take a look."

16 of 798 comments (clear)

  1. Re:Not a cron replacement, a init replacement by akac · · Score: 4, Insightful

    Because everything in OS X uses XML configs. A dang site better than Windows Registry or the thousands of permutations that Linux uses.

  2. Re:Not a cron replacement, a init replacement by Anonymous Coward · · Score: 5, Insightful

    No, you don't get it. Why in hell would you want to write yet another config file parser and use your own awkward config format when you could use standard XML and that very same parser that's already loaded to system RAM as a shared lib?

  3. Re:Not a cron replacement, a init replacement by Senjutsu · · Score: 5, Insightful

    I'm not sure Apple Gets It though. Why in the world would they use XML configs?

    To make it easy to edit the files both by hand and via utilities which can be written very easily by leveraging existing XML parsing libraries?

  4. As long as it doesn't break the fundamentals... by yorick · · Score: 5, Insightful

    Apple is doing a good thing here is shaking up the administrative and setup side of the UNIX world. Most of their work was actually NeXT's, but their "Application as directory" concept is wonderful in a lot of ways, and their reorganizing of the filesystem so that it makes more sense to users is probably a good move in the long run.

    What makes UNIX superior for management and power-users is the ability to do everything you need to from command-line tools and options, and the fact that the storage for configuration is in understandable, alterable files. If those are still there...if I can still run my Apple from the shell--I'm a happy man.

    The only exception to this would be cases where a vendor deliberately makes a deviation simply to introduce incompatibilities. I don't see that as the case here.

  5. Re:Ahh yes. by Cid+Highwind · · Score: 5, Insightful

    You move away from human readability/editability and into the realm where only a machine can fathom the format.

    You're looking at this from the perspective of someone who understands and remembers the differences in a dozen config file formats. Most people don't.

    Do comments in my .whateverrc start with a hash mark? A semicolon? A double slash? C-style /* ... */ delimiters? XML-style ? Are you even allowed to have comments? Can you use nested parentheses? Are angle brackets a symbol for redirecting i/o or do they delimit XML tags? Does a pipe chain the output of cone command to the input of another, or is it a logical or operator? Replacing that mess with a single standard format will make things *more* human readable IMHO, and it will certainly make it easier to have a single integrated pointy-clicky interface for changing all those configuration options.

    --
    0 1 - just my two bits
  6. Re:Not a cron replacement, a init replacement by GamblerZG · · Score: 4, Insightful

    For once I agree. XML is _ideal_ for configs. In fact, it is more suited for configs than for many other fields in which it's actively used. The key things are it's flexibility and human-editability.

  7. XML? by Anonymous Coward · · Score: 4, Insightful

    We do need a replacement for our boot process. Boot GNU/Linux systems is slow. We want processes to be able to start concurrently, or in some cases, with specified pauses. If non-essentials (print server, etc.) start a few seconds after the log-in screen appears, I can be functional faster. We don't have a good system in place now.

    We need a replacement. launchd isn't it. The problem, fundamentally, is XML. XML is a problem since, fundamentally, it is very flexible formatting, and so doesn't play nice with shell scripts. You can't easily cut/sed/etc. xml files. Until we get a suite of replacement tools that can easily modify XML files from shell scripts, XML won't cut it.

    One of the key things to a good system is to make easy, common things fast and easy. The minimal overhead for any program that modifies an XML file is way, way, way to large to want to use it as the standard system format.

    1. Re:XML? by jonabbey · · Score: 4, Insightful

      Python and Perl have perfectly robust XML i/o libraries these days. I don't think I'd mind very much writing the extra ten lines of Python code required to interface with XML, particularly if the transformation I want to do to the config file is simpler in terms of XML than it would be in terms of sed, etc.

  8. Re:Less Compatible? by revscat · · Score: 5, Insightful

    Isn't half the attraction to OS X for geeks how its not that much different from Linux or BSD from the console?

    I'm sure some do. But in the aggregate most users will balance something like this against the benefits gained. There are those who are also experimental enough who will try this, and if they find it to be a better implementation will then port it over to other *nix variants, leading to a new "standard".

    rc.d, cron, etc. may be the way other unices do things right now, but that in and of itself is not justification enough to be married to such mechanisms in perpetuity. Sometimes it's beneficial to *cough* you know, "think different."

  9. Submitter is NOT confused by jamezilla · · Score: 4, Insightful
    From the launchd.plist man page:
    A daemon or agent launched by launchd SHOULD:
    oo Launch on demand given criteria specified in the XML property list.
    What does cron do? Launch programs! Clearly this means that launchd can be used to replace cron.

    Not only that but looking at the rest of the plist syntax reveals that this thing is waaay cooler than cron. It allows you to set user, group, chroot, check dependencies, designate where to send input and output, set resource limits and whole crapload of other things. Sure you can do this all from within a script, but this thing gives you all that for free.

  10. Re:Not a cron replacement, a init replacement by synx · · Score: 4, Insightful

    "Design by committee" is not a way towards excellence. Excellence often comes in small doses and grows from there.

    Let me give you an example from my work. I designed an software monitoring system which read values from our Oracle databases, put the values into RRD files and had a flexible configuration that allowed me to quickly create new sites as copies of other sites. Also I added dependencies and suppression, etc. I designed it to _MY_ specs, what _I_ wanted. But I wrote it in a flexible manner. It's now being used by over 200 people and stands a fair chance at company wide adoption. Not because I asked what people wanted, but because I chose a good solution (not the mythical "best" solution) which worked for me (I had a complex use case fortunately), and made it easily extendable. Now people are feeding data into the system from almost everywhere, and the whole system was rearchitected from a cron job to a continiously running set of daemons. Because of the modular nature of my design it allowed for this redesign easily.

    So I think what Apple did rules. They didn't ask requirements from anyone, they had a flash of inspiration, created something awesome that works good for them, and then said 'hey, if you want to use this, go ahead!'

    Apple never considered asking other Unices because they wanted something that worked, and also wanted to deliver too.

  11. Re:Submitter is confused by As+Seen+On+TV · · Score: 4, Insightful

    I think, to the contrary, we've greatly simplified Mac OS X. When it comes to programs that run without being explicitly started by the user, there used to be six or eight ways to skin the cat, many of which overlapped to a greater or lesser extent. Now there's one.

  12. Re:Submitter is confused by MalachiConstant · · Score: 4, Insightful
    You know, I've read many of your posts and even if you are an actual employee of Apple you say "we" way too often. Unless you're Steve Jobs I find it hard to believe you're personally involved in all the projects you've insinuated yourself into.

    We're all very impressed if you work for Apple, but the chest-thumping is getting a little tiresome.

  13. Re:Not a cron replacement, a init replacement by NoMaster · · Score: 4, Insightful
    XML sucks for anything that humans might want to edit
    However, it's pretty damned good for the times where you want a machine to parse your config files and present them in a nice GUI format.

    Which is exactly what Apple - and the average user - wants. Hell, it's also exactly what you want for your X apps, and what you want for those 90% of times when you're configuring non-graphics apps and services through X, a web interface, or even a command-line configuration app.

    The only time it falls down is when editing configuration files manually - and even then, it's still parsable by the human brain.

    Now, I'm no XML fanboy. But honestly, when was the last time you edited anything more than the most trivial .ini or .cfg file by hand? Your MTA? Apache? Samba? BIND? Crontab? Inetd? Initd? IPFW/PF? If you're like me, you did it by hand-editing the first few times so you knew what was going on; since then you've used Webmin or Gnome/KDE's control-panel-like apps.
    --
    What part of "a well regulated militia" do you not understand?
  14. Re:XML plist configs are easy by cakoose · · Score: 5, Insightful
    If you can't figure out an xml plist config, then you are not smart enough to be in the shell.

    1. It's not about figuring it out. Just because you can figure something out doesn't make it optimal or even non-crap.

    You scared people clearly don't understand plist files and how they represent records and lists.

    2. The grandparent post was talking about XML in general and how it's great for configuration data. That is what I was taking issue with. You can build record/list support on top of XML, but it doesn't fit in naturally.

    3. I still think the property list XML format is crap. Property lists are decent; they're not perfect, but their extreme simplicity makes them very useful. The ASCII format is great, so why would you want an XML format?

    Does having an XML format lets you leverage XML tools? It might have if property list XML worked with XML instead of simply beating it into submission. Apple created a completely opaque layer on top of XML instead of integrating directly.

    {
    Dogs = (
    . {
    . . Name = "Scooby Doo"
    . . Age = 43
    . . Colors = (Brown, Black)
    . }
    )
    }
    A natural XML equivalent would be a little more verbose:
    <Config>
    <Dogs>
    . <Dog>
    . . <Name>Scooby Doo</Name>
    . . <Age>43</Age>
    . . <Colors>
    . . . <Color>Black</Color>
    . . . <Color>Brown</Color>
    . . </Colors>
    . </Dog>
    </Dogs>
    </Config>
    Using Apple's XML format, you'll get:
    <dict>
    <key>Dogs</key>
    <array>
    . <dict>
    . . <key>Name</key>
    . . <string>Scooby Doo</string>
    . . <key>Age</key>
    . . <integer>43</integer>
    . . <key>Colors</key>
    . . <array>
    . . . <string>Brown</string>
    . . . <string>Black</string>
    . . </array>
    . </dict>
    </array>
    </dict>

    The result: something that's more verbose and harder to read than even a natural XML format.

    What's worse is that you can't leverage DTD/Schema as much as you could with a natural XML format.

    • You can't validate semantic structure. (You can ensure that the file is a valid property list XML file, but you can't make sure that it contains launchd configuration info).
    • DTD/Schema sensitive editors still wont help you out with semantic structure. It can auto-complete "key", "dict", etc. but it can't auto complete "Name", "Age", or "Color".
  15. Re:Submitter is confused by JQuick · · Score: 4, Insightful

    However, the question is are we losing simplicity for features?

    Good question.

    Let's look at it. When are programs run? The simplest answer is "when they need to."

    No, I'm not being snide, merely rhetorical. When do programs need to run?

    Programs need to run for a variety of reasons. Some need to to run when the machine is booted. Others need to run at particular times. Some, like certain network server processes are needed only when a user or another program requests service (e.g. accept connections on protocol/port). Others are spool oriented programs where files in a queue directory need to be processed when present but have no work to do when the queue is empty.

    So rc scripts run programs at boot time which either do some work and die or act as standalone servers which are intended to live forever (or until they are explicitly told to stop).
    init runs programs (like getty processes) which are long lived and are respawned when they die.
    inetd/xinetd listens for connection attempts to network ports and spawns server processes on ports.
    cron runs programs based on a schedule, the passage across a point in time triggers execution.

    launchd provides a superset of the above triggers for spawning programs.

    Think of it as
    Run Program [ProgramArgs] [ TemporalTrigger | ServiceRequiredTrigger ]

    By default, the simplest launchd file says "Run this program now just once.". It is thus a simple rc script which, at boot time, runs something and at shutdown time can be told to stop. Adding a further key/value pair can say "restart on exit," thus replacing inittab/init based functionality. Specifying a family/protocol/port says listen and start me when needed to serve a network request al a inet. Adding a qualifier to this type of socket definition says connect() to an address, instead of the more typical bind()/listen()/accept(). Specifying time based activation covers cron functionality, if you need at functionality specify the environment variable and working directory as well. To enable spool-like behavior or programs tied to arbitrary file system activity watch a file or directory for changes.

    Most Unix subsytems only support system level operation. launchd distinguishes whether a process description is system wide or based on user login simply by where the file is found. A launchd plist file found in a LaunchDaemons directory will be loaded on system startup. One found in a LaunchAgents directory will load when a user logs in, and unload on logout. The syntax of the file will be identical in either case.

    So, the launchd plist files (short for property lists) contain a set of key/value pairs describing what to run, and when to run it. Beyond this, launchd defines keys which tailor how the program is run, all of which are optional. These include specifying: user and group by either name or uig/gid; working directory, chroot directory, a dictionary of environment variables, CPU niceness, umask. Do you want to limit how much memory or stack it uses, prevent it from wiring system memory? Do you want limit the number of children it can spawn, or treat its IO requests as low priority as urgent? Keys are available for that.

    So is this simpler or more complex? In the big picture I believe that this simplifies things tremendously. Launchd defines a tiny language for specifying how and when to run processes. It covers all the traditional triggers of init, rc files, cron, and inetd. It specifies the environmental and security issues of su/sudo, chroot, ulimit, umask, nice and at. It covers both system level startup/shutdown as well as user level login/logout.

    Because of well chosen defaults, most launchd input files will be very short and to the point, only specifying the direct functionality they need. Adding just a few more key/value pairs can obviate the need for the majority of moderately complex rc and daemon startup files. Since launchd also obviates the need to daemonize, close files descriptors, fo