]> git.saurik.com Git - apple/launchd.git/blame - launchd/src/launchd.plist.5
launchd-258.25.tar.gz
[apple/launchd.git] / launchd / src / launchd.plist.5
CommitLineData
e91b9f68
A
1.Dd September 30, 2004
2.Dt launchd.plist 5
3.Os Darwin
4.Sh NAME
5.Nm launchd.plist
6.Nd System wide and per-user daemon/agent configuration files
7.Sh DESCRIPTION
8This document details the parameters that can be given to an XML property list that can be loaded into
9.Nm launchd
10with
11.Nm launchctl .
12.Sh EXPECTATIONS
13Daemons or agents managed by
14.Nm launchd
15are expected to behave certain ways.
16.Pp
17A daemon or agent launched by
18.Nm launchd
19MUST NOT do the following in the process directly launched by
20.Nm launchd :
21.Pp
22.Bl -bullet -offset indent -compact
23.It
ed34e3c3
A
24Call
25.Xr daemon 3 .
26.It
27Do the moral equivalent of
28.Xr daemon 3
29by calling
e91b9f68
A
30.Xr fork 2
31and have the parent process
32.Xr exit 3
33or
34.Xr _exit 2 .
e91b9f68
A
35.El
36.Pp
37A daemon or agent launched by
38.Nm launchd
39SHOULD NOT do the following as a part of their startup initialization:
40.Pp
41.Bl -bullet -offset indent -compact
42.It
43Setup the user ID or group ID.
44.It
45Setup the working directory.
46.It
47.Xr chroot 2
48.It
49.Xr setsid 2
50.It
51Close "stray" file descriptors.
52.It
53Change
54.Xr stdio 3
55to /dev/null.
56.It
57Setup resource limits with
58.Xr setrusage 2 .
59.It
60Setup priority with
61.Xr setpriority 2 .
62.It
63Ignore the SIGTERM signal.
64.El
65.Pp
66A daemon or agent launched by
67.Nm launchd
68SHOULD:
69.Pp
70.Bl -bullet -offset indent -compact
71.It
72Launch on demand given criteria specified in the XML property list.
ed34e3c3 73More information can be found later in this man page.
e91b9f68
A
74.It
75Catch the SIGTERM signal.
76.El
77.Sh XML PROPERTY LIST KEYS
78The follow keys can be used to describe the configuration details of your daemon or agent.
ed34e3c3
A
79Property lists are Apple's standard configuration file format. Please see
80.Xr plist 5
81for more information. Please note. Property list files are expected to have their name end in ".plist".
e91b9f68
A
82.Pp
83.Bl -ohang
84.It Sy Label <string>
85This required key uniquely identifies the job to
86.Nm launchd .
87.It Sy Disabled <boolean>
88This optional key is used to disable your job. The default is false.
89.It Sy UserName <string>
ed34e3c3 90This optional key specifies the user to run the job as. This key is only applicable when launchd is running as root.
e91b9f68 91.It Sy GroupName <string>
ed34e3c3 92This optional key specifies the group to run the job as. This key is only applicable when launchd is running as root. If UserName is set and GroupName is not, the the group will be set to the default group of the user.
e91b9f68 93.It Sy inetdCompatibility <dictionary>
ed34e3c3 94The presence of this key specifies that the daemon expects to be run as if it were launched from inetd.
e91b9f68
A
95.Bl -ohang -offset indent
96.It Sy Wait <boolean>
ed34e3c3
A
97This flag corresponds to the "wait" or "nowait" option of inetd. If true, then the listening socket is passed via the standard in/out/error file descriptors. If false, then
98.Xr accept 2
99is called on behalf of the job, and the result is passed via the standard in/out/error descriptors.
e91b9f68 100.El
ed34e3c3
A
101.It Sy LimitLoadToHosts <array of strings>
102This configuration file only applies to the hosts listed with this key.
103.It Sy LimitLoadFromHosts <array of strings>
104This configuration file only applies to hosts NOT listed with this key.
105.It Sy LimitLoadToSessionType <string>
106This configuration file only applies to sessions of the type specified. This key is used
107in concert with the -S flag to
108.Nm launchctl .
e91b9f68 109.It Sy Program <string>
5b0a4722 110This key maps to the first argument of
e91b9f68
A
111.Xr execvp 3 .
112If this key is missing, then the first element of the array of strings provided to the ProgramArguments will be used instead.
5b0a4722
A
113This key is required in the absence of the ProgramArguments key.
114.It Sy ProgramArguments <array of strings>
115This key maps to the second argument of
116.Xr execvp 3 .
117This key is required in the absence of the Program key. Please note! Many people are confused by this key. Please read
118.Xr execvp 3
119very carefully!
ed34e3c3
A
120.It Sy EnableGlobbing <boolean>
121This flag causes
122.Nm launchd
123to use the
124.Xr glob 3
125mechanism to update the program arguments before invocation.
e91b9f68 126.It Sy OnDemand <boolean>
ed34e3c3
A
127This key was used in Mac OS X 10.4 to control whether a job was kept alive or not. The default was true.
128This key has been deprecated and replaced in Mac OS X 10.5 with the more powerful KeepAlive option.
129.It Sy KeepAlive <boolean or dictionary of stuff>
130This optional key is used to control whether your job is to be kept
131continuously running or to let demand and conditions control the invocation. The
132default is false and therefore only demand will start the job. The value may be
133set to true to unconditionally keep the job alive. Alternatively, a dictionary
134of conditions may be specified to selectively control whether
135.Nm launchd
136keeps a job alive or not. If multiple keys are provided, launchd ORs them, thus
137providing maximum flexibility to the job to refine the logic and stall if necessary. If
138.Nm launchd
139finds no reason to restart the job, it falls back on demand based invocation.
140Jobs that exit quickly and frequently when configured to be kept alive will be
141throttled to converve system resources.
142.Bl -ohang -offset indent
143.It Sy SuccessfulExit <boolean>
144If true, the job will be restarted as long as the program exits and with an exit
145status of zero. If false, the job will be restarted in the inverse condition.
146This key implies that "RunAtLoad" is set to true, since the job needs to run at
147least once before we can get an exit status.
148.It Sy NetworkState <boolean>
149If true, the job will be kept alive as long as the network is up, where up is
150defined as at least one non-loopback interface being up and having IPv4 or IPv6
151addresses assigned to them.
152If false, the job will be kept alive in the inverse condition.
153.It Sy PathState <dictionary of booleans>
154Each key in this dictionary is a file-system path. If the value of the key is
155true, then the job will be kept alive as long as the path exists.
156If false, the job will be kept alive in the inverse condition. The intent of this
157feature is that two or more jobs may create semaphores in the file-system namespace.
5b0a4722
A
158.It Sy OtherJobEnabled <dictionary of booleans>
159Each key in this dictionary is the label of another job. If the value of the key is
160true, then this job is kept alive as long as that other job is enabled. Otherwise,
161if the value is false, then this job is kept alive as long as the other job is disabled.
162This feature should not be considered a substitute for the use of IPC.
ed34e3c3 163.El
e91b9f68
A
164.It Sy RunAtLoad <boolean>
165This optional key is used to control whether your job is launched once at the time the job is loaded. The default is false.
166.It Sy RootDirectory <string>
ed34e3c3 167This optional key is used to specify a directory to
e91b9f68
A
168.Xr chroot 2
169to before running the job.
170.It Sy WorkingDirectory <string>
ed34e3c3 171This optional key is used to specify a directory to
e91b9f68
A
172.Xr chdir 2
173to before running the job.
e91b9f68
A
174.It Sy EnvironmentVariables <dictionary of strings>
175This optional key is used to specify additional environmental variables to be setup before running the job.
176.It Sy Umask <integer>
177This optional key specifies what value should be passed to
178.Xr umask 2
ed34e3c3 179before running the job. Known bug: Property lists don't support octal, so please convert the value to decimal.
e91b9f68 180.It Sy TimeOut <integer>
5b0a4722 181The recommended idle time out (in seconds) to pass to the job. If no value is specified, a default time out will be supplied by
e91b9f68
A
182.Nm launchd
183for use by the job at check in time.
5b0a4722
A
184.It Sy ExitTimeOut <integer>
185The amount of time
186.Nm launchd
187waits before sending a SIGKILL signal. The default value is 20 seconds. The value zero is interpreted as infinity.
188.It Sy ThrottleInterval <integer>
189This key lets one override the default throttling policy imposed on jobs by
190.Nm launchd .
191The value is in seconds, and by default, jobs will not be spawned more than once every 10 seconds.
192The principle behind this is that jobs should linger around just in case they are needed again in the near future. This not only
193reduces the latency of responses, but it encourages developers to amortize the cost of program invocation.
e91b9f68
A
194.It Sy InitGroups <boolean>
195This optional key specifies whether the job should have
196.Xr initgroups 3
ab36757d 197be called before running the job.
5b0a4722 198The default is true in 10.5 and false in 10.4. This key will be ignored if the UserName key is not set.
e91b9f68
A
199.It Sy WatchPaths <array of strings>
200This optional key causes the job to be started if any one of the listed paths are modified.
201.It Sy QueueDirectories <array of strings>
202Much like the WatchPaths option, this key will watch the paths for modifications. The difference being that the job will only be started if the path is a directory and the directory is not empty.
5b0a4722
A
203.It Sy StartOnMount <boolean>
204This optional key causes the job to be started every time a filesystem is mounted.
e91b9f68
A
205.It Sy StartInterval <integer>
206This optional key causes the job to be started every N seconds.
ab36757d
A
207If the system is asleep, the job will be started the next time the computer
208wakes up. If multiple intervals transpire before the computer is woken, those
209events will be coalesced into one event upon wake from sleep.
ed34e3c3 210.It Sy StartCalendarInterval <dictionary of integers or array of dictionary of integers>
e91b9f68 211This optional key causes the job to be started every calendar interval as specified. Missing arguments are considered to be wildcard. The semantics are much like
ab36757d
A
212.Xr crontab 5 .
213Unlike cron which skips job invocations when the computer is asleep, launchd
214will start the job the next time the computer wakes up. If multiple intervals
215transpire before the computer is woken, those events will be coalesced into one
216event upon wake from sleep.
e91b9f68
A
217.Bl -ohang -offset indent
218.It Sy Minute <integer>
219The minute on which this job will be run.
220.It Sy Hour <integer>
221The hour on which this job will be run.
222.It Sy Day <integer>
223The day on which this job will be run.
224.It Sy Weekday <integer>
225The weekday on which this job will be run (0 and 7 are Sunday).
226.It Sy Month <integer>
227The month on which this job will be run.
228.El
229.It Sy StandardOutPath <string>
230This optional key specifies what file should be used for data being sent to stdout when using
231.Xr stdio 3 .
232.It Sy StandardErrorPath <string>
233This optional key specifies what file should be used for data being sent to stderr when using
234.Xr stdio 3 .
235.It Sy Debug <boolean>
236This optional key specifies that
237.Nm launchd
238should adjust its log mask temporarily to LOG_DEBUG while dealing with this job.
ed34e3c3
A
239.It Sy WaitForDebugger <boolean>
240This optional key specifies that
241.Nm launchd
242should instruct the kernel to have the job wait for a debugger to attach before any code in the job is executed.
e91b9f68
A
243.It Sy SoftResourceLimits <dictionary of integers>
244.It Sy HardResourceLimits <dictionary of integers>
245Resource limits to be imposed on the job. These adjust variables set with
246.Xr setrlimit 2 .
247The following keys apply:
248.Bl -ohang -offset indent
249.It Sy Core <integer>
250The largest size (in bytes) core file that may be created.
251.It Sy CPU <integer>
252The maximum amount of cpu time (in seconds) to be used by each process.
253.It Sy Data <integer>
254The maximum size (in bytes) of the data segment for a process; this defines how far a program may extend its break with the
255.Xr sbrk 2
256system call.
257.It Sy FileSize <integer>
258The largest size (in bytes) file that may be created.
259.It Sy MemoryLock <integer>
260The maximum size (in bytes) which a process may lock into memory using the
261.Xr mlock 2
262function.
263.It Sy NumberOfFiles <integer>
264The maximum number of open files for this process.
265.It Sy NumberOfProcesses <integer>
266The maximum number of simultaneous processes for this user id.
267.It Sy ResidentSetSize <integer>
268The maximum size (in bytes) to which a process's resident set size may grow.
269This imposes a limit on the amount of physical memory to be given to a process;
270if memory is tight, the system will prefer to take memory from processes that
271are exceeding their declared resident set size.
272.It Sy Stack <integer>
273The maximum size (in bytes) of the stack segment for a process; this defines
274how far a program's stack segment may be extended. Stack extension is
275performed automatically by the system.
276.El
277.It Sy Nice <integer>
278This optional key specifies what
279.Xr nice 3
280value should be applied to the daemon.
5b0a4722
A
281.It Sy AbandonProcessGroup <boolean>
282When a job dies,
283.Nm launchd
284kills any remaining processes with the same process group ID as the job.
285Setting this key to true disables that behavior.
286.It Sy HopefullyExitsFirst <boolean>
287This optional key causes programs to exit earlier during system shutdown.
288This key exists because some jobs do more than flush buffers and exit like
289they're supposed to. The use of this key should be considered a
290temporary solution until the software can be changed to only flush dirty buffers
291and then exit.
292.It Sy HopefullyExitsLast <boolean>
293This optional key causes programs to exit later during system shutdown. This
294key exists because some jobs don't reference count their clients, and therefore
295do not know when it is safe to exit. The use of this key should be considered a
296temporary solution until the software can be changed to properly reference
297count clients.
e91b9f68
A
298.It Sy LowPriorityIO <boolean>
299This optional key specifies whether the kernel should consider this daemon to be low priority when doing file system I/O.
5b0a4722
A
300.It Sy LaunchOnlyOnce <boolean>
301This optional key specifies whether the job can only be run once and only once.
302In other words, if the job cannot be safely respawned without a full machine
303reboot, then set this key to be true.
304.It Sy MachServices <dictionary of booleans or a dictionary of dictionaries>
ed34e3c3
A
305This optional key is used to specify Mach services to be registered with the
306Mach bootstrap sub-system. Each key in this dictionary should be the name of
5b0a4722
A
307service to be advertised. The value of the key must be a boolean and set to true.
308Alternatively, a dictionary can be used instead of a simple true value.
309.Bl -ohang -offset indent
310.It Sy ResetAtClose <boolean>
311If this boolean is false, the port is recycled, thus leaving clients to remain oblivious
312to the demand nature of job. If the value is set to true, clients receive port
ed34e3c3
A
313death notifications when the job lets go of the receive right. The port will be
314recreated atomically with respect to bootstrap_look_up() calls, so that clients
315can trust that after receiving a port death notification, the new port will
5b0a4722
A
316have already been recreated. Setting the value to true should be done with
317care. Not all clients may be able to handle this behavior. The default value is false.
318.It Sy HideUntilCheckIn <boolean>
319Reserve the name in the namespace, but cause bootstrap_look_up() to fail until the job has checked in with
320.Nm launchd .
321.El
322.Pp
323Finally, for the job itself, the values will be replaced with Mach ports at the time of check-in with
ed34e3c3 324.Nm launchd .
ab36757d 325.It Sy Sockets <dictionary of dictionaries... OR dictionary of array of dictionaries...>
e91b9f68
A
326This optional key is used to specify launch on demand sockets that can be used to let
327.Nm launchd
ed34e3c3 328know when to run the job. The job must check-in to get a copy of the file descriptors using APIs outlined in
e91b9f68 329.Xr launch 3 .
ab36757d
A
330The keys of the top level Sockets dictionary can be anything. They are meant for the application developer to use to
331differentiate different which descriptors correspond to which application level protocols (e.g. http vs. ftp vs. DNS...).
332At check in time, the value of each Sockets dictionary key will be an array of descriptors. Daemon/Agent writers should
333consider all descriptors of a given key to be to be effectively equivalent, even though each file descriptor likely represents
334a different networking protocol which conforms to the criteria specified in the job configuration file.
335.Pp
5b0a4722 336The parameters below are used as inputs to call
e91b9f68
A
337.Xr getaddrinfo 3 .
338.Bl -ohang -offset indent
339.It Sy SockType <string>
340This optional key tells
341.Nm launchctl
342what type of socket to create. The default is "stream" and other valid values for this key
343are "dgram" and "seqpacket" respectively.
344.It Sy SockPassive <boolean>
345This optional key specifies whether
346.Xr listen 2
347or
348.Xr connect 2
349should be called on the created file descriptor. The default is true ("to listen").
350.It Sy SockNodeName <string>
351This optional key specifies the node to
352.Xr connect 2
353or
354.Xr bind 2
355to.
356.It Sy SockServiceName <string>
357This optional key specifies the service on the node to
358.Xr connect 2
359or
360.Xr bind 2
361to.
362.It Sy SockFamily <string>
363This optional key can be used to specifically request that "IPv4" or "IPv6" socket(s) be created.
364.It Sy SockProtocol <string>
365This optional key specifies the protocol to be passed to
366.Xr socket 2 .
367The only value understood by this key at the moment is "TCP".
368.It Sy SockPathName <string>
369This optional key implies SockFamily is set to "Unix". It specifies the path to
370.Xr connect 2
371or
372.Xr bind 2
373to.
ed34e3c3
A
374.It Sy SecureSocketWithKey <string>
375This optional key is a variant of SockPathName. Instead of binding to a known
376path, a securely generated socket is created and the path is assigned to the
377environment variable that is inherited by all jobs spawned by launchd.
aa59983a 378.It Sy SockPathMode <integer>
ed34e3c3
A
379This optional key specifies the mode of the socket. Known bug: Property lists
380don't support octal, so please convert the value to decimal.
e91b9f68
A
381.It Sy Bonjour <boolean or string or array of strings>
382This optional key can be used to request that the service be registered with the
383.Xr mDNSResponder 8 .
384If the value is boolean, the service name is inferred from the SockServiceName.
ab36757d
A
385.It Sy MulticastGroup <string>
386This optional key can be used to request that the datagram socket join a multicast group.
387If the value is a hostname, then
388.Xr getaddrinfo 3
389will be used to join the correct multicast address for a given socket family.
ed34e3c3
A
390If an explicit IPv4 or IPv6 address is given, it is required that the
391SockFamily family also be set, otherwise the results are undefined.
e91b9f68
A
392.El
393.El
394.Pp
ed34e3c3
A
395.Sh DEPENDENCIES
396Unlike many bootstrapping daemons, launchd has no explicit dependency model.
397Interdependencies are expected to be solved through the use of IPC.
398It is therefore in the best interest of a job developer who expects dependents
399to define all of the sockets in the configuration file. This has the added
400benefit of making it possible to start the job based on demand instead of
401immediately.
e91b9f68
A
402.Sh EXAMPLE XML PROPERTY LISTS
403.Pp
404The following XML Property List simply keeps "exampled" running continuously:
405.Pp
406.Dl <?xml version="1.0" encoding="UTF-8"?>
407.Dl <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
408.Dl <plist version="1.0">
409.Dl <dict>
410.Dl <key>Label</key>
411.Dl <string>com.example.exampled</string>
412.Dl <key>ProgramArguments</key>
413.Dl <array>
414.Dl <string>exampled</string>
415.Dl </array>
ed34e3c3
A
416.Dl <key>KeepAlive</key>
417.Dl <true/>
e91b9f68
A
418.Dl </dict>
419.Dl </plist>
420.Pp
421.Sh FILES
422.Bl -tag -width "/System/Library/LaunchDaemons" -compact
423.It Pa ~/Library/LaunchAgents
424Per-user agents provided by the user.
425.It Pa /Library/LaunchAgents
426Per-user agents provided by the administrator.
427.It Pa /Library/LaunchDaemons
428System wide daemons provided by the administrator.
429.It Pa /System/Library/LaunchAgents
430Mac OS X Per-user agents.
431.It Pa /System/Library/LaunchDaemons
432Mac OS X System wide daemons.
433.El
434.Sh SEE ALSO
435.Xr launchctl 1 ,
436.Xr launch 3 ,
ed34e3c3
A
437.Xr launchd 8 ,
438.Xr plist 5