HOME

TheInfoList



OR:

launchd is an
init In Unix-based computer operating systems, init (short for ''initialization'') is the first process started during booting of the operating system. Init is a daemon process that continues running until the system is shut down. It is the direc ...
and operating system service management
daemon A demon is a malevolent supernatural being, evil spirit or fiend in religion, occultism, literature, fiction, mythology and folklore. Demon, daemon or dæmon may also refer to: Entertainment Fictional entities * Daemon (G.I. Joe), a character ...
created by
Apple Inc. Apple Inc. is an American multinational corporation and technology company headquartered in Cupertino, California, in Silicon Valley. It is best known for its consumer electronics, software, and services. Founded in 1976 as Apple Comput ...
as part of
macOS macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
to replace its BSD-style
init In Unix-based computer operating systems, init (short for ''initialization'') is the first process started during booting of the operating system. Init is a daemon process that continues running until the system is shut down. It is the direc ...
and SystemStarter. There have been efforts to
port A port is a maritime facility comprising one or more wharves or loading areas, where ships load and discharge cargo and passengers. Although usually situated on a sea coast or estuary, ports can also be found far inland, such as Hamburg, Manch ...
launchd to
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
and derived systems.


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 macOS 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 In the macOS, 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. Property l ...
-based files have approximately thirty different keys that can be set. launchd itself has no knowledge of these configuration files or any ability to read them - that is the responsibility of "launchctl". ''launchctl'' is a command line application which talks to launchd using IPC and knows how to parse the
property list In the macOS, 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. Property l ...
files used to describe launchd jobs, serializing them using a specialized dictionary protocol that launchd understands. launchctl can be 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 A boot is a type of footwear. Most boots mainly cover the foot and the ankle, while some also cover some part of the lower calf. Some boots extend up the leg, sometimes as far as the knee or even the hip. Most boots have a heel that is clearl ...
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 (with the backronym Performance Optimization With Enhanced RISC – Performance Computing, sometimes abbreviated as PPC) is a reduced instruction set computer (RISC) instruction set architecture (ISA) created by the 1991 Apple Inc., App ...
Mac (on an
Intel Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California, and Delaware General Corporation Law, incorporated in Delaware. Intel designs, manufactures, and sells computer compo ...
Mac, EFI replaces
Open Firmware Open Firmware is a standard defining the interfaces of a computer firmware system, formerly endorsed by the Institute of Electrical and Electronics Engineers (IEEE). It originated at Sun Microsystems where it was known as OpenBoot, and has bee ...
and boot.efi replaces BootX): #
Open Firmware Open Firmware is a standard defining the interfaces of a computer firmware system, formerly endorsed by the Institute of Electrical and Electronics Engineers (IEEE). It originated at Sun Microsystems where it was known as OpenBoot, and has bee ...
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, various scripts which scan through /System/Library/LaunchDaemons and /Library/LaunchDaemons, calling launchctl on the plists as needed, then launchd starts the login window. In step 4, the startup scripts scan through a few different directories for jobs to run. There are two different directories that are scanned: # The LaunchDaemons directories contain items that will run as root, generally background processes. # The LaunchAgents directories 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 directories 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 launchctl scans through the job plists at boot time, it asks launchd to reserve and listen 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 no longer needed. 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. Mac OS X Tiger, consequently, boots much faster than previous releases. The system only has to register the daemons that are to run and does not actually launch them until they are needed. 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 launchd dependencies on Tiger: IPC allows daemons to talk amongst themselves to work out dependencies, or daemons 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. SystemStarter was still supported up to
OS X Mountain Lion OS X Mountain Lion (version 10.8) is the ninth major release of macOS, Apple Inc.'s desktop and server operating system for Macintosh computers. OS X Mountain Lion was released on July 25, 2012, for purchase and download through the Mac App S ...
, but was removed in
OS X Yosemite OS X Yosemite ( ; version 10.10) is the eleventh major release of macOS, Apple Inc.'s desktop and server operating system for Macintosh computers. OS X Yosemite was announced and released to developers on June 2, 2014, at WWDC 2014 and re ...
.


launchctl

In launchd, control of services is centralized in the launchctl application. On its own, launchctl can take commands from the command line, from standard in, or operate in interactive mode. With
superuser In computing, the superuser is a special user account used for system administration. Depending on the operating system (OS), the actual name of this account might be root, administrator, admin or supervisor. In some cases, the actual name of the ...
privileges, launchctl can be used to make changes on a global scale. A set of launchctl commands can be made permanent when stored in /etc/launchd.conf. (A per-user ~/.launchd.conf file appears to have been considered, but is not supported in any existing version of macOS.Mac OS X Manual Page For launchd.conf(5)
/ref>) launchctl communicates with launchd via a
Mach The Mach number (M or Ma), often only Mach, (; ) is a dimensionless quantity in fluid dynamics representing the ratio of flow velocity past a Boundary (thermodynamic), boundary to the local speed of sound. It is named after the Austrian physi ...
-specific IPC mechanism.


Property list

A
property list In the macOS, 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. Property l ...
(plist) is a type of file that launchd 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. All keys are optional unless otherwise noted. For a full list, see Apple's manual page for launchd.plist.


Socket activation protocol

The name of each key under Sockets will be placed into the environment of the job when it is run, and the file descriptor of that socket will be available in that environment variable. This differs from systemd's socket activation in that the name of a socket definition inside of the job configuration is hardcoded into the application. This protocol is less flexible, although it does not, as systemd does, require the daemon to hardcode a starting file descriptor (as of 2014, it is 3).


History

The software was designed and coded by Dave Zarzycki at
Apple An apple is a round, edible fruit produced by an apple tree (''Malus'' spp.). Fruit trees of the orchard or domestic apple (''Malus domestica''), the most widely grown in the genus, are agriculture, cultivated worldwide. The tree originated ...
. The company planned for all of the following to be superseded in
OS X macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
environments – *
init In Unix-based computer operating systems, init (short for ''initialization'') is the first process started during booting of the operating system. Init is a daemon process that continues running until the system is shut down. It is the direc ...
* rc * init.d script * rc.d script * SystemStarter *
inetd inetd (internet service daemon) is a super-server Daemon (computer software), daemon on many Unix systems that provides Internet services. For each configured service, it listens for requests from connecting clients. Requests are served by spawn ...
/
xinetd In computer networking, xinetd (''Extended Internet Service Daemon'') is an open-source software, open-source super-server Daemon (computer software), daemon which runs on many Unix-like operating system, systems, and manages Internet-based conne ...
* crond / atd * watchdogd – and most of those things ''were'' superseded when launchd was introduced with Mac OS X v10.4 (Tiger). In 2005, R. Tyler Croy ported launchd to
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
as part of Google Summer of Code Project. It could not be run as PID 1 (only a session init), and it was not commonly used on that platform. In 2006, the
Ubuntu Ubuntu ( ) is a Linux distribution based on Debian and composed primarily of free and open-source software. Developed by the British company Canonical (company), Canonical and a community of contributors under a Meritocracy, meritocratic gover ...
Linux distribution A Linux distribution, often abbreviated as distro, is an operating system that includes the Linux kernel for its kernel functionality. Although the name does not imply product distribution per se, a distro—if distributed on its own—is oft ...
considered using launchd. The option was rejected because the source code was subject to the
Apple Public Source License The Apple Public Source License (APSL) is the open-source and free software license under which Apple's Darwin operating system was released in 2000. A free and open-source software license was voluntarily adopted to further involve the commu ...
– described as an "inescapable licence problem". Ubuntu instead developed and switched to its own service management tool, Upstart. In August 2006, Apple relicensed launchd under the Apache License, Version 2.0 in an effort to make adoption by other open source developers easier. Most Linux distributions use
systemd systemd is a software suite that provides an array of system components for Linux operating systems. The main aim is to unify service configuration and behavior across Linux distributions. Its primary component is a "system and service manage ...
or Upstart, or continue with
init In Unix-based computer operating systems, init (short for ''initialization'') is the first process started during booting of the operating system. Init is a daemon process that continues running until the system is shut down. It is the direc ...
, and the
BSD The Berkeley Software Distribution (BSD), also known as Berkeley Unix or BSD Unix, is a discontinued Unix operating system developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Berkeley, beginni ...
s also continue with init. In December 2013, R. Tyler Croy announced his intent to resume work on his port of launchd to FreeBSD, and his "openlaunchd" GitHub repo subsequently rose in activity. The last Wayback Machine capture of the Mac OS Forge area for launchd was in June 2012, and the most recent open source version from Apple wa
842.92.1
in code for OS X 10.9.5. In 2014, with OS X 10.10 and iOS 8, Apple moved code for launchd to closed source libxpc. In August 2015 Jordan Hubbard and Kip Macy announced NextBSD, which is based on FreeBSD-CURRENT kernel while adding in Mach IPC, Libdispatch, notifyd, asld, launchd, and other components derived from Darwin, Apple's open-source code for OS X.


Apple open source release history


See also

*
systemd systemd is a software suite that provides an array of system components for Linux operating systems. The main aim is to unify service configuration and behavior across Linux distributions. Its primary component is a "system and service manage ...
: similar utility developed by
Red Hat Red Hat, Inc. (formerly Red Hat Software, Inc.) is an American software company that provides open source software products to enterprises and is a subsidiary of IBM. Founded in 1993, Red Hat has its corporate headquarters in Raleigh, North ...
for use among various mainline Linux distributions * Service Management Facility *
Super-server A super-server, sometimes called a service dispatcher, is a type of Daemon (computer software), daemon run generally on Unix-like systems. Usage A super-server starts other Server (computing), servers when needed, normally with access to them ...
* TCP Wrapper * Operating system service management


References


External links

Apple Developer: * Mac Developer Library: Daemons and Services Programming Guide
Creating Launch Daemons and Agents
* Mac Developer Library

Apple Developer Retired Documents Library: * * * * Other links: * Apple Developer Library:
Launchd: One Program to Rule them All - YouTube
– presentation by Dave Zarzycki uploaded October 8, 2007 by ''GoogleTechTalks'' * * {{Service management in Unix MacOS Software using the Apache license Unix process- and task-management-related software