chiark / gitweb /
udevadm-settle: add missing brace
[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                 </authorgroup>
35         </refentryinfo>
36         <refmeta>
37                 <refentrytitle>systemd-socket-proxyd</refentrytitle>
38                 <manvolnum>1</manvolnum>
39         </refmeta>
40         <refnamediv>
41                 <refname>systemd-socket-proxyd</refname>
42                 <refpurpose>Bidirectionally proxy local sockets to another (possibly remote) socket.</refpurpose>
43         </refnamediv>
44         <refsynopsisdiv>
45                 <cmdsynopsis>
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>
49                 </cmdsynopsis>
50                 <cmdsynopsis>
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>
54                         </arg>
55                 </cmdsynopsis>
56         </refsynopsisdiv>
57         <refsect1>
58                 <title>Description</title>
59                 <para>
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>
65
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
73                 two.</para>
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
80                 connections.</para>
81         </refsect1>
82         <refsect1>
83                 <title>Options</title>
84                 <para>The following options are understood:</para>
85                 <variablelist>
86                         <varlistentry>
87                                 <term><option>-h</option></term>
88                                 <term><option>--help</option></term>
89                                 <listitem>
90                                         <para>Prints a short help
91                                         text and exits.</para>
92                                 </listitem>
93                         </varlistentry>
94                         <varlistentry>
95                                 <term><option>--version</option></term>
96                                 <listitem>
97                                         <para>Prints a version
98                                         string and exits.</para>
99                                 </listitem>
100                         </varlistentry>
101                 </variablelist>
102         </refsect1>
103         <refsect1>
104                 <title>Exit status</title>
105                 <para>On success, 0 is returned, a non-zero failure
106                 code otherwise.</para>
107         </refsect1>
108         <refsect1>
109                 <title>Examples</title>
110                 <refsect2>
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>
116                                 <programlisting>
117 <![CDATA[[Socket]
118 ListenStream=80
119
120 [Install]
121 WantedBy=sockets.target]]>
122 </programlisting>
123                         </example>
124                         <example label="proxy service unit">
125                                 <title>/etc/systemd/system/proxy-to-nginx.service</title>
126                                 <programlisting>
127 <![CDATA[[Unit]
128 After=nginx.service
129 Requires=nginx.service
130
131 [Service]
132 ExecStart=/usr/bin/systemd-socket-proxyd /tmp/nginx.sock
133 PrivateTmp=true
134 PrivateNetwork=true]]>
135 </programlisting>
136                         </example>
137                         <example label="nginx configuration">
138                                 <title>/etc/nginx/nginx.conf</title>
139                                 <programlisting>
140 <![CDATA[[...]
141 server {
142     listen       unix:/tmp/nginx.sock;
143     [...]]]>
144 </programlisting>
145                         </example>
146                         <example label="commands">
147                                 <programlisting>
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/]]>
152 </programlisting>
153                         </example>
154                 </refsect2>
155                 <refsect2>
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
162                         interfaces.</para>
163                         <example label="combined proxy and nginx socket unit">
164
165                                 <title>
166                                 /etc/systemd/system/proxy-with-nginx.socket</title>
167                                 <programlisting>
168 <![CDATA[[Socket]
169 ListenStream=80
170
171 [Install]
172 WantedBy=sockets.target]]>
173 </programlisting>
174                         </example>
175                         <example label="combined proxy and nginx service unit">
176
177                                 <title>
178                                 /etc/systemd/system/proxy-with-nginx.service</title>
179                                 <programlisting>
180 <![CDATA[[Unit]
181 After=syslog.target remote-fs.target nss-lookup.target
182
183 [Service]
184 ExecStartPre=/usr/sbin/nginx -t
185 ExecStart=/usr/bin/socket-proxyd-nginx.sh
186 PrivateTmp=true
187 PrivateNetwork=true]]>
188 </programlisting>
189                         </example>
190                         <example label="shell script">
191                                 <title>
192                                 /usr/bin/socket-proxyd-nginx.sh</title>
193                                 <programlisting>
194 <![CDATA[#!/bin/sh
195 /usr/sbin/nginx
196 while [ ! -f /tmp/nginx.pid ]
197   do
198      /usr/bin/inotifywait /tmp/nginx.pid
199   done
200 exec /usr/bin/systemd-socket-proxyd localhost 8080]]>
201 </programlisting>
202                         </example>
203                         <example label="nginx configuration">
204                                 <title>
205                                 /etc/nginx/nginx.conf</title>
206                                 <programlisting>
207 <![CDATA[[...]
208 server {
209     listen       8080;
210     listen       unix:/tmp/nginx.sock;
211     [...]]]>
212 </programlisting>
213                         </example>
214                         <example label="commands">
215                                 <programlisting>
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/]]>
220 </programlisting>
221                         </example>
222                 </refsect2>
223         </refsect1>
224         <refsect1>
225                 <title>See Also</title>
226                 <para>
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>
232                 </para>
233         </refsect1>
234 </refentry>