Module Launchd
Allow an application to be managed by launchd.
Launchd is a daemon managment system used on OS X. Launchd can listen for incoming connections on sockets and spawn your server on demand. This module allows your application to retrieve the listening sockets created by launchd.
Please read the following documents:
val error_to_msg : ('a, error) Stdlib.result -> ('a, [ `Msg of string ]) Stdlib.result
val activate_socket : string -> (Unix.file_descr list, error) Stdlib.result
activate_socket name
: retrieve the file descriptors for the sockets associated with the givenname
in the .plist file. This should be called once per invocation; subsequent calls will fail with`Ealready
.For example, in the following .plist,
name
should be"Listener"
:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.recoil.dave.anotherd</string> <key>ProgramArguments</key> <array> <string>/path/to/binary</string> </array> <key>Sockets</key> <dict> <key>Listener</key> <dict> <key>SockServiceName</key> <string>8081</string> <key>SockType</key> <string>stream</string> <key>SockFamily</key> <string>IPv4</string> </dict> </dict> </dict> </plist>
Please note that launchd may bind multiple sockets (e.g. one for IPv4 and another for IPv6) and so the application must handle all the sockets returned by the call.
Please note that this call is blocking.
This call fails with:
`Enoent name
ifname
could not be found in the .plist.`Esrch
if this process is not being managed by launchd (for example if it is running from a terminal).`Ealready
if the socket has already been activated.