Launchd
Encyclopedia
launchd is a unified, open-source
Open-source software
Open-source software is computer software that is available in source code form: the source code and certain other rights normally reserved for copyright holders are provided under a software license that permits users to study, change, improve and at times also to distribute the software.Open...

 service management
Operating system service management
In computing, mechanisms and techniques for managing services often differ by operating system. Operating system service management can refer to the following:...

 framework
Software framework
In computer programming, a software framework is an abstraction in which software providing generic functionality can be selectively changed by user code, thus providing application specific software...

 for starting, stopping and managing daemons
Daemon (computer software)
In Unix and other multitasking computer operating systems, a daemon is a computer program that runs as a background process, rather than being under the direct control of an interactive user...

, application
Application software
Application software, also known as an application or an "app", is computer software designed to help the user to perform specific tasks. Examples include enterprise software, accounting software, office suites, graphics software and media players. Many application programs deal principally with...

s, processes
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

, and scripts
Shell script
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language...

. Written and designed by Dave Zarzycki at Apple, it was introduced with Mac OS X Tiger and is licensed under the Apache License
Apache License
The Apache License is a copyfree free software license authored by the Apache Software Foundation . The Apache License requires preservation of the copyright notice and disclaimer....

.

The launchd daemon
Daemon (computer software)
In Unix and other multitasking computer operating systems, a daemon is a computer program that runs as a background process, rather than being under the direct control of an interactive user...

 is essentially a replacement for:
  • init
    Init
    init is a program for Unix-based computer operating systems that spawns all other processes. It runs as a daemon and typically has PID 1. The boot loader starts the kernel and the kernel starts init...

  • rc
    Unix security
    Unix security refers to the means of securing a Unix or Unix-like operating system. A secure environment is achieved not only by the design concepts of these operating systems, but also through vigilant user and administrative practices.- Permissions :...

  • init.d script
  • rc.d script
  • SystemStarter
    SystemStarter
    SystemStarter is a system program in Mac OS X, started by Mac OS X's BSD-style init prior to Mac OS X v10.4 and by launchd in Mac OS X v10.4 and later releases, that starts system processes specified by a set of property lists. SystemStarter was originally written by Wilfredo Sanchez for Mac OS X...

     (Mac OS X)
  • inetd
    Inetd
    inetd is a super-server daemon on many Unix systems that manages Internet services. First appearing in 4.3BSD , it is generally located at /usr/sbin/inetd.-Function:...

  • xinetd
    Xinetd
    In computer networking, xinetd, the eXtended InterNET Daemon, is an open-source super-server daemon which runs on many Unix-like systems and manages Internet-based connectivity...

  • atd
    At (Unix)
    In Unix-like computer operating systems,the at commandis used to schedule commands to be executed once, at a particular time in the future....

  • crond
  • watchdogd
    Watchdog timer
    A watchdog timer is a computer hardware or software timer that triggers a system reset or other corrective action if the main program, due to some fault condition, such as a hang, neglects to regularly service the watchdog A watchdog timer (or computer operating properly (COP) timer) is a computer...


Apple has stated that it intends to eliminate all of the aforementioned services in favor of launchd.

For Mac OS X v10.4
Mac OS X v10.4
Mac OS X v10.4 Tiger is the fifth major release of Mac OS X, Apple's desktop and server operating system for Macintosh computers. Tiger was released to the public on 29 April 2005 for US$129.95 as the successor to Mac OS X Panther , which had been released 18 months earlier...

 Apple 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.

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
Process identifier
In computing, the process identifier is a number used by most operating system kernels to uniquely identify a process...

 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
Property list
In the Mac OS X, iOS, NeXTSTEP, and GNUstep programming frameworks, property list files are files that store serialized objects. Property list files use the filename extension .plist, and thus are often referred to as p-list files....

-based files have approximately 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
Booting
In computing, booting is a process that begins when a user turns on a computer system and prepares the computer to perform its normal operations. On modern computers, this typically involves loading and starting an operating system. The boot sequence is the initial set of operations that the...

 the system, and the second is to load and maintain services.

Here is a simplified view of the Mac OS X Tiger system startup on a PowerPC
PowerPC
PowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM...

 Mac (on an Intel Mac, EFI
Extensible Firmware Interface
The Unified Extensible Firmware Interface is a specification that defines a software interface between an operating system and platform firmware...

 replaces Open Firmware
Open Firmware
Open Firmware, or OpenBoot in Sun Microsystems parlance, is a standard defining the interfaces of a computer firmware system, formerly endorsed by the Institute of Electrical and Electronics Engineers . It originated at Sun, and has been used by Sun, Apple, IBM, and most other non-x86 PCI chipset...

 and boot.efi replaces BootX
BootX (Apple)
BootX is a software-based bootloader designed and developed by Apple Inc. for use on the company's Macintosh computer range. BootX is used to prepare the computer for use by loading all required device drivers and then starting-up Mac OS X by booting the kernel on all PowerPC Macintoshes running...

):
  1. Open Firmware
    Open Firmware
    Open Firmware, or OpenBoot in Sun Microsystems parlance, is a standard defining the interfaces of a computer firmware system, formerly endorsed by the Institute of Electrical and Electronics Engineers . It originated at Sun, and has been used by Sun, Apple, IBM, and most other non-x86 PCI chipset...

     activates, initializes the hardware, and then loads BootX.
  2. BootX
    BootX (Apple)
    BootX is a software-based bootloader designed and developed by Apple Inc. for use on the company's Macintosh computer range. BootX is used to prepare the computer for use by loading all required device drivers and then starting-up Mac OS X by booting the kernel on all PowerPC Macintoshes running...

     loads the kernel, spins the pinwheel cursor, and loads any needed kernel extensions
    Loadable Kernel Module
    In computing, a loadable kernel module is an object file that contains code to extend the running kernel, or so-called base kernel, of an operating system...

     (kexts).
  3. The kernel loads launchd.
  4. 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 Tiger 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) 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 Tiger. Using IPC
Inter-process communication
In computing, Inter-process communication is a set of methods for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC methods are divided into methods for message passing, synchronization, shared...

 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 reduced in importance in Mac OS X Tiger; 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. Apple fixes this with launchctl.

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 superuser
Superuser
On many computer operating systems, the superuser is a special user account used for system administration. Depending on the operating system, the actual name of this account might be: root, administrator or supervisor....

 privileges, launchctl can be used to make changes on a global scale.

Property list

A property list
Property list
In the Mac OS X, iOS, NeXTSTEP, and GNUstep programming frameworks, property list files are files that store serialized objects. Property list files use the filename extension .plist, and thus are often referred to as p-list files....

 (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 often used keys follows below. For a full list, see Apple's manpage for launchd.plist.
Key Description Required
Label The name of the job. By convention, the job label is the same as the plist file name, without the .plist extension. Required.
Program A path to an executable. Useful for simple launches. At least one of Program or ProgramArguments is required
ProgramArguments An array of strings representing a unix command. The first string is generally a path to an executable, while latter strings contain options or parameters. At least one of Program or ProgramArguments is required
UserName The job will be run as the given user, who may not necessarily be the one who submitted it to launchd. Optional, defaults to root or current user.
OnDemand Deprecated as of 10.5. A boolean flag that defines if a job runs continuously or not Optional, defaults to true.
RunAtLoad A boolean flag that defines if a task is launched immediately when the job is loaded into launchd. Optional, defaults to false.
StartOnMount A boolean flag that defines if a task is launched when a new file system is mounted. Optional, defaults to false.
QueueDirectories Watch an directory for new files. The directory must be empty to begin with, and must be returned to an empty state before QueueDirectories will launch its task again. Optional
WatchPaths Watch a file-system path for changes - this could be a file or folder. Optional
StartInterval Used to schedule a job that runs on a repeating schedule. Specified as the number of seconds to wait between runs. Optional
StartCalendarInterval Job scheduling. The syntax
Syntax
In linguistics, syntax is the study of the principles and rules for constructing phrases and sentences in natural languages....

 is similar to cron
Cron
Cron is a time-based job scheduler in Unix-like computer operating systems. Cron enables users to schedule jobs to run periodically at certain times or dates...

.
Optional
RootDirectory The job will be chroot
Chroot
A chroot on Unix operating systems is an operation that changes the apparent root directory for the current running process and its children. A program that is run in such a modified environment cannot name files outside the designated directory tree. The term "chroot" may refer to the chroot...

ed into this directory before execution
Optional
WorkingDirectory The job will be chdir
Chdir
cd, sometimes also available as chdir , is a command line command to change the current working directory in operating systems such as Unix, DOS, OS/2, AmigaOS , Windows, and Linux...

ed into this directory before execution
Optional
StandardInPath, StandardOutPath, StandardErrorPath Keys to determine files for input and output for the launched process Optional
LowPriorityIO Tells the kernel that this task is of a low priority when doing file system I/O Optional
AbandonProcessGroup A boolean flag that defines whether subprocess launched from tasks launched by launchd will be killed when the tasks end. Useful where a short-lived task starts a long-lived subtask, but may result in zombie processes. Optional, defaults to false

Use outside Mac OS X

A port to FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

 was done as part of Google Summer of Code Project in 2005.

The Ubuntu
Ubuntu (Linux distribution)
Ubuntu is a computer operating system based on the Debian Linux distribution and distributed as free and open source software. It is named after the Southern African philosophy of Ubuntu...

 Linux distribution considered using launchd in 2006. However, launchd was rejected as an option because it was released under the Apple Public Source License
Apple Public Source License
The Apple Public Source License is the open source and free software license under which Apple's Darwin operating system was released. A free software and open source license was voluntarily adopted to further involve the community from which much of Darwin originated.The first version of the Apple...

 – which at the time was described as an "inescapable licence problem".

In August 2006, Apple relicensed launchd under the Apache License, Version 2.0
Apache License
The Apache License is a copyfree free software license authored by the Apache Software Foundation . The Apache License requires preservation of the copyright notice and disclaimer....

 in an effort to make adoption by other open source developers easier.

See also

  • Daemontools
    Daemontools
    daemontools is a collection of free tools for managing Unix services. It was written by Daniel J. Bernstein as an improvement to the inittab, ttys, init.d or rc.local alternatives by providingall of the following features....

  • Runit
    Runit
    runit is an implementation of Process Supervision for Linux....

  • eINIT
    EINIT
    eINIT is a replacement for sysvinit, an init system used on Unix-based operating systems. eINIT is designed with speed in mind. Many testers claim that their systems boot up in 30 seconds, whereas sysvinit takes around two minutes to boot....

  • Initng
    Initng
    Initng is a full replacement of the UNIX System V init, the first process spawned by the kernel in Unix-like computer operating systems, which is responsible for the initialization of every other process...

  • Operating System service management
    Operating system service management
    In computing, mechanisms and techniques for managing services often differ by operating system. Operating system service management can refer to the following:...

  • Super-server
    Super-server
    A super-server or sometimes called a service dispatcher is a type of daemon run generally on Unix-like systems.- Usage :It starts other servers when needed, normally with access to them checked by a TCP wrapper. It uses very few resources when in idle state...

  • TCP Wrapper
    TCP Wrapper
    TCP Wrapper is a host-based networking ACL system, used to filter network access to Internet Protocol servers on operating systems such as Linux or BSD...

  • Upstart
    Upstart
    Upstart is an event-based replacement for the traditional init daemon — the method by which several Unix-like computer operating systems perform tasks when the computer is started. It was written by Scott James Remnant, a former employee of Canonical Ltd....

  • Service Management Facility
    Service Management Facility
    Service Management Facility is a feature of the Solaris operating system that creates a supported, unified model for services and service management on each Solaris system and replaces init.d scripts. SMF introduces:...

  • systemd
    Systemd
    systemd is a replacement for the System V init daemon for Linux. It is intended to provide a better framework for expressing services' dependencies, allow more work to be done in parallel at system startup, and to reduce shell overhead....


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK