launch_socket_server for Mac
Problem: You want to accept connections on a port number under 1024 on OS X, but you don't want your server to run as root.
launch_socket_server — overview
Problem: You want to accept connections on a port number under 1024 on OS X, but you don't want your server to run as root.
Solution: Run your server with _launch_socket_server_.
_launch_socket_server_ sits in between launchd(8) and your server, using the system's APIs to proxy incoming connections from a privileged port to your unprivileged program.
It uses the launch_activate_socket API, available on OS X 10.9 and higher.
_launch_socket_server_ can proxy incoming connections to a Unix domain socket or to a local TCP port. By default, _launch_socket_server_ generates the path to a domain socket and passes that path to your program in an environment variable.
To run your server with _launch_socket_server_, begin by creating a launch daemon.
Creating and configuring a conventional launch daemon
The following configuration sets up launchd to listen on port 80. _launch_socket_server_ activates the port, runs your server program, and proxies requests to it via a UNIX domain socket. Your server is responsible for reading the path to the domain socket from the LAUNCH_PROGRAM_SOCKET_PATH environment variable and accepting connections on that socket. Pick an identifier for your server. By convention, launch daemon identifiers start with the components of a domain name you control, in reverse order, followed by the name of your server. For this example, we will use an identifier of com.example.myserver. Create an XML plist file at /Library/LaunchDaemons/.plist, replacing _identifier_ in the pathname with your server's identifier. In the plist file, specify your server's identifier, tell it to execute when loaded, and request that launchd keeps it running. Specify the user and group you want to use to run your server program. Tell launchd where to redirect your server program's stdout and stderr. (Optional, but recommended.) Specify the path to the launch_socket_server executable, your server program, and any arguments you wish to pass to your server. Define a launch daemon socket with the address and port you want to listen on. (Note: The _SockServiceName_ value may be a port number, or the name of any service defined in /etc/services.)
Configuring your server to run with launch_socket_server
Update your server's configuration to bind to the UNIX domain socket specified in the LAUNCH_PROGRAM_SOCKET_PATH environment variable, if it is set. Your server must unlink the socket before binding if the socket already exists, and should unlink the socket when the program terminates.
For more information on using domain sockets, please see the documentation for your programming environment.
Note: Your server program must run in the foreground, not forked as a background process.
Manually specifying the path to the domain socket
If you wish to specify the path to the domain socket shared by _launch_socket_server_ and your program, you may set the LAUNCH_PROGRAM_SOCKET_PATH environment variable in the launch daemon plist file.
Details
在不以 root 用户运行服务器的情况下绑定特权端口
How to install launch_socket_server
- Open Terminal (press ⌘ + Space and type “Terminal”).
- If Homebrew is not installed yet, run the command below first.
- Run this command:
Latest 10 releases
This project has no GitHub releases yet.
Prebuilt bottle platforms
Official Homebrew bottles cover:
- Apple silicon · latest macOS
- Apple silicon · macOS 26 Tahoe
- Apple silicon · macOS 15 Sequoia
- Apple silicon · macOS 14 Sonoma
- Intel · macOS 14 Sonoma
Compared with similar apps
Only public metadata is compared, with no subjective recommendation; see the compare pages for field-by-field comparisons.
| App | Version | License | Architecture | 30-day installs |
|---|---|---|---|---|
| launch_socket_server | 2.0.0 | MIT | CLI | 1 |
| mighttpd2 | 4.0.10 | BSD-3-Clause | CLI | 0 |
| purescript-language-server | v0.18.5 | MIT | CLI | 1 |
| rinetd | v0.73 | GPL-2.0-or-later | CLI | 1 |
Similar apps: Command-line Tools
mighttpd2
mighttpd2 is a lightweight HTTP server built on the Warp framework, primarily used to publish…purescript-language-server
PureScript language serverrinetd
rinetd, by Thomas Boutell and Sam Hocevar. Released under the terms of the GNU General Public…sshportal
SSH & Telnet bastion serveropenssl@4
Cryptography and SSL/TLS Toolkitxz
General-purpose data compression with high compression ratioCategories: Command-line Tools