chiark / gitweb /
d57a59cf79958e54a1a186cb0cf0238649bbd59b
[elogind.git] / man / systemd-socket-proxyd.xml
1 <?xml version="1.0"?>
2 <!--*-nxml-*-->
3 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
4      "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5 <!--
6   This file is part of systemd.
7
8   Copyright 2013 David Strauss
9
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.
14
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.
19
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/>.
22 -->
23 <refentry id="systemd-socket-proxyd">
24         <refentryinfo>
25                 <title>systemd-socket-proxyd</title>
26                 <productname>systemd</productname>
27                 <authorgroup>
28                         <author>
29                                 <contrib>Developer</contrib>
30                                 <firstname>David</firstname>
31                                 <surname>Strauss</surname>
32                                 <email>david@davidstrauss.net</email>
33                         </author>
34                         <author>
35                                 <contrib>Developer</contrib>
36                                 <firstname>Lennart</firstname>
37                                 <surname>Poettering</surname>
38                                 <email>lennart@poettering.net</email>
39                         </author>
40                 </authorgroup>
41         </refentryinfo>
42         <refmeta>
43                 <refentrytitle>systemd-socket-proxyd</refentrytitle>
44                 <manvolnum>1</manvolnum>
45         </refmeta>
46         <refnamediv>
47                 <refname>systemd-socket-proxyd</refname>
48                 <refpurpose>Bidirectionally proxy local sockets to another (possibly remote) socket.</refpurpose>
49         </refnamediv>
50         <refsynopsisdiv>
51                 <cmdsynopsis>
52                         <command>systemd-socket-proxyd</command>
53                         <arg choice="opt" rep="repeat"><replaceable>OPTIONS</replaceable></arg>
54                         <arg choice="plain"><replaceable>HOST</replaceable>:<replaceable>PORT</replaceable></arg>
55                 </cmdsynopsis>
56                 <cmdsynopsis>
57                         <command>systemd-socket-proxyd</command>
58                         <arg choice="opt" rep="repeat"><replaceable>OPTIONS</replaceable></arg>
59                         <arg choice="plain"><replaceable>UNIX-DOMAIN-SOCKET-PATH</replaceable>
60                         </arg>
61                 </cmdsynopsis>
62         </refsynopsisdiv>
63         <refsect1>
64                 <title>Description</title>
65                 <para>
66                 <command>systemd-socket-proxyd</command> is a generic
67                 socket-activated network socket forwarder proxy daemon
68                 for IPV4, IPv6 and UNIX stream sockets. It may be used
69                 to bi-directionally forward traffic from a local listening socket to a
70                 local or remote destination socket.</para>
71
72                 <para>One use of this tool is to provide
73                 socket activation support for services that do not
74                 natively support socket activation. On behalf of the
75                 service to activate, the proxy inherits the socket
76                 from systemd, accepts each client connection, opens a
77                 connection to a configured server for each client, and
78                 then bidirectionally forwards data between the
79                 two.</para>
80                 <para>This utility's behavior is similar to
81                 <citerefentry><refentrytitle>socat</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
82                 The main differences for <command>systemd-socket-proxyd</command>
83                 are support for socket activation with
84                 <literal>Accept=false</literal> and an event-driven
85                 design that scales better with the number of
86                 connections.</para>
87         </refsect1>
88         <refsect1>
89                 <title>Options</title>
90                 <para>The following options are understood:</para>
91                 <variablelist>
92                         <varlistentry>
93                                 <term><option>-l</option></term>
94                                 <term><option>--listener</option></term>
95                                 <listitem>
96                                         <para>Restricts listening to a
97                                         single inherited socket, specified
98                                         as a file descriptor. By default,
99                                         the proxy listens on all inherited
100                                         sockets.</para>
101                                 </listitem>
102                         </varlistentry>
103                         <varlistentry>
104                                 <term><option>-h</option></term>
105                                 <term><option>--help</option></term>
106                                 <listitem>
107                                         <para>Prints a short help
108                                         text and exits.</para>
109                                 </listitem>
110                         </varlistentry>
111                         <varlistentry>
112                                 <term><option>--version</option></term>
113                                 <listitem>
114                                         <para>Prints a version
115                                         string and exits.</para>
116                                 </listitem>
117                         </varlistentry>
118                 </variablelist>
119         </refsect1>
120         <refsect1>
121                 <title>Exit status</title>
122                 <para>On success, 0 is returned, a non-zero failure
123                 code otherwise.</para>
124         </refsect1>
125         <refsect1>
126                 <title>Examples</title>
127                 <refsect2>
128                         <title>Direct-Use Example</title>
129                         <para>Use two services with a dependency
130                         and no namespace isolation.</para>
131                         <example label="proxy socket unit">
132                                 <title>/etc/systemd/system/proxy-to-nginx.socket</title>
133                                 <programlisting>
134 <![CDATA[[Socket]
135 ListenStream=80
136
137 [Install]
138 WantedBy=sockets.target]]>
139 </programlisting>
140                         </example>
141                         <example label="proxy service unit">
142                                 <title>/etc/systemd/system/proxy-to-nginx.service</title>
143                                 <programlisting>
144 <![CDATA[[Unit]
145 After=nginx.service
146 Requires=nginx.service
147
148 [Service]
149 ExecStart=/usr/bin/systemd-socket-proxyd /tmp/nginx.sock
150 PrivateTmp=true
151 PrivateNetwork=true]]>
152 </programlisting>
153                         </example>
154                         <example label="nginx configuration">
155                                 <title>/etc/nginx/nginx.conf</title>
156                                 <programlisting>
157 <![CDATA[[...]
158 server {
159     listen       unix:/tmp/nginx.sock;
160     [...]]]>
161 </programlisting>
162                         </example>
163                         <example label="commands">
164                                 <programlisting>
165 <![CDATA[# systemctl enable proxy-to-nginx.socket
166 # systemctl start proxy-to-nginx.socket
167 $ curl http://localhost:80/]]>
168 </programlisting>
169                         </example>
170                 </refsect2>
171                 <refsect2>
172                         <title>Indirect-Use Example</title>
173                         <para>Use a shell script to isolate the
174                         service and proxy into the same namespace.
175                         This is particularly useful for running
176                         TCP-only daemons without the daemon
177                         affecting ports on regular
178                         interfaces.</para>
179                         <example label="combined proxy and nginx socket unit">
180
181                                 <title>
182                                 /etc/systemd/system/proxy-with-nginx.socket</title>
183                                 <programlisting>
184 <![CDATA[[Socket]
185 ListenStream=80
186
187 [Install]
188 WantedBy=sockets.target]]>
189 </programlisting>
190                         </example>
191                         <example label="combined proxy and nginx service unit">
192
193                                 <title>
194                                 /etc/systemd/system/proxy-with-nginx.service</title>
195                                 <programlisting>
196 <![CDATA[[Unit]
197 After=remote-fs.target nss-lookup.target
198
199 [Service]
200 ExecStartPre=/usr/sbin/nginx -t
201 ExecStart=/usr/bin/socket-proxyd-nginx.sh
202 PrivateTmp=true
203 PrivateNetwork=true]]>
204 </programlisting>
205                         </example>
206                         <example label="shell script">
207                                 <title>
208                                 /usr/bin/socket-proxyd-nginx.sh</title>
209                                 <programlisting>
210 <![CDATA[#!/bin/sh
211 /usr/sbin/nginx
212 while [ ! -f /tmp/nginx.pid ]
213   do
214      /usr/bin/inotifywait /tmp/nginx.pid
215   done
216 exec /usr/bin/systemd-socket-proxyd localhost:8080]]>
217 </programlisting>
218                                 <para>Make it executable:</para>
219                                 <programlisting>
220 <![CDATA[chmod 755 /usr/bin/socket-proxyd-nginx.sh]]>
221                                 </programlisting>
222                         </example>
223                         <example label="nginx configuration">
224                                 <title>
225                                 /etc/nginx/nginx.conf</title>
226                                 <programlisting>
227 <![CDATA[[...]
228 server {
229     listen       8080;
230     listen       unix:/tmp/nginx.sock;
231     [...]]]>
232 </programlisting>
233                         </example>
234                         <example label="commands">
235                                 <programlisting>
236 <![CDATA[# systemctl enable proxy-with-nginx.socket
237 # systemctl start proxy-with-nginx.socket
238 $ curl http://localhost:80/]]>
239 </programlisting>
240                         </example>
241                 </refsect2>
242
243                 <refsect2>
244                         <title>Multiple Listeners with Multiple Destinations</title>
245                         <para>When using namespaces, it may be useful to
246                         have multiple listeners with each going to a unique
247                         destination. systemd always passes sockets into
248                         services in the order specified in the socket
249                         unit, beginning with file descriptor 3.</para>
250                         <para>In this example, port <literal>80</literal>
251                         will proxy to <literal>localhost:8080</literal>,
252                         and port <literal>443</literal> will proxy to
253                         <literal>localhost:8443</literal>.</para>
254                         <example label="proxy socket unit">
255                                 <title>/etc/systemd/system/multi-destination.socket</title>
256                                 <programlisting>
257 <![CDATA[[Socket]
258 ListenStream=80
259 ListenStream=443
260
261 [Install]
262 WantedBy=sockets.target]]>
263 </programlisting>
264                         </example>
265                         <example label="proxy service unit">
266                                 <title>/etc/systemd/system/multi-destination.service</title>
267                                 <programlisting>
268 <![CDATA[[Service]
269 ExecStart=/usr/bin/socket-proxyd-multi-destination.sh
270 PrivateTmp=true
271 PrivateNetwork=true]]>
272 </programlisting>
273                         </example>
274
275                         <example label="shell script">
276                                 <title>
277                                 /usr/bin/socket-proxyd-multi-destination.sh</title>
278                                 <programlisting>
279 <![CDATA[#!/bin/sh
280 /usr/bin/systemd-socket-proxyd --listener=3 localhost:8080 &
281 /usr/bin/systemd-socket-proxyd --listener=4 localhost:8443 &
282 wait]]>
283 </programlisting>
284                                 <para>Make it executable:</para>
285                                 <programlisting>
286 <![CDATA[chmod 755 /usr/bin/socket-proxyd-multi-destination.sh]]>
287                                 </programlisting>
288                         </example>
289
290                         <example label="commands">
291                                 <programlisting>
292 <![CDATA[# systemctl enable multi-destination.socket
293 # systemctl start multi-destination.socket
294 $ curl http://localhost/
295 $ curl https://localhost/]]>
296 </programlisting>
297                         </example>
298                 </refsect2>
299         </refsect1>
300         <refsect1>
301                 <title>See Also</title>
302                 <para>
303                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
304                         <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
305                         <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
306                         <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
307                         <citerefentry><refentrytitle>socat</refentrytitle><manvolnum>1</manvolnum></citerefentry>
308                 </para>
309         </refsect1>
310 </refentry>