Launchd

Launchd

Infobox Software
name = launchd
author = Apple Computer
released = 29 April 2005
programming language = C (programming language)
operating system = Mac OS X
status = Active
genre = System Startup software
license = Apache License 2.0
website = http://developer.apple.com/macosx/launchd.html

launchd is a unified, open source service management framework for starting, stopping and managing daemons, programs and scripts. It was introduced with Mac OS X v10.4/Darwin v8.0, and is licensed under the Apache License.

The launchd daemon is essentially a replacement for init, rc, the init.d and rc.d scripts, SystemStarter (Mac OS X), inetd and xinetd, atd, crond and watchdogd. Apple has stated that it intends to eliminate all of the aforementioned services in favor of launchd. [cite web |title=See Apple's launchd man page |url=http://developer.apple.com/documentation/Darwin/Reference/ManPages/man8/launchd.8.html |accessdate=2008-01-08]

As of OS X v10.4 Apple has moved most of the processes handled by the previously mentioned daemons to launchd. By consolidating all the launch services into one program, launchd significantly shortens boot time on slow computers.

launchd Components

There are two main programs in the launchd system: launchd and launchctl.

"launchd" manages the daemons at both a system and user level. Similar to xinetd, launchd can start daemons on demand. Similar to watchdogd, launchd can monitor daemons to make sure that they keep running. launchd also has replaced init as PID 1 on Mac OS X and as a result it is responsible for starting the system at boot time.

Configuration files define the parameters of services run by launchd. Stored in the LaunchAgents and LaunchDaemons subdirectories of the Library folders, the property list-based files have around thirty different keys that can be set.

launchctl is a command line application used to load and unload daemons, start and stop launchd controlled jobs, get system utilization statistics for launchd and its child processes, and set environment settings.

launchd

launchd has two main tasks. The first is to boot the system, and the second is to load and maintain services.

Here is a simplified view of the 10.4 system startup on a PowerPC Mac (on an Intel Mac, EFI replaces Open Firmware and boot.efi replaces BootX):

#Open Firmware activates, initializes the hardware, and then loads BootX.
#BootX loads the kernel, spins the pinwheel cursor, and loads any needed kernel extensions (kexts).
#The kernel loads launchd.
#launchd runs /etc/rc, scans through /System/Library/LaunchAgents and /Library/LaunchDaemons and acts on the plists as needed, and starts the login window.

In step 4, launchd scans through a few different directories for jobs to run. There are two different folders that are scanned. The LaunchDaemons folders contain items that will run as root, generally background processes. The LaunchAgents folders contain jobs, called agent applications, that will run as a user or in the context of userland. These may be scripts or other foreground items, and they can even include a user interface. These directories are all kept in the typical Library folders of Mac OS X.

Launchd is very different from SystemStarter in that it may not actually launch all the daemons at boot time. Key to launchd, and similar to xinetd, is the idea of launch on demand daemons. When launchd scans through the job plists at boot time it reserves and listens on all of the ports requested by those jobs. If so indicated in the plist by the "OnDemand" key, the daemon is not actually loaded at the time. Rather, launchd will listen on the port, start the daemon when needed, and shut it down when it is not. After a daemon is loaded, launchd will keep track of it and make sure it is running if needed. In this way it is like watchdogd, and shares watchdogd's requirement that processes do not attempt to fork or daemonize on their own. If a process goes into the background launchd will lose track of it and attempt to relaunch it.

Consequently, Mac OS X 10.4 boots much faster than previous releases. The system only has to register the daemons that are to run, not actually launch them. In fact, the progress bar that appears during boot time is just a placebo application (named WaitingForLoginWindow [ [http://daringfireball.net/misc/2005/04/tiger_details#waitingforloginwindow Daring Fireball: Tiger Details ] ] ) that does not really show anything other than the passage of time.

The hardest part to manage during a launchd boot is dependencies. SystemStarter had a very simple system of dependencies that used the "Uses", "Requires", and "Provides" keys in the plist of a startup item. There are two main strategies when creating launch dependencies on 10.4. Using IPC will allow the daemons to talk amongst themselves to work it out, or you can watch files or paths for changes. Using IPC is much more subtle than the SystemStarter's keys and requires more work from the developer, but it may lead to cleaner and quicker startups. The SystemStarter is an option that is still supported at this time, but it has been deprecated in Mac OS X 10.4; it may not be available in future OS X versions.

launchctl

One of the major complaints with the other facilities for service control is that they are strewn across the OS with no central way to manage them. launchctl is Apple's way of fixing this.

On its own, launchctl can take commands from the command line, from standard in, or operate in interactive mode. A set of commands can be made permanent when stored in ~/.launchd.conf or /etc/launchd.conf. With sudo, launchctl can be used to make changes on a global scale.

Property list

A property list (plist) is a type of file that Apple uses for program configuration. When launchd scans a folder, or a job is submitted with launchctl, it reads a plist file that describes how the program is to be run.

A list of oft-used keys follows below. For a full list, see Apple's manpage for launchd.plist. [ [http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html Mac OS X Manual Page For launchd.plist(5) ] ]

References

See also

* Daemontools
* eINIT
* Initng
* Operating System service management
* Super-server
* TCP Wrapper
* Upstart

External links

* [http://developer.apple.com/macosx/launchd.html Getting Started with launchd] at developer.apple.com
* [http://launchd.macosforge.org/trac/browser launchd's source code] at Mac OS Forge (click on "trunk", then "Zip Archive" to get the full source)
* [http://launchd.macosforge.org/ launchd site] at macosforge.org
* [http://www.afp548.com/article.php?story=20050620071558293 launchd in Depth] : The basis for much of this article.
* [http://video.google.com/videoplay?docid=1781045834610400422 launchd: One Programm to Rule Them All] – Video presentation of launchd.
* [http://www.macgeekery.com/tips/all_about_launchd_items_and_how_to_make_one_yourself All About launchd Items (and How To Make One Yourself)] : The creation of property lists for launchd
* [http://www.codepoetry.net/products/launchdeditor Launchd Editor] , a shareware editor for creating launchd service property lists
* [http://lingon.sourceforge.net/ Lingon] , an Open Source editor for creating launchd service property lists
* [http://wikitest.freebsd.org/moin.cgi/launchd launchd - FreeBSD-Wiki] , launchd ported to FreeBSD

Online Unix Manual References

*man|8|launchd|Darwin|System wide daemon and per-user agent manager
*man|5|launchd.conf|Darwin
*man|5|launchd.plist|Darwin
*man|1|launchctl|Darwin


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Launchd — ist ein vereinheitlichtes, Open Source Verwaltungssystem (Framework) zum Starten, Beenden und Verwalten von Daemons, Programmen und Shell Scripts. Eingeführt wurde es mit Mac OS X v10.4/Darwin v8.0, es ist lizenziert unter der Apache Lizenz. Der… …   Deutsch Wikipedia

  • launchd — ist ein einheitliches Framework zum Starten, Verwalten und Beenden von Daemons, Programmen und Shell Skripten. Eingeführt wurde es mit Mac OS X v10.4/Darwin v8.0 und lizenziert ist es unter der Apache Lizenz. Der bei Apple angestellte Dave… …   Deutsch Wikipedia

  • Launchd — Launchd  система инциализации системы с открытым исходным кодом, используемая в ОС Mac OS X. Процесс имеет PID 1 и занимается тем, что запускает другие процессы и перезапускает их в случае сбоя, то есть выполняет функции init в Linux. Также… …   Википедия

  • Darwin (operating system) — Darwin Company / developer Apple Inc. Programmed in C, C++ OS family Unix …   Wikipedia

  • AppleScript — Paradigm(s) Natural language, Scripting …   Wikipedia

  • Spotlight (software) — Spotlight Screenshot of the Spotlight menu performing a search for the word adobe in Mac OS X Leopard …   Wikipedia

  • Cron — Der cron Daemon ist eine Jobsteuerung von Unix bzw. Unix artigen Betriebssystemen wie Linux, BSD oder Mac OS X, die wiederkehrende Aufgaben (cronjobs) automatisch zu einer bestimmten Zeit ausführen kann. Häufig führt der Cron Daemon wichtige… …   Deutsch Wikipedia

  • Cron-Job — Der cron Daemon ist eine Jobsteuerung von Unix bzw. Unix artigen Betriebssystemen wie Linux, BSD oder Mac OS X, die wiederkehrende Aufgaben (cronjobs) automatisch zu einer bestimmten Zeit ausführen kann. Häufig führt der Cron Daemon wichtige… …   Deutsch Wikipedia

  • Cron Jobs — Der cron Daemon ist eine Jobsteuerung von Unix bzw. Unix artigen Betriebssystemen wie Linux, BSD oder Mac OS X, die wiederkehrende Aufgaben (cronjobs) automatisch zu einer bestimmten Zeit ausführen kann. Häufig führt der Cron Daemon wichtige… …   Deutsch Wikipedia

  • Cronjob — Der cron Daemon ist eine Jobsteuerung von Unix bzw. Unix artigen Betriebssystemen wie Linux, BSD oder Mac OS X, die wiederkehrende Aufgaben (cronjobs) automatisch zu einer bestimmten Zeit ausführen kann. Häufig führt der Cron Daemon wichtige… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”