]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd.socket.xml
pcrlock: reject device path node shorter than its header
[thirdparty/systemd.git] / man / systemd.socket.xml
CommitLineData
514094f9 1<?xml version='1.0'?>
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
eea10b26 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
db9ecf05 4<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
1f812fea 5
d8e1613e 6<refentry id="systemd.socket" xmlns:xi="http://www.w3.org/2001/XInclude">
798d3a52
ZJS
7 <refentryinfo>
8 <title>systemd.socket</title>
9 <productname>systemd</productname>
798d3a52
ZJS
10 </refentryinfo>
11
12 <refmeta>
13 <refentrytitle>systemd.socket</refentrytitle>
14 <manvolnum>5</manvolnum>
15 </refmeta>
16
17 <refnamediv>
18 <refname>systemd.socket</refname>
19 <refpurpose>Socket unit configuration</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23 <para><filename><replaceable>socket</replaceable>.socket</filename></para>
24 </refsynopsisdiv>
25
26 <refsect1>
27 <title>Description</title>
28
29 <para>A unit configuration file whose name ends in
30 <literal>.socket</literal> encodes information about an IPC or
31 network socket or a file system FIFO controlled and supervised by
32 systemd, for socket-based activation.</para>
33
34 <para>This man page lists the configuration options specific to
35 this unit type. See
36 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
37 for the common options of all unit configuration files. The common
bdac5608
ZJS
38 configuration items are configured in the generic [Unit] and
39 [Install] sections. The socket specific configuration options are
40 configured in the [Socket] section.</para>
798d3a52
ZJS
41
42 <para>Additional options are listed in
43 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
44 which define the execution environment the
45 <option>ExecStartPre=</option>, <option>ExecStartPost=</option>,
46 <option>ExecStopPre=</option> and <option>ExecStopPost=</option>
47 commands are executed in, and in
48 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
49 which define the way the processes are terminated, and in
50 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
51 which configure resource control settings for the processes of the
52 socket.</para>
53
847af199 54 <para>For each socket unit, a matching service unit must exist,
798d3a52
ZJS
55 describing the service to start on incoming traffic on the socket
56 (see
57 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
847af199 58 for more information about .service units). The name of the
798d3a52
ZJS
59 .service unit is by default the same as the name of the .socket
60 unit, but can be altered with the <option>Service=</option> option
61 described below. Depending on the setting of the
62 <option>Accept=</option> option described below, this .service
63 unit must either be named like the .socket unit, but with the
64 suffix replaced, unless overridden with <option>Service=</option>;
65 or it must be a template unit named the same way. Example: a
66 socket file <filename>foo.socket</filename> needs a matching
67 service <filename>foo.service</filename> if
964c4eda 68 <option>Accept=no</option> is set. If
847af199 69 <option>Accept=yes</option> is set, a service template
798d3a52
ZJS
70 <filename>foo@.service</filename> must exist from which services
71 are instantiated for each incoming connection.</para>
72
45f09f93 73 <para>No implicit <varname>WantedBy=</varname> or
798d3a52
ZJS
74 <varname>RequiredBy=</varname> dependency from the socket to the
75 service is added. This means that the service may be started
76 without the socket, in which case it must be able to open sockets
77 by itself. To prevent this, an explicit
78 <varname>Requires=</varname> dependency may be added.</para>
79
80 <para>Socket units may be used to implement on-demand starting of
81 services, as well as parallelized starting of services. See the
82 blog stories linked at the end for an introduction.</para>
83
df2f5817
LP
84 <para>Note that the daemon software configured for socket activation with socket units needs to be able
85 to accept sockets from systemd, either via systemd's native socket passing interface (see
86 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
87 details about the precise protocol used and the order in which the file descriptors are passed) or via
88 traditional <citerefentry
89 project='freebsd'><refentrytitle>inetd</refentrytitle><manvolnum>8</manvolnum></citerefentry>-style
90 socket passing (i.e. sockets passed in via standard input and output, using
91 <varname>StandardInput=socket</varname> in the service file).</para>
48e6dd37 92
f8e1a7a6 93 <para>By default, network sockets allocated through <filename>.socket</filename> units are allocated in the host's network
48e6dd37
LP
94 namespace (see <citerefentry
95 project='man-pages'><refentrytitle>network_namespaces</refentrytitle><manvolnum>7</manvolnum></citerefentry>). This
96 does not mean however that the service activated by a configured socket unit has to be part of the host's network
97 namespace as well. It is supported and even good practice to run services in their own network namespace (for
98 example through <varname>PrivateNetwork=</varname>, see
99 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>), receiving only
100 the sockets configured through socket-activation from the host's namespace. In such a set-up communication within
101 the host's network namespace is only permitted through the activation sockets passed in while all sockets allocated
3d62af7d
YW
102 from the service code itself will be associated with the service's own namespace, and thus possibly subject to a
103 restrictive configuration.</para>
f8e1a7a6
LW
104
105 <para>Alternatively, it is possible to run a <filename>.socket</filename> unit in another network namespace
106 by setting <option>PrivateNetwork=yes</option> in combination with <varname>JoinsNamespaceOf=</varname>, see
107 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> and
108 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for details.</para>
798d3a52
ZJS
109 </refsect1>
110
c129bd5d 111 <refsect1>
aed5cb03
ZJS
112 <title>Automatic Dependencies</title>
113
114 <refsect2>
115 <title>Implicit Dependencies</title>
116
117 <para>The following dependencies are implicitly added:</para>
118
119 <itemizedlist>
120 <listitem><para>Socket units automatically gain a <varname>Before=</varname>
121 dependency on the service units they activate.</para></listitem>
122
e9dd6984
ZJS
123 <listitem><para>Socket units referring to file system paths (such as <constant>AF_UNIX</constant>
124 sockets or FIFOs) implicitly gain <varname>Requires=</varname> and <varname>After=</varname>
125 dependencies on all mount units necessary to access those paths.</para></listitem>
aed5cb03
ZJS
126
127 <listitem><para>Socket units using the <varname>BindToDevice=</varname>
128 setting automatically gain a <varname>BindsTo=</varname> and
129 <varname>After=</varname> dependency on the device unit
130 encapsulating the specified network interface.</para></listitem>
131 </itemizedlist>
132
133 <para>Additional implicit dependencies may be added as result of
134 execution and resource control parameters as documented in
135 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
136 and
137 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
138 </refsect2>
139
140 <refsect2>
141 <title>Default Dependencies</title>
142
143 <para>The following dependencies are added unless
144 <varname>DefaultDependencies=no</varname> is set:</para>
145
146 <itemizedlist>
147 <listitem><para>Socket units automatically gain a
148 <varname>Before=</varname> dependency on
149 <filename>sockets.target</filename>.</para></listitem>
150
151 <listitem><para>Socket units automatically gain a pair of
152 <varname>After=</varname> and <varname>Requires=</varname>
153 dependency on <filename>sysinit.target</filename>, and a pair of
154 <varname>Before=</varname> and <varname>Conflicts=</varname>
155 dependencies on <filename>shutdown.target</filename>. These
156 dependencies ensure that the socket unit is started before normal
157 services at boot, and is stopped on shutdown. Only sockets
158 involved with early boot or late system shutdown should disable
159 <varname>DefaultDependencies=</varname> option.</para></listitem>
160 </itemizedlist>
161 </refsect2>
45f09f93
JL
162 </refsect1>
163
798d3a52
ZJS
164 <refsect1>
165 <title>Options</title>
166
d8e1613e
ZJS
167 <para>Socket unit files may include [Unit] and [Install] sections, which are described in
168 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
169 </para>
170
171 <para>Socket unit files must include a [Socket] section, which carries
798d3a52
ZJS
172 information about the socket or FIFO it supervises. A number of
173 options that may be used in this section are shared with other
174 unit types. These options are documented in
78a529ca 175 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
176 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry> and
177 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
798d3a52
ZJS
178 The options specific to the [Socket] section of socket units are
179 the following:</para>
180
181 <variablelist class='unit-directives'>
182 <varlistentry>
183 <term><varname>ListenStream=</varname></term>
184 <term><varname>ListenDatagram=</varname></term>
185 <term><varname>ListenSequentialPacket=</varname></term>
186 <listitem><para>Specifies an address to listen on for a stream
187 (<constant>SOCK_STREAM</constant>), datagram
188 (<constant>SOCK_DGRAM</constant>), or sequential packet
189 (<constant>SOCK_SEQPACKET</constant>) socket, respectively.
190 The address can be written in various formats:</para>
191
192 <para>If the address starts with a slash
193 (<literal>/</literal>), it is read as file system socket in
194 the <constant>AF_UNIX</constant> socket family.</para>
195
196 <para>If the address starts with an at symbol
197 (<literal>@</literal>), it is read as abstract namespace
198 socket in the <constant>AF_UNIX</constant> family. The
199 <literal>@</literal> is replaced with a
200 <constant>NUL</constant> character before binding. For
201 details, see
202 <citerefentry project='man-pages'><refentrytitle>unix</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
203
204 <para>If the address string is a single number, it is read as
205 port number to listen on via IPv6. Depending on the value of
206 <varname>BindIPv6Only=</varname> (see below) this might result
207 in the service being available via both IPv6 and IPv4
208 (default) or just via IPv6.
209 </para>
210
211 <para>If the address string is a string in the format
69e3234d 212 <literal><replaceable>v.w.x.y</replaceable>:<replaceable>z</replaceable></literal>, it is interpreted
a07ab56a 213 as IPv4 address <replaceable>v.w.x.y</replaceable> and port <replaceable>z</replaceable>.</para>
798d3a52 214
a07ab56a
ZJS
215 <para>If the address string is a string in the format
216 <literal>[<replaceable>x</replaceable>]:<replaceable>y</replaceable></literal>, it is interpreted as
217 IPv6 address <replaceable>x</replaceable> and port <replaceable>y</replaceable>. An optional
69e3234d 218 interface scope (interface name or number) may be specified after a <literal>%</literal> symbol:
a07ab56a
ZJS
219 <literal>[<replaceable>x</replaceable>]:<replaceable>y</replaceable>%<replaceable>dev</replaceable></literal>.
220 Interface scopes are only useful with link-local addresses, because the kernel ignores them in other
221 cases. Note that if an address is specified as IPv6, it might still make the service available via
222 IPv4 too, depending on the <varname>BindIPv6Only=</varname> setting (see below).</para>
798d3a52 223
359a5bcf 224 <para>If the address string is a string in the format
a07ab56a
ZJS
225 <literal>vsock:<replaceable>x</replaceable>:<replaceable>y</replaceable></literal>, it is read as CID
226 <replaceable>x</replaceable> on a port <replaceable>y</replaceable> address in the
227 <constant>AF_VSOCK</constant> family. The CID is a unique 32-bit integer identifier in
228 <constant>AF_VSOCK</constant> analogous to an IP address. Specifying the CID is optional, and may be
db7374e1
DDM
229 set to the empty string. <literal>vsock</literal> may be replaced with
230 <literal>vsock-stream</literal>, <literal>vsock-dgram</literal> or <literal>vsock-seqpacket</literal>
231 to force usage of the corresponding socket type.</para>
359a5bcf 232
798d3a52
ZJS
233 <para>Note that <constant>SOCK_SEQPACKET</constant> (i.e.
234 <varname>ListenSequentialPacket=</varname>) is only available
235 for <constant>AF_UNIX</constant> sockets.
236 <constant>SOCK_STREAM</constant> (i.e.
237 <varname>ListenStream=</varname>) when used for IP sockets
238 refers to TCP sockets, <constant>SOCK_DGRAM</constant> (i.e.
239 <varname>ListenDatagram=</varname>) to UDP.</para>
240
b938cb90 241 <para>These options may be specified more than once, in which
798d3a52
ZJS
242 case incoming traffic on any of the sockets will trigger
243 service activation, and all listed sockets will be passed to
244 the service, regardless of whether there is incoming traffic
245 on them or not. If the empty string is assigned to any of
246 these options, the list of addresses to listen on is reset,
247 all prior uses of any of these options will have no
248 effect.</para>
249
250 <para>It is also possible to have more than one socket unit
251 for the same service when using <varname>Service=</varname>,
252 and the service will receive all the sockets configured in all
253 the socket units. Sockets configured in one unit are passed in
254 the order of configuration, but no ordering between socket
255 units is specified.</para>
256
257 <para>If an IP address is used here, it is often desirable to
258 listen on it before the interface it is configured on is up
259 and running, and even regardless of whether it will be up and
260 running at any point. To deal with this, it is recommended to
261 set the <varname>FreeBind=</varname> option described
262 below.</para></listitem>
263 </varlistentry>
264
265 <varlistentry>
266 <term><varname>ListenFIFO=</varname></term>
c758bea7
LP
267 <listitem><para>Specifies a file system FIFO (see <citerefentry
268 project='man-pages'><refentrytitle>fifo</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
269 details) to listen on. This expects an absolute file system path as argument. Behavior otherwise is
270 very similar to the <varname>ListenDatagram=</varname> directive above.</para></listitem>
798d3a52
ZJS
271 </varlistentry>
272
273 <varlistentry>
274 <term><varname>ListenSpecial=</varname></term>
275 <listitem><para>Specifies a special file in the file system to
276 listen on. This expects an absolute file system path as
277 argument. Behavior otherwise is very similar to the
278 <varname>ListenFIFO=</varname> directive above. Use this to
279 open character device nodes as well as special files in
3b121157
ZJS
280 <filename>/proc/</filename> and
281 <filename>/sys/</filename>.</para></listitem>
798d3a52
ZJS
282 </varlistentry>
283
284 <varlistentry>
285 <term><varname>ListenNetlink=</varname></term>
286 <listitem><para>Specifies a Netlink family to create a socket
287 for to listen on. This expects a short string referring to the
288 <constant>AF_NETLINK</constant> family name (such as
289 <varname>audit</varname> or <varname>kobject-uevent</varname>)
290 as argument, optionally suffixed by a whitespace followed by a
291 multicast group integer. Behavior otherwise is very similar to
292 the <varname>ListenDatagram=</varname> directive
293 above.</para></listitem>
294 </varlistentry>
295
296 <varlistentry>
297 <term><varname>ListenMessageQueue=</varname></term>
c758bea7
LP
298 <listitem><para>Specifies a POSIX message queue name to listen on (see <citerefentry
299 project='man-pages'><refentrytitle>mq_overview</refentrytitle><manvolnum>7</manvolnum></citerefentry>
300 for details). This expects a valid message queue name (i.e. beginning with
301 <literal>/</literal>). Behavior otherwise is very similar to the <varname>ListenFIFO=</varname>
302 directive above. On Linux message queue descriptors are actually file descriptors and can be
303 inherited between processes.</para></listitem>
798d3a52
ZJS
304 </varlistentry>
305
8c7c9839
PS
306 <varlistentry>
307 <term><varname>ListenUSBFunction=</varname></term>
3d314510 308 <listitem><para>Specifies a <ulink
0e685823 309 url="https://docs.kernel.org/usb/functionfs.html">USB
00bb64ec 310 FunctionFS</ulink> endpoints location to listen on, for
3d314510 311 implementation of USB gadget functions. This expects an
885a4e6c 312 absolute file system path of a FunctionFS mount point as the argument.
00bb64ec 313 Behavior otherwise is very similar to the <varname>ListenFIFO=</varname>
a8eaaee7 314 directive above. Use this to open the FunctionFS endpoint
3d314510
LP
315 <filename>ep0</filename>. When using this option, the
316 activated service has to have the
22065311
ZJS
317 <varname>USBFunctionDescriptors=</varname> and
318 <varname>USBFunctionStrings=</varname> options set.
ec07c3c8
AK
319 </para>
320
321 <xi:include href="version-info.xml" xpointer="v227"/></listitem>
8c7c9839
PS
322 </varlistentry>
323
74bb646e
SS
324 <varlistentry>
325 <term><varname>SocketProtocol=</varname></term>
3f690705
MBN
326 <listitem><para>Takes one of <option>udplite</option>,
327 <option>sctp</option> or <option>mptcp</option>. The socket will use
328 the UDP-Lite (<constant>IPPROTO_UDPLITE</constant>), SCTP
329 (<constant>IPPROTO_SCTP</constant>) or MPTCP
330 (<constant>IPPROTO_MPTCP</constant>) protocol, respectively.</para>
ec07c3c8
AK
331
332 <xi:include href="version-info.xml" xpointer="v229"/>
74bb646e
SS
333 </listitem>
334 </varlistentry>
335
798d3a52
ZJS
336 <varlistentry>
337 <term><varname>BindIPv6Only=</varname></term>
a7c64e14 338 <listitem><para>Takes one of <option>default</option>,
798d3a52
ZJS
339 <option>both</option> or <option>ipv6-only</option>. Controls
340 the IPV6_V6ONLY socket option (see
3ba3a79d 341 <citerefentry project='die-net'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry>
798d3a52
ZJS
342 for details). If <option>both</option>, IPv6 sockets bound
343 will be accessible via both IPv4 and IPv6. If
344 <option>ipv6-only</option>, they will be accessible via IPv6
345 only. If <option>default</option> (which is the default,
346 surprise!), the system wide default setting is used, as
347 controlled by
348 <filename>/proc/sys/net/ipv6/bindv6only</filename>, which in
349 turn defaults to the equivalent of
350 <option>both</option>.</para>
351 </listitem>
352 </varlistentry>
353
354 <varlistentry>
355 <term><varname>Backlog=</varname></term>
da890466 356 <listitem><para>Takes an unsigned 32-bit integer argument. Specifies the number of connections to
768fcd77
LP
357 queue that have not been accepted yet. This setting matters only for stream and sequential packet
358 sockets. See
359 <citerefentry><refentrytitle>listen</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
bf63dadb
ZJS
360 details. Defaults to 4294967295. Note that this value is silently capped by the
361 <literal>net.core.somaxconn</literal> sysctl, which typically defaults to 4096, so typically
362 the sysctl is the setting that actually matters.</para></listitem>
798d3a52
ZJS
363 </varlistentry>
364
365 <varlistentry>
366 <term><varname>BindToDevice=</varname></term>
e9dd6984
ZJS
367 <listitem><para>Specifies a network interface name to bind this socket to. If set, traffic will only
368 be accepted from the specified network interfaces. This controls the
369 <constant>SO_BINDTODEVICE</constant> socket option (see <citerefentry
370 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
371 details). If this option is used, an implicit dependency from this socket unit on the network
372 interface device unit is created
373 (see <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
374 Note that setting this parameter might result in additional dependencies to be added to the unit (see
c129bd5d 375 above).</para></listitem>
798d3a52
ZJS
376 </varlistentry>
377
378 <varlistentry>
379 <term><varname>SocketUser=</varname></term>
380 <term><varname>SocketGroup=</varname></term>
381
e9dd6984 382 <listitem><para>Takes a UNIX user/group name. When specified, all <constant>AF_UNIX</constant>
3eec82f6 383 sockets, FIFO nodes, and message queues are owned by the specified user and group. If unset (the
e9dd6984
ZJS
384 default), the nodes are owned by the root user/group (if run in system context) or the invoking
385 user/group (if run in user context). If only a user is specified but no group, then the group is
ec07c3c8
AK
386 derived from the user's default group.</para>
387
388 <xi:include href="version-info.xml" xpointer="v214"/></listitem>
798d3a52
ZJS
389 </varlistentry>
390
391 <varlistentry>
392 <term><varname>SocketMode=</varname></term>
3eec82f6
DM
393 <listitem><para>If listening on a file system socket, FIFO, or message queue, this option specifies
394 the file system access mode used when creating the file node. Takes an access mode in octal notation.
395 Defaults to 0666.</para></listitem>
798d3a52
ZJS
396 </varlistentry>
397
398 <varlistentry>
399 <term><varname>DirectoryMode=</varname></term>
400 <listitem><para>If listening on a file system socket or FIFO,
401 the parent directories are automatically created if needed.
402 This option specifies the file system access mode used when
403 creating these directories. Takes an access mode in octal
404 notation. Defaults to 0755.</para></listitem>
405 </varlistentry>
406
407 <varlistentry>
408 <term><varname>Accept=</varname></term>
c91d2b43
LP
409 <listitem><para>Takes a boolean argument. If yes, a service instance is spawned for each incoming
410 connection and only the connection socket is passed to it. If no, all listening sockets themselves
411 are passed to the started service unit, and only one service unit is spawned for all connections
412 (also see above). This value is ignored for datagram sockets and FIFOs where a single service unit
fbf43297
LP
413 unconditionally handles all incoming traffic. Defaults to <option>no</option>.</para>
414
415 <para>Typically, for performance sensitive services, a choice of <option>Accept=no</option> is
416 preferable, since that way only the first connection will have to pay the activation resource
417 cost. On the other hand, for sporadically used services <option>Accept=yes</option> can be preferable
418 as it simplifies the implementation (as the service program code only has to process a single
419 connection instead of handling multiple) and enables stronger security (since the various sandboxing
420 options can be used to isolate parallel connections from each other, as each is serviced by a
421 separate service instance and process).</para>
422
423 <para>A service listening on an <constant>AF_UNIX</constant> socket may, but does not need to, call
c91d2b43
LP
424 <citerefentry><refentrytitle>close</refentrytitle><manvolnum>2</manvolnum></citerefentry> on the
425 received socket before exiting. However, it must not unlink the socket from a file system. It should
426 not invoke
427 <citerefentry><refentrytitle>shutdown</refentrytitle><manvolnum>2</manvolnum></citerefentry> on
428 sockets it got with <varname>Accept=no</varname>, but it may do so for sockets it got with
fbf43297
LP
429 <varname>Accept=yes</varname> set.</para>
430
431 <para>Setting <varname>Accept=yes</varname> is in particular useful for allowing daemons designed for
432 usage with <citerefentry
c91d2b43
LP
433 project='freebsd'><refentrytitle>inetd</refentrytitle><manvolnum>8</manvolnum></citerefentry> to work
434 unmodified with systemd socket activation.</para>
3b1c5241 435
dbbf0618
LP
436 <para>Note that depending on this setting the services activated by units of this type are either
437 regular services (in case of <varname>Accept=</varname><option>no</option>) or instances of templated
438 services (in case of <varname>Accept=</varname><option>yes</option>). See the Description section
439 above for a more detailed discussion of the naming rules of triggered services.</para>
440
608bfe76 441 <para>For IPv4 and IPv6 connections, the <varname>$REMOTE_ADDR</varname> environment variable will
bfb1f9e2
LP
442 contain the remote IP address, and <varname>$REMOTE_PORT</varname> will contain the remote port
443 number. These two variables correspond to those defined by the CGI interface for web services (see
444 <ulink url="https://datatracker.ietf.org/doc/html/rfc3875">RFC 3875</ulink>).</para>
c91d2b43 445
608bfe76
KS
446 <para>For <constant>AF_UNIX</constant> socket connections, the <varname>$REMOTE_ADDR</varname>
447 environment variable will contain either the remote socket's file system path starting with a slash
448 (<literal>/</literal>) or its address in the abstract namespace starting with an at symbol
bfb1f9e2
LP
449 (<literal>@</literal>). If the socket is unnamed, <varname>$REMOTE_ADDR</varname> will not be
450 set.</para>
451
fbf43297
LP
452 <para>If <varname>Accept=yes</varname> is used, the activated service process will have set the
453 <varname>$SO_COOKIE</varname> environment variable to the Linux socket cookie, formatted as decimal
454 integer. The socket cookie can otherwise be acquired via <citerefentry
bfb1f9e2 455 project='man-pages'><refentrytitle>getsockopt</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
608bfe76 456
c91d2b43
LP
457 <para>It is recommended to set <varname>CollectMode=inactive-or-failed</varname> for service
458 instances activated via <varname>Accept=yes</varname>, to ensure that failed connection services are
459 cleaned up and released from memory, and do not accumulate.</para></listitem>
798d3a52
ZJS
460 </varlistentry>
461
55301ec0
LP
462 <varlistentry>
463 <term><varname>Writable=</varname></term>
464 <listitem><para>Takes a boolean argument. May only be used in
465 conjunction with <varname>ListenSpecial=</varname>. If true,
466 the specified special file is opened in read-write mode, if
ec07c3c8
AK
467 false, in read-only mode. Defaults to false.</para>
468
469 <xi:include href="version-info.xml" xpointer="v227"/></listitem>
55301ec0
LP
470 </varlistentry>
471
3e5f04bf
RM
472 <varlistentry>
473 <term><varname>FlushPending=</varname></term>
474 <listitem><para>Takes a boolean argument. May only be used when
475 <option>Accept=no</option>. If yes, the socket's buffers are cleared after the
476 triggered service exited. This causes any pending data to be
477 flushed and any pending incoming connections to be rejected. If no, the
44855c77 478 socket's buffers will not be cleared, permitting the service to handle any
3e5f04bf
RM
479 pending connections after restart, which is the usually expected behaviour.
480 Defaults to <option>no</option>.
ec07c3c8
AK
481 </para>
482
483 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
3e5f04bf
RM
484 </varlistentry>
485
798d3a52
ZJS
486 <varlistentry>
487 <term><varname>MaxConnections=</varname></term>
6b014a2a
MY
488 <listitem><para>The maximum number of connections to simultaneously run services instances for, when
489 <option>Accept=yes</option> is set. If more concurrent connections are coming in, they will be refused
490 until at least one existing connection is terminated. This setting has no effect on sockets configured
491 with <option>Accept=no</option> or datagram sockets. Defaults to 64.</para></listitem>
798d3a52
ZJS
492 </varlistentry>
493
494 <varlistentry>
9d565427 495 <term><varname>MaxConnectionsPerSource=</varname></term>
48930a5d
LP
496 <listitem><para>The maximum number of connections for a service per source IP address (in case of
497 IPv4/IPv6), per source CID (in case of <constant>AF_VSOCK</constant>), or source UID (in case of
498 <constant>AF_UNIX</constant>). This is very similar to the <varname>MaxConnections=</varname>
6b014a2a 499 directive above. Defaults to 0, i.e. disabled.</para>
ec07c3c8
AK
500
501 <xi:include href="version-info.xml" xpointer="v232"/>
9d565427
SS
502 </listitem>
503 </varlistentry>
504
505 <varlistentry>
798d3a52 506 <term><varname>KeepAlive=</varname></term>
e9dd6984
ZJS
507 <listitem><para>Takes a boolean argument. If true, the TCP/IP stack will send a keep alive message
508 after 2h (depending on the configuration of
509 <filename>/proc/sys/net/ipv4/tcp_keepalive_time</filename>) for all TCP streams accepted on this
510 socket. This controls the <constant>SO_KEEPALIVE</constant> socket option (see <citerefentry
511 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
512 the <ulink url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP Keepalive
513 HOWTO</ulink> for details.) Defaults to <option>false</option>.</para></listitem>
798d3a52
ZJS
514 </varlistentry>
515
516 <varlistentry>
517 <term><varname>KeepAliveTimeSec=</varname></term>
b938cb90 518 <listitem><para>Takes time (in seconds) as argument. The connection needs to remain
798d3a52
ZJS
519 idle before TCP starts sending keepalive probes. This controls the TCP_KEEPIDLE
520 socket option (see
3ba3a79d 521 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
798d3a52
ZJS
522 and the <ulink
523 url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP
524 Keepalive HOWTO</ulink> for details.)
ec07c3c8
AK
525 Default value is 7200 seconds (2 hours).</para>
526
527 <xi:include href="version-info.xml" xpointer="v216"/></listitem>
798d3a52
ZJS
528 </varlistentry>
529
530 <varlistentry>
531 <term><varname>KeepAliveIntervalSec=</varname></term>
e9dd6984
ZJS
532 <listitem><para>Takes time (in seconds) as argument between individual keepalive probes, if the
533 socket option <constant>SO_KEEPALIVE</constant> has been set on this socket. This controls the
534 <constant>TCP_KEEPINTVL</constant> socket option (see <citerefentry
535 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
536 the <ulink url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP Keepalive
ec07c3c8
AK
537 HOWTO</ulink> for details.) Default value is 75 seconds.</para>
538
539 <xi:include href="version-info.xml" xpointer="v216"/></listitem>
798d3a52
ZJS
540 </varlistentry>
541
542 <varlistentry>
543 <term><varname>KeepAliveProbes=</varname></term>
7ca41557 544 <listitem><para>Takes an integer as argument. It is the number of
798d3a52
ZJS
545 unacknowledged probes to send before considering the
546 connection dead and notifying the application layer. This
547 controls the TCP_KEEPCNT socket option (see
3ba3a79d 548 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
798d3a52
ZJS
549 and the <ulink
550 url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP
6870daff 551 Keepalive HOWTO</ulink> for details.) Default value is
ec07c3c8
AK
552 9.</para>
553
554 <xi:include href="version-info.xml" xpointer="v216"/></listitem>
798d3a52
ZJS
555 </varlistentry>
556
557 <varlistentry>
558 <term><varname>NoDelay=</varname></term>
559 <listitem><para>Takes a boolean argument. TCP Nagle's
560 algorithm works by combining a number of small outgoing
561 messages, and sending them all at once. This controls the
562 TCP_NODELAY socket option (see
e9dd6984 563 <citerefentry project='die-net'><refentrytitle>tcp</refentrytitle><manvolnum>7</manvolnum></citerefentry>).
ec07c3c8
AK
564 Defaults to <option>false</option>.</para>
565
566 <xi:include href="version-info.xml" xpointer="v216"/></listitem>
798d3a52
ZJS
567 </varlistentry>
568
569 <varlistentry>
570 <term><varname>Priority=</varname></term>
e9dd6984
ZJS
571 <listitem><para>Takes an integer argument controlling the priority for all traffic sent from this
572 socket. This controls the <constant>SO_PRIORITY</constant> socket option (see <citerefentry
573 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
574 details.).</para></listitem>
798d3a52
ZJS
575 </varlistentry>
576
577 <varlistentry>
578 <term><varname>DeferAcceptSec=</varname></term>
579
580 <listitem><para>Takes time (in seconds) as argument. If set,
581 the listening process will be awakened only when data arrives
582 on the socket, and not immediately when connection is
583 established. When this option is set, the
584 <constant>TCP_DEFER_ACCEPT</constant> socket option will be
585 used (see
3ba3a79d 586 <citerefentry project='die-net'><refentrytitle>tcp</refentrytitle><manvolnum>7</manvolnum></citerefentry>),
798d3a52
ZJS
587 and the kernel will ignore initial ACK packets without any
588 data. The argument specifies the approximate amount of time
589 the kernel should wait for incoming data before falling back
2dd67817 590 to the normal behavior of honoring empty ACK packets. This
798d3a52
ZJS
591 option is beneficial for protocols where the client sends the
592 data first (e.g. HTTP, in contrast to SMTP), because the
593 server process will not be woken up unnecessarily before it
594 can take any action.
595 </para>
596
597 <para>If the client also uses the
598 <constant>TCP_DEFER_ACCEPT</constant> option, the latency of
599 the initial connection may be reduced, because the kernel will
600 send data in the final packet establishing the connection (the
601 third packet in the "three-way handshake").</para>
602
603 <para>Disabled by default.</para>
ec07c3c8
AK
604
605 <xi:include href="version-info.xml" xpointer="v216"/>
798d3a52
ZJS
606 </listitem>
607 </varlistentry>
608
609 <varlistentry>
610 <term><varname>ReceiveBuffer=</varname></term>
611 <term><varname>SendBuffer=</varname></term>
e9dd6984
ZJS
612 <listitem><para>Takes an integer argument controlling the receive or send buffer sizes of this
613 socket, respectively. This controls the <constant>SO_RCVBUF</constant> and
614 <constant>SO_SNDBUF</constant> socket options (see <citerefentry
615 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
616 details.). The usual suffixes K, M, G are supported and are understood to the base of
617 1024.</para></listitem>
798d3a52
ZJS
618 </varlistentry>
619
620 <varlistentry>
621 <term><varname>IPTOS=</varname></term>
c6a79245
LP
622 <listitem><para>Takes an integer argument controlling the IP Type-Of-Service field for packets
623 generated from this socket. This controls the <constant>IP_TOS</constant> socket option (see
624 <citerefentry
625 project='die-net'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
626 details.). Either a numeric string or one of <option>low-delay</option>, <option>throughput</option>,
627 <option>reliability</option> or <option>low-cost</option> may be specified.</para></listitem>
798d3a52
ZJS
628 </varlistentry>
629
630 <varlistentry>
631 <term><varname>IPTTL=</varname></term>
c6a79245
LP
632 <listitem><para>Takes an integer argument controlling the IPv4 Time-To-Live/IPv6 Hop-Count field for
633 packets generated from this socket. This sets the
634 <constant>IP_TTL</constant>/<constant>IPV6_UNICAST_HOPS</constant> socket options (see <citerefentry
635 project='die-net'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
636 <citerefentry
637 project='die-net'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
638 details.)</para></listitem>
798d3a52
ZJS
639 </varlistentry>
640
641 <varlistentry>
642 <term><varname>Mark=</varname></term>
e9dd6984
ZJS
643 <listitem><para>Takes an integer value. Controls the firewall mark of packets generated by this
644 socket. This can be used in the firewall logic to filter packets from this socket. This sets the
645 <constant>SO_MARK</constant> socket option. See <citerefentry
646 project='die-net'><refentrytitle>iptables</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
647 details.</para></listitem>
798d3a52
ZJS
648 </varlistentry>
649
650 <varlistentry>
651 <term><varname>ReusePort=</varname></term>
e9dd6984
ZJS
652 <listitem><para>Takes a boolean value. If true, allows multiple
653 <citerefentry><refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum></citerefentry>s to this TCP
654 or UDP port. This controls the <constant>SO_REUSEPORT</constant> socket option. See <citerefentry
655 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
ec07c3c8
AK
656 details.</para>
657
658 <xi:include href="version-info.xml" xpointer="v206"/></listitem>
798d3a52
ZJS
659 </varlistentry>
660
661 <varlistentry>
662 <term><varname>SmackLabel=</varname></term>
663 <term><varname>SmackLabelIPIn=</varname></term>
664 <term><varname>SmackLabelIPOut=</varname></term>
665 <listitem><para>Takes a string value. Controls the extended
666 attributes <literal>security.SMACK64</literal>,
667 <literal>security.SMACK64IPIN</literal> and
668 <literal>security.SMACK64IPOUT</literal>, respectively, i.e.
669 the security label of the FIFO, or the security label for the
670 incoming or outgoing connections of the socket, respectively.
671 See <ulink
0e685823 672 url="https://docs.kernel.org/admin-guide/LSM/Smack.html">Smack</ulink>
ec07c3c8
AK
673 for details.</para>
674
675 <xi:include href="version-info.xml" xpointer="v196"/></listitem>
798d3a52
ZJS
676 </varlistentry>
677
cc174775
LP
678 <varlistentry>
679 <term><varname>XAttrEntryPoint=</varname></term>
680 <term><varname>XAttrListen=</varname></term>
681 <term><varname>XAttrAccept=</varname></term>
682 <listitem><para>Set an extended attribute on the socket, in the form
683 <literal><replaceable>NAME</replaceable>=<replaceable>VALUE</replaceable></literal>. The extended
684 attribute's name must be in the <literal>user.</literal> namespace, i.e. begin with the four
685 characters <literal>user.</literal>. Specifiers are expanded in both the name and the value, see
686 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
687 details on the available specifiers. These settings may be used more than once to set multiple
688 extended attributes; assigning the empty string resets the list.</para>
689
690 <para>The three variables control where the extended attributes are applied:
691 <varname>XAttrEntryPoint=</varname> sets them on the file-system inode an
692 <constant>AF_UNIX</constant> socket is bound to (i.e. the socket node visible in the file system at
693 the specified listening path; this only applies to <constant>AF_UNIX</constant> sockets),
694 <varname>XAttrListen=</varname> sets them on the listening socket, and
695 <varname>XAttrAccept=</varname> sets them on the connection sockets accepted off the listening socket
696 (and is thus only relevant in combination with
697 <varname>Accept=</varname><literal>yes</literal>).</para>
698
699 <para>This is primarily useful to tag sockets so that they can be discovered and classified by other
700 tools. For example, Varlink entrypoint sockets are supposed to be tagged with
701 <literal>user.varlink=entrypoint</literal> via <varname>XAttrEntryPoint=</varname>, which makes them
702 discoverable via <command>varlinkctl list-sockets</command>, see
703 <citerefentry><refentrytitle>varlinkctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para>
704
705 <para>These settings require kernel support for extended attributes on socket inodes (available since
706 Linux 7.0). Extended attributes that cannot be applied are logged at debug level and otherwise
707 ignored.</para>
708
709 <xi:include href="version-info.xml" xpointer="v262"/></listitem>
710 </varlistentry>
711
798d3a52
ZJS
712 <varlistentry>
713 <term><varname>SELinuxContextFromNet=</varname></term>
714 <listitem><para>Takes a boolean argument. When true, systemd
715 will attempt to figure out the SELinux label used for the
716 instantiated service from the information handed by the peer
717 over the network. Note that only the security level is used
718 from the information provided by the peer. Other parts of the
719 resulting SELinux context originate from either the target
720 binary that is effectively triggered by socket unit or from
721 the value of the <varname>SELinuxContext=</varname> option.
49590d67
MS
722 This configuration option applies only when activated service
723 is passed in single socket file descriptor, i.e. service
724 instances that have standard input connected to a socket or
725 services triggered by exactly one socket unit. Also note
726 that this option is useful only when MLS/MCS SELinux policy
727 is deployed. Defaults to
ec07c3c8
AK
728 <literal>false</literal>. </para>
729
730 <xi:include href="version-info.xml" xpointer="v217"/></listitem>
798d3a52
ZJS
731 </varlistentry>
732
733 <varlistentry>
734 <term><varname>PipeSize=</varname></term>
735 <listitem><para>Takes a size in bytes. Controls the pipe
736 buffer size of FIFOs configured in this socket unit. See
737 <citerefentry><refentrytitle>fcntl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
738 for details. The usual suffixes K, M, G are supported and are
739 understood to the base of 1024.</para></listitem>
740 </varlistentry>
741
742 <varlistentry>
743 <term><varname>MessageQueueMaxMessages=</varname>,
744 <varname>MessageQueueMessageSize=</varname></term>
745 <listitem><para>These two settings take integer values and
746 control the mq_maxmsg field or the mq_msgsize field,
747 respectively, when creating the message queue. Note that
748 either none or both of these variables need to be set. See
3ba3a79d 749 <citerefentry project='die-net'><refentrytitle>mq_setattr</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52
ZJS
750 for details.</para></listitem>
751 </varlistentry>
752
753 <varlistentry>
754 <term><varname>FreeBind=</varname></term>
c6a79245
LP
755 <listitem><para>Takes a boolean value. Controls whether the socket can be bound to non-local IP
756 addresses. This is useful to configure sockets listening on specific IP addresses before those IP
757 addresses are successfully configured on a network interface. This sets the
758 <constant>IP_FREEBIND</constant>/<constant>IPV6_FREEBIND</constant> socket option. For robustness
759 reasons it is recommended to use this option whenever you bind a socket to a specific IP
760 address. Defaults to <option>false</option>.</para></listitem>
798d3a52
ZJS
761 </varlistentry>
762
763 <varlistentry>
764 <term><varname>Transparent=</varname></term>
765 <listitem><para>Takes a boolean value. Controls the
c6a79245 766 <constant>IP_TRANSPARENT</constant>/<constant>IPV6_TRANSPARENT</constant> socket option. Defaults to
798d3a52
ZJS
767 <option>false</option>.</para></listitem>
768 </varlistentry>
769
770 <varlistentry>
771 <term><varname>Broadcast=</varname></term>
e9dd6984
ZJS
772 <listitem><para>Takes a boolean value. This controls the <constant>SO_BROADCAST</constant> socket
773 option, which allows broadcast datagrams to be sent from this socket. Defaults to
798d3a52
ZJS
774 <option>false</option>.</para></listitem>
775 </varlistentry>
776
777 <varlistentry>
778 <term><varname>PassCredentials=</varname></term>
e9dd6984
ZJS
779 <listitem><para>Takes a boolean value. This controls the <constant>SO_PASSCRED</constant> socket
780 option, which allows <constant>AF_UNIX</constant> sockets to receive the credentials of the sending
781 process in an ancillary message. Defaults to <option>false</option>.</para></listitem>
798d3a52
ZJS
782 </varlistentry>
783
35462aa1
MY
784 <varlistentry>
785 <term><varname>PassPIDFD=</varname></term>
786
787 <listitem><para>Takes a boolean value. This controls the <constant>SO_PASSPIDFD</constant> socket
788 option, which allows <constant>AF_UNIX</constant> sockets to receive the pidfd of the sending
789 process in an ancillary message. Defaults to <option>false</option>.</para>
790
791 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
792 </varlistentry>
793
798d3a52
ZJS
794 <varlistentry>
795 <term><varname>PassSecurity=</varname></term>
e9dd6984
ZJS
796 <listitem><para>Takes a boolean value. This controls the <constant>SO_PASSSEC</constant> socket
797 option, which allows <constant>AF_UNIX</constant> sockets to receive the security context of the
798 sending process in an ancillary message. Defaults to <option>false</option>.</para></listitem>
798d3a52
ZJS
799 </varlistentry>
800
a3d19f5d
LP
801 <varlistentry>
802 <term><varname>PassPacketInfo=</varname></term>
803 <listitem><para>Takes a boolean value. This controls the <constant>IP_PKTINFO</constant>,
2d6d4136
LP
804 <constant>IPV6_RECVPKTINFO</constant>, <constant>NETLINK_PKTINFO</constant> or
805 <constant>PACKET_AUXDATA</constant> socket options, which enable reception of additional per-packet
806 metadata as ancillary message, on <constant>AF_INET</constant>, <constant>AF_INET6</constant>,
807 <constant>AF_UNIX</constant> and <constant>AF_PACKET</constant> sockets. Defaults to
ec07c3c8
AK
808 <option>false</option>.</para>
809
810 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
a3d19f5d
LP
811 </varlistentry>
812
5c12797f
MY
813 <varlistentry>
814 <term><varname>AcceptFileDescriptors=</varname></term>
815
816 <listitem><para>Takes a boolean value. This controls the <constant>SO_PASSRIGHTS</constant> socket
817 option, which when disabled prohibits the peer from sending <constant>SCM_RIGHTS</constant>
818 ancillary messages (aka file descriptors) via <constant>AF_UNIX</constant> sockets. Defaults to
819 <option>true</option>.</para>
820
821 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
822 </varlistentry>
823
95923d7e
LP
824 <varlistentry>
825 <term><varname>Timestamping=</varname></term>
826 <listitem><para>Takes one of <literal>off</literal>, <literal>us</literal> (alias:
e503019b 827 <literal>usec</literal>, <literal>μs</literal>) or <literal>ns</literal> (alias:
95923d7e
LP
828 <literal>nsec</literal>). This controls the <constant>SO_TIMESTAMP</constant> or
829 <constant>SO_TIMESTAMPNS</constant> socket options, and enables whether ingress network traffic shall
ec07c3c8
AK
830 carry timestamping metadata. Defaults to <option>off</option>.</para>
831
832 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
95923d7e
LP
833 </varlistentry>
834
798d3a52
ZJS
835 <varlistentry>
836 <term><varname>TCPCongestion=</varname></term>
e9dd6984 837 <listitem><para>Takes a string value. Controls the TCP congestion algorithm used by this
a7d8cacc 838 socket. Should be one of <literal>westwood</literal>, <literal>reno</literal>,
e9dd6984
ZJS
839 <literal>cubic</literal>, <literal>lp</literal> or any other available algorithm supported by the IP
840 stack. This setting applies only to stream sockets.</para></listitem>
798d3a52
ZJS
841 </varlistentry>
842
843 <varlistentry>
844 <term><varname>ExecStartPre=</varname></term>
845 <term><varname>ExecStartPost=</varname></term>
846 <listitem><para>Takes one or more command lines, which are
847 executed before or after the listening sockets/FIFOs are
848 created and bound, respectively. The first token of the
849 command line must be an absolute filename, then followed by
850 arguments for the process. Multiple command lines may be
851 specified following the same scheme as used for
852 <varname>ExecStartPre=</varname> of service unit
853 files.</para></listitem>
854 </varlistentry>
855
856 <varlistentry>
857 <term><varname>ExecStopPre=</varname></term>
858 <term><varname>ExecStopPost=</varname></term>
859 <listitem><para>Additional commands that are executed before
860 or after the listening sockets/FIFOs are closed and removed,
861 respectively. Multiple command lines may be specified
862 following the same scheme as used for
863 <varname>ExecStartPre=</varname> of service unit
864 files.</para></listitem>
865 </varlistentry>
866
867 <varlistentry>
868 <term><varname>TimeoutSec=</varname></term>
869 <listitem><para>Configures the time to wait for the commands
870 specified in <varname>ExecStartPre=</varname>,
871 <varname>ExecStartPost=</varname>,
872 <varname>ExecStopPre=</varname> and
873 <varname>ExecStopPost=</varname> to finish. If a command does
874 not exit within the configured time, the socket will be
875 considered failed and be shut down again. All commands still
876 running will be terminated forcibly via
877 <constant>SIGTERM</constant>, and after another delay of this
878 time with <constant>SIGKILL</constant>. (See
879 <option>KillMode=</option> in
880 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.)
881 Takes a unit-less value in seconds, or a time span value such
882 as "5min 20s". Pass <literal>0</literal> to disable the
883 timeout logic. Defaults to
884 <varname>DefaultTimeoutStartSec=</varname> from the manager
885 configuration file (see
886 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
887 </para></listitem>
888 </varlistentry>
889
890 <varlistentry>
891 <term><varname>Service=</varname></term>
892 <listitem><para>Specifies the service unit name to activate on
893 incoming traffic. This setting is only allowed for sockets
894 with <varname>Accept=no</varname>. It defaults to the service
895 that bears the same name as the socket (with the suffix
896 replaced). In most cases, it should not be necessary to use
c129bd5d
LP
897 this option. Note that setting this parameter might result in
898 additional dependencies to be added to the unit (see
899 above).</para></listitem>
798d3a52
ZJS
900 </varlistentry>
901
902 <varlistentry>
903 <term><varname>RemoveOnStop=</varname></term>
e9dd6984
ZJS
904 <listitem><para>Takes a boolean argument. If enabled, any file nodes created by this socket unit are
905 removed when it is stopped. This applies to <constant>AF_UNIX</constant> sockets in the file system,
906 POSIX message queues, FIFOs, as well as any symlinks to them configured with
907 <varname>Symlinks=</varname>. Normally, it should not be necessary to use this option, and is not
908 recommended as services might continue to run after the socket unit has been terminated and it should
909 still be possible to communicate with them via their file system node. Defaults to
ec07c3c8
AK
910 off.</para>
911
912 <xi:include href="version-info.xml" xpointer="v214"/></listitem>
798d3a52
ZJS
913 </varlistentry>
914
915 <varlistentry>
916 <term><varname>Symlinks=</varname></term>
3ecc7fc3
LP
917 <listitem><para>Takes a list of file system paths. The specified paths will be created as symlinks to the
918 <constant>AF_UNIX</constant> socket path or FIFO path of this socket unit. If this setting is used, only one
919 <constant>AF_UNIX</constant> socket in the file system or one FIFO may be configured for the socket unit. Use
920 this option to manage one or more symlinked alias names for a socket, binding their lifecycle together. Note
921 that if creation of a symlink fails this is not considered fatal for the socket unit, and the socket unit may
922 still start. If an empty string is assigned, the list of paths is reset. Defaults to an empty
ec07c3c8
AK
923 list.</para>
924
925 <xi:include href="version-info.xml" xpointer="v214"/></listitem>
798d3a52
ZJS
926 </varlistentry>
927
8dd4c05b
LP
928 <varlistentry>
929 <term><varname>FileDescriptorName=</varname></term>
daa78907
MY
930 <listitem><para>Assigns a name to all file descriptors this socket unit encapsulates.
931 This is useful to help activated services identify specific file descriptors, if multiple fds are passed.
932 Services may use the
8dd4c05b 933 <citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>
daa78907
MY
934 call to acquire the names configured for the received file descriptors. Names may contain any ASCII character,
935 but must exclude control characters and <literal>:</literal>, and must be at most 255 characters in length.
936 If this setting is not used, the file descriptor name defaults to the name of the socket unit
937 (including its <filename>.socket</filename> suffix) when <varname>Accept=no</varname>,
938 <literal>connection</literal> otherwise.</para>
ec07c3c8
AK
939
940 <xi:include href="version-info.xml" xpointer="v227"/></listitem>
8dd4c05b
LP
941 </varlistentry>
942
8b26cdbd
LP
943 <varlistentry>
944 <term><varname>TriggerLimitIntervalSec=</varname></term>
db985064 945 <term><varname>TriggerLimitBurst=</varname></term>
8b26cdbd 946
9373fce6
LP
947 <listitem><para>Configures a limit on how often this socket unit may be activated within a specific
948 time interval. The <varname>TriggerLimitIntervalSec=</varname> setting may be used to configure the
949 length of the time interval in the usual time units <literal>us</literal>, <literal>ms</literal>,
950 <literal>s</literal>, <literal>min</literal>, <literal>h</literal>, … and defaults to 2s (See
951 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
952 details on the various time units understood). The <varname>TriggerLimitBurst=</varname> setting
953 takes a positive integer value and specifies the number of permitted activations per time interval,
954 and defaults to 200 for <varname>Accept=yes</varname> sockets (thus by default permitting 200
955 activations per 2s), and 20 otherwise (20 activations per 2s). Set either to 0 to disable any form of
956 trigger rate limiting.</para>
957
958 <para>If the limit is hit, the socket unit is placed into a failure mode, and will not be connectible
959 anymore until restarted. Note that this limit is enforced before the service activation is
960 enqueued.</para>
961
962 <para>Compare with <varname>PollLimitIntervalSec=</varname>/<varname>PollLimitBurst=</varname>
963 described below, which implements a temporary slowdown if a socket unit is flooded with incoming
964 traffic, as opposed to the permanent failure state
965 <varname>TriggerLimitIntervalSec=</varname>/<varname>TriggerLimitBurst=</varname> results in.</para>
ec07c3c8
AK
966
967 <xi:include href="version-info.xml" xpointer="v230"/></listitem>
8b26cdbd
LP
968 </varlistentry>
969
9373fce6
LP
970 <varlistentry>
971 <term><varname>PollLimitIntervalSec=</varname></term>
972 <term><varname>PollLimitBurst=</varname></term>
973
974 <listitem><para>Configures a limit on how often polling events on the file descriptors backing this
975 socket unit will be considered. This pair of settings is similar to
976 <varname>TriggerLimitIntervalSec=</varname>/<varname>TriggerLimitBurst=</varname> but instead of
977 putting a (fatal) limit on the activation frequency puts a (transient) limit on the polling
978 frequency. The expected parameter syntax and range are identical to that of the aforementioned
979 options, and can be disabled the same way.</para>
980
981 <para>If the polling limit is hit polling is temporarily disabled on it until the specified time
982 window passes. The polling limit hence slows down connection attempts if hit, but unlike the trigger
44855c77 983 limit will not cause permanent failures. It's the recommended mechanism to deal with DoS attempts
9373fce6
LP
984 through packet flooding.</para>
985
986 <para>The polling limit is enforced per file descriptor to listen on, as opposed to the trigger limit
987 which is enforced for the entire socket unit. This distinction matters for socket units that listen
988 on multiple file descriptors (i.e. have multiple <varname>ListenXYZ=</varname> stanzas).</para>
989
990 <para>These setting defaults to 150 (in case of <varname>Accept=yes</varname>) and 15 (otherwise)
991 polling events per 2s. This is considerably lower than the default values for the trigger limit (see
992 above) and means that the polling limit should typically ensure the trigger limit is never hit,
993 unless one of them is reconfigured or disabled.</para>
994
995 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
996 </varlistentry>
997
1b4ab5a2
MY
998 <varlistentry>
999 <term><varname>DeferTrigger=</varname></term>
1000
1001 <listitem><para>Takes a boolean argument, or <literal>patient</literal>. May only be used when <varname>Accept=no</varname>.
1002 If enabled, job mode <literal>lenient</literal> instead of <literal>replace</literal> is used when
1003 triggering the service, which means currently activating/running units that conflict with the service
1004 won't be disturbed/brought down. Furthermore, if a conflict exists, the socket unit will wait for
1005 current job queue to complete and potentially defer the activation by then. An upper limit of total time
1006 to wait can be configured via <varname>DeferTriggerMaxSec=</varname>. If set to <option>yes</option>,
1007 the socket unit will fail if all jobs have finished or the timeout has been reached but the conflict remains.
1008 If <option>patient</option>, always wait until <varname>DeferTriggerMaxSec=</varname> elapses.
1009 Defaults to no.</para>
1010
1011 <para>This setting is particularly useful if the socket unit should stay active across switch-root/soft-reboot
1012 operations while the triggered service is stopped.</para>
1013
1014 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
1015 </varlistentry>
1016
1017 <varlistentry>
1018 <term><varname>DeferTriggerMaxSec=</varname></term>
1019
1020 <listitem><para>Configures the maximum time to defer the triggering when <varname>DeferTrigger=</varname>
1021 is enabled. If the service cannot be activated within the specified time, the socket will be considered
1022 failed and get terminated. Takes a unit-less value in seconds, or a time span value such as "5min 20s".
1023 Pass <literal>0</literal> or <literal>infinity</literal> to disable the timeout logic (the default).
1024 </para>
1025
1026 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
1027 </varlistentry>
1028
97df75d7
JS
1029 <varlistentry>
1030 <term><varname>PassFileDescriptorsToExec=</varname></term>
1031
1032 <listitem><para>Takes a boolean argument. Defaults to off. If enabled, file descriptors created by
1033 the socket unit are passed to <varname>ExecStartPost=</varname>, <varname>ExecStopPre=</varname>, and
1034 <varname>ExecStopPost=</varname> commands from the socket unit. The passed file descriptors can be
1035 accessed with
1036 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry> as
1037 if the commands were invoked from the associated service units. Note that
1038 <varname>ExecStartPre=</varname> command cannot access socket file descriptors.</para>
1039
1040 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
1041 </varlistentry>
1042
798d3a52
ZJS
1043 </variablelist>
1044
d8e1613e 1045 <xi:include href="systemd.service.xml" xpointer="shared-unit-options" />
798d3a52
ZJS
1046 </refsect1>
1047
1048 <refsect1>
1049 <title>See Also</title>
13a69c12
DT
1050 <para><simplelist type="inline">
1051 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
1052 <member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
1053 <member><citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1054 <member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1055 <member><citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1056 <member><citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1057 <member><citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1058 <member><citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
1059 <member><citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
1060 <member><citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
1061 <member><citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
1062 </simplelist></para>
798d3a52
ZJS
1063 <para>
1064 For more extensive descriptions see the "systemd for Developers" series:
13a69c12
DT
1065 <simplelist type="inline">
1066 <member><ulink url="https://0pointer.de/blog/projects/socket-activation.html">Socket Activation</ulink></member>
1067 <member><ulink url="https://0pointer.de/blog/projects/socket-activation2.html">Socket Activation, part II</ulink></member>
1068 <member><ulink url="https://0pointer.de/blog/projects/inetd.html">Converting inetd Services</ulink></member>
1069 <member><ulink url="https://0pointer.de/blog/projects/socket-activated-containers.html">Socket Activated Internet Services and OS Containers</ulink></member>
1070 </simplelist>.
798d3a52
ZJS
1071 </para>
1072 </refsect1>
1f812fea
LP
1073
1074</refentry>