chiark / gitweb /
man: simplify socket-proxyd examples
[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 enable proxy-to-nginx.socket
149 # systemctl start proxy-to-nginx.socket
150 $ curl http://localhost:80/]]>
151 </programlisting>
152                         </example>
153                 </refsect2>
154                 <refsect2>
155                         <title>Indirect-Use Example</title>
156                         <para>Use a shell script to isolate the
157                         service and proxy into the same namespace.
158                         This is particularly useful for running
159                         TCP-only daemons without the daemon
160                         affecting ports on regular
161                         interfaces.</para>
162                         <example label="combined proxy and nginx socket unit">
163
164                                 <title>
165                                 /etc/systemd/system/proxy-with-nginx.socket</title>
166                                 <programlisting>
167 <![CDATA[[Socket]
168 ListenStream=80
169
170 [Install]
171 WantedBy=sockets.target]]>
172 </programlisting>
173                         </example>
174                         <example label="combined proxy and nginx service unit">
175
176                                 <title>
177                                 /etc/systemd/system/proxy-with-nginx.service</title>
178                                 <programlisting>
179 <![CDATA[[Unit]
180 After=remote-fs.target nss-lookup.target
181
182 [Service]
183 ExecStartPre=/usr/sbin/nginx -t
184 ExecStart=/usr/bin/socket-proxyd-nginx.sh
185 PrivateTmp=true
186 PrivateNetwork=true]]>
187 </programlisting>
188                         </example>
189                         <example label="shell script">
190                                 <title>
191                                 /usr/bin/socket-proxyd-nginx.sh</title>
192                                 <programlisting>
193 <![CDATA[#!/bin/sh
194 /usr/sbin/nginx
195 while [ ! -f /tmp/nginx.pid ]
196   do
197      /usr/bin/inotifywait /tmp/nginx.pid
198   done
199 exec /usr/bin/systemd-socket-proxyd localhost 8080]]>
200 </programlisting>
201                         </example>
202                         <example label="nginx configuration">
203                                 <title>
204                                 /etc/nginx/nginx.conf</title>
205                                 <programlisting>
206 <![CDATA[[...]
207 server {
208     listen       8080;
209     listen       unix:/tmp/nginx.sock;
210     [...]]]>
211 </programlisting>
212                         </example>
213                         <example label="commands">
214                                 <programlisting>
215 <![CDATA[# systemctl enable proxy-with-nginx.socket
216 # systemctl start proxy-with-nginx.socket
217 $ curl http://localhost:80/]]>
218 </programlisting>
219                         </example>
220                 </refsect2>
221         </refsect1>
222         <refsect1>
223                 <title>See Also</title>
224                 <para>
225                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
226                         <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
227                         <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
228                         <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
229                         <citerefentry><refentrytitle>socat</refentrytitle><manvolnum>1</manvolnum></citerefentry>
230                 </para>
231         </refsect1>
232 </refentry>