mac.column.ted: Customizing System-level Startup
by Ted Landau
Show of hands...how many of you have heard of Startup Items in Mac OS X? No, I am not talking about the list of items (that used to be called Login Items) that appear in the Startup Items tab in the Accounts System Preferences pane. I am talking about the "true" Startup Items -- the ones that reside in the StartupItems folder in the /System/Library directory. These items -- part of the standard installation of Mac OS X -- run each time you restart your computer, even before you log in to your account. They are responsible for launching an assortment of critical Mac OS X services, especially those related to networking and sharing. An additional StartupItems folder may be found in the /Library directory. This one is available to third-party software (or to you, should you care to create your own startup item) to similarly initiate an action that will run at startup regardless of which user logs in.This article is not about these Startup Items. I only mention them to tell you that, starting with Panther, Apple has moved to abandon these Items. That's right, Apple will likely no longer be using Startup Items in the next version of Mac OS X. Their replacement is already in place and in limited use in Panther. They are called Bootstrap Daemons. This column, which is admittedly a bit more technical than my previous columns, provides an overview of what these daemons are and how you can easily create one yourself.
Bootstrap daemons Bootstrap Daemons get launched at two different points in the startup sequence:
- The first time is relatively early in the startup sequence, around the same time that Startup Items are run. The daemons that are loaded at this point are stored in the following Unix directory: /etc/mach_init.d. The daemons stored here include ones for starting up Unix's configd and lookupd services. (If you don't know what these are, don't worry; you don't need to know to follow along here.)
- A second set of daemons are run when the loginwindow application is run. That is, they are run just after you enter your name and password to log in to your account. (If you are set to automatically log in, these daemons run at the same post-login point even though you never manually enter your name and password.) These secondary daemons can be found at this location: /etc/mach_init_per_user.d. In a default Panther system, the only daemon in the this directory is MirrorAgent.plist (which is used to manage the local copy of an iDisk, if present).
ServiceName. The value of this key is the name of the bootstrap service. The name typically follows the name format used by preferences files in your ~/Library/Preferences folder. For example, the ServiceName value for the WindowServer.plist daemon is com.apple.windowserver. For a daemon you create yourself, the name can usually be whatever you want (in fact, you can leave out this property altogether). Command. The value of this key is the absolute pathway to the executable file that runs when the daemon loads. For Apple's pre-installed daemons, most of the executables are either in Unix directories (for example, the configd and lookupd executables are in /usr/bin) or in /System/Library/Frameworks/ApplicationServices.framework (this is where windowserver is located). For the daemon we create here, it will be where the Preview executable is located. OnDemand. This is an optional key. By default, OnDemand is set to on. However, if this key is added and set to a Boolean value of False (or No), the on-demand feature of the daemon is disabled. OnDemand refers to a major advantage of Bootstrap Daemons over the older Startup Items: Daemons can launch on demand -- that is, a loaded process can "sleep" when not needed, significantly reducing its effect on system load and thus reducing performance slow-downs.
- Launch Property List Editor and click the New Root button.
- Click the disclosure triangle next to the newly create Root property.
- Click the New Child button.
- Change the name "New Item" to "Command". Leave the Class as "String".
- For the Value, enter the following: "/Applications/Preview.app/Contents/MacOS/Preview".
- Save the file to your Desktop. The name of the file, aside from the .plist extension, is not critical. I chose "launchpreview.plist".
- Choose Go to Folder from the Finder's Go menu. Type "/etc/mach_init_per_user.d" and press Return.
- Drag the launchpreview.plist file to the folder window. When the Authentication dialog appears, enter your password.
System-level loginwindow.plist. As is often the case in Mac OS X, there is more than one way to accomplish a goal. In this case, if you prefer not to work with bootstrap daemons, you can get an application to launch at login for all users by adding the application to the loginwindow.plist file in the /Library/Preferences folder (creating this folder and/or file, if they do not already exist). Glossing over the specific steps involved, this file follows the same format as the loginwindow.plist file in the Library/Preferences folder in your Home directory (which is where the items in your personal Startup Items list are stored). In particular, check out the numerical children of the AutoLaunchedApplicationDictionary property for the file to see how to set up your own file. You can leave off the alias property in the items you create; it will still work.![]()
Figure 1: The contents of two bootstrap daemon files: (a) configd.plist and (b) launchpreview.plist (which I created).
Bottom line. Each method (bootstrap daemons and loginwindow.plist) has its own pluses and minuses. I like that each bootstrap daemon is a separate file and that its action occurs prior to the desktop and Dock loading. However, your personal daemons are stored in Unix directories and could get wiped out in an upgrade to Mac OS X -- so maintain backups! In either case, if your Mac has multiple users, and you've been wishing for a simple way to customize the login for all accounts, you wish has now been granted.![]()
Figure 2: A loginwindow.plist file that, when placed in /Library/Preferences, will launch Preview at login for all users.
Tip of the month: Deciding on digital camera batteries
I recently bought a new digital (still picture) camera. In researching which camera to purchase, one issue that frequently came up was the type of battery. Some cameras use standard AA batteries while others use a proprietary rechargeable battery. The typical advice is, all other things being equal (which they never are, of course), to give a preference to cameras that use AA batteries. The logic is that these batteries are cheaper than the propriety batteries and more readily available. In a pinch, should the batteries you are using run out of power, you can buy AA batteries virtually anywhere. In my opinion, this advice is wrong. I prefer the proprietary batteries. Here's why: I looked at a Canon A80 which is a very small camera that runs on 4 AA batteries. These batteries add significant weight to the camera, already one disadvantage. Second, standard AA batteries don't last for more than a few snapshots (not to mention that it can be expensive to have to keep purchasing new batteries). So the first thing you should do after getting this camera is purchase 8 rechargeable AA batteries and a recharger. Four batteries go in the camera and 4 remain as a quick replacement (adding still more weight to lug around). The cost of these batteries and charger is not trivial. Figure at least $50 (and possibly more, especially if you want the batteries that recharge in 15 minutes). In contrast, I looked at an Olympus camera that uses a proprietary LiOn battery. The battery is much smaller and lighter than 4 AA batteries. The camera comes standard with an external charger, so you don't need to purchase one separately. Finally, the cost of a second back-up battery is less than what I would have spent on 8 rechargeable AA batteries and a recharger. The one remaining potential advantage of the AA batteries is their availability. However, my previous digital camera ran on AA batteries and, using rechargeables, I never once found myself in a position where I needed to run out and get batteries at a drug store. It could happen, but I wouldn't let this affect my decision as to which camera to get. Note: This article is adapted from my just-released new book: Ted Landau's Mac OS X Help Line (Peachpit, 2004). For more details on the material in this article -- plus the scoop on hundreds of other Mac OS X troubleshooting-related topics -- get the book. This is the latest in a series of monthly mac.column.ted articles by Ted Landau. To see a list of previous columns, click here. To send comments regarding this column directly to Ted, click here.Resources


---
psr
hurts. Wonder if Apple will ever get around to re-implementing shutdown/
logout items without having to go through the process of setting up logout
hooks manually.
As far as the battery argument goes. I agree with your decision for the
specific case you mention, but I have a Panasonic DMC-LC43 4 megapixel
camera. It runs off of rechargeable AA batteries, but it only needs 2, not 4
(which I can definitely see being excessive). On top of that, it came with a
charger for AA batteries included. All I had to do when I got it was go out
and by a set of 4 extra rechargeable AA batteries, which fit nicely in the
camera case I use. I've also found that battery life is acceptable, as long as
you remember to recharge the batteries before taking it anywhere that I'm
gonna be using it extensively. Besides that, I've had no problems?so I'm
inclined to think that this may be better decided on a camera by camera basis
(as your "they never are" [equal] statement implies). Just my 2¢.
Great article. Learn something new here at least a few times a week.
BootStrap daemnos... and logout hooks. Hm... I thought that only happened
during the Folsom Street Fair in San Francisco!
cameras. Yes, the weight factor is one to consider but
the cost factor IS indeed trivial. You can buy a charger
with 4 NiMH batteries at Wall-Mart for around $10.
I also disagree with Ted's preference for proprietary batteries over standard
AAs. He's right about the weight (in most cases), but in several other ways
AAs are superior:
- Availability: I <em>have</em> run out of juice on both sets of my
rechargeables a handful of times (usually while travelling where charging was
challenging), and I was always able to find standard AAs for temporary use.
- Cost: Even a camera with a proprietary battery needs to have a backup
battery. Because it's proprietary, it's going to cost far more than 2 or 4 AAs.
Once you have a AA charger (which I imagine almost all of us techie types
have) you don't need to buy it again, and you can use it for more than your
camera.
- Replacement: With proprietary batteries, you're at the whim of the
manufacturer (and third-party battery companies) about whether or not they
will continue to provide replacement batteries. I've been burned with too
many devices that have proprietary batteries that go out of style, rendering
the device useless before it should be. (This is the most compelling argument
for me.)
Thanks for pointing out the bootstrap daemon process -- your main point! A
clear presentation as usual.
For what it's worth, I happen to agree with Ted regarding proprietary batteries
;-) Our Canon PowerShot S400 would be significantly larger if it had to use
AA batteries. On top of that, an extra "proprietary" battery can be purchased
for $8.99 from third-party vendors. So two extra batteries amount to less
than $20, and the charger and two extra batteries together are about the size
of an 8-pack of AAs and last many, many times longer. As long as I can
access an AC outlet every two or three days I'm fine, and my camera is tiny
enough that I actually take it with me rather than leaving it at home because
it's too bulky.
<p>
But, of course, everyone has their own preferences. What works for me may
not work for everyone :-)<p>---<br>Dan<br />
MacFixIt Editor
My dad has a Canon S100, which is about the same size and weight as the S400. I use a Casio QR-V40, which is also darn close to the same size. His camera uses Canon batteries, which cost a lot, and in his experience (three batteries by now), have a very modest camera life. My Casio, which uses 2 AA batteries, lasts as long or longer on cheaper, more versatile batteries in the same size and shape.
Clearly this is a decision that varies from user to user, and camera to camera, but I think it's inaccuarte to say AA usage forces a much larger form factor.
Ran
I'll agree with Ted on this one for a reason that nobody has yet
mentioned: NiMH AA batteries inherently self-discharge, while proprietary
batteries (at least the LiIon ones) do not. NiMH batteries will eventually
run down by themselves, requiring a recharge, whether you use them or
not. Better hope that is not when you really want to take a picture.
My Minolta Dimage Xt uses a very small proprietary LiIon battery (about
3cm x 5cm x 0.5 cm). I was concerned about battery life at first, but
found that for my family's usage pattern (taking a few pictures here and
there over a period of weeks), this battery was perfect. I recharge every
month or so and carry a spare battery in the (also very small) camera
case. You can stick the whole works in a jeans pocket.
the programs are launched. This is necessary because some programs
require certain services (network, drives...) and need to launch later in the
process. And other's have dependencies on prior services. Is there any
allowance for this in the Bootstrap plist files?
WRT batteries. I prefer AA for two reasons. One, I only need to carry a single
charger with me for all of my devices--and they can share backup batteries.
Two, I keep an emergency set of Lithium AA's, which are expensive, but
extremely light. Should I run out of rechargables, I can always use those. If
you do go with AA, forget alkaline--they don't last at all in digital cameras.
Get the NiMH batteries with the highest mAh rating you can find. Last I
checked that was around 2100.
Re: And other's have dependencies on prior services. Is there any
allowance for this in the Bootstrap plist files?
Good question. As far as I know, this ability is missing in bootstrap daemons.
There seems to be no way to specify the load order of daemons.
- Ted
> Re: And other's have dependencies on prior services. Is there any
> allowance for this in the Bootstrap plist files?
Sequencing is, theoretically, not necessary. The mach_init daemon, will
launch any necessary dameons IT KNOWS ABOUT on demand.
The initial call in rc registers all of the known bootstrap daemons' services.
From then on, any call on that service will launch the appropriate daemon.
---
William H. Magill
Ick.
I prefer StartupItems anyhow, since with all the hassle about registering
services (my firewall script, ntpd, apache2, etc) it seems like it's more trouble
than it's worth.
Or I could just hack rc, which is more tempting..
Panther first came out. However, one thing that I like about StartupItems
which has prevented me from migrating to the daemons is the ability to start/
stop StartupItems from the command line via SystemStarter. For example, I
can issue sudo SystemStarter stop Resin when I want to stop my app server of
choice (which happens to be Resin). Similarly, I can sudo SystemStarter stop
"Web Server" and that will stop BOTH apache AND Resin since Resin is defined
to rely upon apache.
I need to be able to do this kind of stopping/starting because I work with this
stuff an often need to do a clean start of Resin and/or apache and I certainly
don't want to have to restart my computer and I'd prefer not to do "kill pid" or
much around with the Activity Monitor.
So, can I do this with bootstrap daemons?
Rob
- by 123 June 13, 2004 1:59 AM PDT
- Loaded processes normally "sleep" anyway, or they would be using lots of cpu
- Like this Reply to this comment
-
(14 Comments)time. In fact, the only overhead of having a daemon loaded and not in use
should be the memory usage, and for a decently coded daemon, that should
be under 1 MB.