3 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
4 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of systemd.
8 Copyright 2013 David Strauss
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 <refentry id="systemd-socket-proxyd">
25 <title>systemd-socket-proxyd</title>
26 <productname>systemd</productname>
29 <contrib>Developer</contrib>
30 <firstname>David</firstname>
31 <surname>Strauss</surname>
32 <email>david@davidstrauss.net</email>
37 <refentrytitle>systemd-socket-proxyd</refentrytitle>
38 <manvolnum>1</manvolnum>
41 <refname>systemd-socket-proxyd</refname>
42 <refpurpose>Bidirectionally proxy local sockets to another (possibly remote) socket.</refpurpose>
46 <command>systemd-socket-proxyd</command>
47 <arg choice="opt" rep="repeat"><replaceable>OPTIONS</replaceable></arg>
48 <arg choice="plain"><replaceable>HOST</replaceable>:<replaceable>PORT</replaceable></arg>
51 <command>systemd-socket-proxyd</command>
52 <arg choice="opt" rep="repeat"><replaceable>OPTIONS</replaceable></arg>
53 <arg choice="plain"><replaceable>UNIX-DOMAIN-SOCKET-PATH</replaceable>
58 <title>Description</title>
60 <command>systemd-socket-proxyd</command> is a generic
61 socket-activated network socket forwarder proxy daemon
62 for IPV4, IPv6 and UNIX stream sockets. It may be used
63 to bi-directionally forward traffic from a local listening socket to a
64 local or remote destination socket.</para>
66 <para>One use of this tool is to provide
67 socket activation support for services that do not
68 natively support socket activation. On behalf of the
69 service to activate, the proxy inherits the socket
70 from systemd, accepts each client connection, opens a
71 connection to a configured server for each client, and
72 then bidirectionally forwards data between the
74 <para>This utility's behavior is similar to
75 <citerefentry><refentrytitle>socat</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
76 The main differences for <command>systemd-socket-proxyd</command>
77 are support for socket activation with
78 <literal>Accept=false</literal> and an event-driven
79 design that scales better with the number of
83 <title>Options</title>
84 <para>The following options are understood:</para>
87 <term><option>-h</option></term>
88 <term><option>--help</option></term>
90 <para>Prints a short help
91 text and exits.</para>
95 <term><option>--version</option></term>
97 <para>Prints a version
98 string and exits.</para>
104 <title>Exit status</title>
105 <para>On success, 0 is returned, a non-zero failure
106 code otherwise.</para>
109 <title>Examples</title>
111 <title>Direct-Use Example</title>
112 <para>Use two services with a dependency
113 and no namespace isolation.</para>
114 <example label="proxy socket unit">
115 <title>/etc/systemd/system/proxy-to-nginx.socket</title>
121 WantedBy=sockets.target]]>
124 <example label="proxy service unit">
125 <title>/etc/systemd/system/proxy-to-nginx.service</title>
129 Requires=nginx.service
132 ExecStart=/usr/bin/systemd-socket-proxyd /tmp/nginx.sock
134 PrivateNetwork=true]]>
137 <example label="nginx configuration">
138 <title>/etc/nginx/nginx.conf</title>
142 listen unix:/tmp/nginx.sock;
146 <example label="commands">
148 <![CDATA[# systemctl --system daemon-reload
149 # systemctl start proxy-to-nginx.socket
150 # systemctl enable proxy-to-nginx.socket
151 $ curl http://localhost:80/]]>
156 <title>Indirect-Use Example</title>
157 <para>Use a shell script to isolate the
158 service and proxy into the same namespace.
159 This is particularly useful for running
160 TCP-only daemons without the daemon
161 affecting ports on regular
163 <example label="combined proxy and nginx socket unit">
166 /etc/systemd/system/proxy-with-nginx.socket</title>
172 WantedBy=sockets.target]]>
175 <example label="combined proxy and nginx service unit">
178 /etc/systemd/system/proxy-with-nginx.service</title>
181 After=syslog.target remote-fs.target nss-lookup.target
184 ExecStartPre=/usr/sbin/nginx -t
185 ExecStart=/usr/bin/socket-proxyd-nginx.sh
187 PrivateNetwork=true]]>
190 <example label="shell script">
192 /usr/bin/socket-proxyd-nginx.sh</title>
196 while [ ! -f /tmp/nginx.pid ]
198 /usr/bin/inotifywait /tmp/nginx.pid
200 exec /usr/bin/systemd-socket-proxyd localhost 8080]]>
203 <example label="nginx configuration">
205 /etc/nginx/nginx.conf</title>
210 listen unix:/tmp/nginx.sock;
214 <example label="commands">
216 <![CDATA[# systemctl --system daemon-reload
217 # systemctl start proxy-with-nginx.socket
218 # systemctl enable proxy-with-nginx.socket
219 $ curl http://localhost:80/]]>
225 <title>See Also</title>
227 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
228 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
229 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
230 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
231 <citerefentry><refentrytitle>socat</refentrytitle><manvolnum>1</manvolnum></citerefentry>