]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd.socket.xml
oom: use CMP() macro
[thirdparty/systemd.git] / man / systemd.socket.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="systemd.socket">
7 <refentryinfo>
8 <title>systemd.socket</title>
9 <productname>systemd</productname>
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
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>
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
54 <para>For each socket unit, a matching service unit must exist,
55 describing the service to start on incoming traffic on the socket
56 (see
57 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
58 for more information about .service units). The name of the
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
68 <option>Accept=no</option> is set. If
69 <option>Accept=yes</option> is set, a service template
70 <filename>foo@.service</filename> must exist from which services
71 are instantiated for each incoming connection.</para>
72
73 <para>No implicit <varname>WantedBy=</varname> or
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
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>
92
93 <para>All network sockets allocated through <filename>.socket</filename> units are allocated in the host's network
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
102 from the service code itself will be associated with the service's own namespace, and thus possibly subject to a a
103 much more restrictive configuration.</para>
104 </refsect1>
105
106 <refsect1>
107 <title>Automatic Dependencies</title>
108
109 <refsect2>
110 <title>Implicit Dependencies</title>
111
112 <para>The following dependencies are implicitly added:</para>
113
114 <itemizedlist>
115 <listitem><para>Socket units automatically gain a <varname>Before=</varname>
116 dependency on the service units they activate.</para></listitem>
117
118 <listitem><para>Socket units referring to file system paths (such as <constant>AF_UNIX</constant>
119 sockets or FIFOs) implicitly gain <varname>Requires=</varname> and <varname>After=</varname>
120 dependencies on all mount units necessary to access those paths.</para></listitem>
121
122 <listitem><para>Socket units using the <varname>BindToDevice=</varname>
123 setting automatically gain a <varname>BindsTo=</varname> and
124 <varname>After=</varname> dependency on the device unit
125 encapsulating the specified network interface.</para></listitem>
126 </itemizedlist>
127
128 <para>Additional implicit dependencies may be added as result of
129 execution and resource control parameters as documented in
130 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
131 and
132 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
133 </refsect2>
134
135 <refsect2>
136 <title>Default Dependencies</title>
137
138 <para>The following dependencies are added unless
139 <varname>DefaultDependencies=no</varname> is set:</para>
140
141 <itemizedlist>
142 <listitem><para>Socket units automatically gain a
143 <varname>Before=</varname> dependency on
144 <filename>sockets.target</filename>.</para></listitem>
145
146 <listitem><para>Socket units automatically gain a pair of
147 <varname>After=</varname> and <varname>Requires=</varname>
148 dependency on <filename>sysinit.target</filename>, and a pair of
149 <varname>Before=</varname> and <varname>Conflicts=</varname>
150 dependencies on <filename>shutdown.target</filename>. These
151 dependencies ensure that the socket unit is started before normal
152 services at boot, and is stopped on shutdown. Only sockets
153 involved with early boot or late system shutdown should disable
154 <varname>DefaultDependencies=</varname> option.</para></listitem>
155 </itemizedlist>
156 </refsect2>
157 </refsect1>
158
159 <refsect1>
160 <title>Options</title>
161
162 <para>Socket files must include a [Socket] section, which carries
163 information about the socket or FIFO it supervises. A number of
164 options that may be used in this section are shared with other
165 unit types. These options are documented in
166 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
167 and
168 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
169 The options specific to the [Socket] section of socket units are
170 the following:</para>
171
172 <variablelist class='unit-directives'>
173 <varlistentry>
174 <term><varname>ListenStream=</varname></term>
175 <term><varname>ListenDatagram=</varname></term>
176 <term><varname>ListenSequentialPacket=</varname></term>
177 <listitem><para>Specifies an address to listen on for a stream
178 (<constant>SOCK_STREAM</constant>), datagram
179 (<constant>SOCK_DGRAM</constant>), or sequential packet
180 (<constant>SOCK_SEQPACKET</constant>) socket, respectively.
181 The address can be written in various formats:</para>
182
183 <para>If the address starts with a slash
184 (<literal>/</literal>), it is read as file system socket in
185 the <constant>AF_UNIX</constant> socket family.</para>
186
187 <para>If the address starts with an at symbol
188 (<literal>@</literal>), it is read as abstract namespace
189 socket in the <constant>AF_UNIX</constant> family. The
190 <literal>@</literal> is replaced with a
191 <constant>NUL</constant> character before binding. For
192 details, see
193 <citerefentry project='man-pages'><refentrytitle>unix</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
194
195 <para>If the address string is a single number, it is read as
196 port number to listen on via IPv6. Depending on the value of
197 <varname>BindIPv6Only=</varname> (see below) this might result
198 in the service being available via both IPv6 and IPv4
199 (default) or just via IPv6.
200 </para>
201
202 <para>If the address string is a string in the format
203 <literal><replaceable>v.w.x.y</replaceable>:<replaceable>z</replaceable></literal>, it is interpreted
204 as IPv4 address <replaceable>v.w.x.y</replaceable> and port <replaceable>z</replaceable>.</para>
205
206 <para>If the address string is a string in the format
207 <literal>[<replaceable>x</replaceable>]:<replaceable>y</replaceable></literal>, it is interpreted as
208 IPv6 address <replaceable>x</replaceable> and port <replaceable>y</replaceable>. An optional
209 interface scope (interface name or number) may be specified after a <literal>%</literal> symbol:
210 <literal>[<replaceable>x</replaceable>]:<replaceable>y</replaceable>%<replaceable>dev</replaceable></literal>.
211 Interface scopes are only useful with link-local addresses, because the kernel ignores them in other
212 cases. Note that if an address is specified as IPv6, it might still make the service available via
213 IPv4 too, depending on the <varname>BindIPv6Only=</varname> setting (see below).</para>
214
215 <para>If the address string is a string in the format
216 <literal>vsock:<replaceable>x</replaceable>:<replaceable>y</replaceable></literal>, it is read as CID
217 <replaceable>x</replaceable> on a port <replaceable>y</replaceable> address in the
218 <constant>AF_VSOCK</constant> family. The CID is a unique 32-bit integer identifier in
219 <constant>AF_VSOCK</constant> analogous to an IP address. Specifying the CID is optional, and may be
220 set to the empty string.</para>
221
222 <para>Note that <constant>SOCK_SEQPACKET</constant> (i.e.
223 <varname>ListenSequentialPacket=</varname>) is only available
224 for <constant>AF_UNIX</constant> sockets.
225 <constant>SOCK_STREAM</constant> (i.e.
226 <varname>ListenStream=</varname>) when used for IP sockets
227 refers to TCP sockets, <constant>SOCK_DGRAM</constant> (i.e.
228 <varname>ListenDatagram=</varname>) to UDP.</para>
229
230 <para>These options may be specified more than once, in which
231 case incoming traffic on any of the sockets will trigger
232 service activation, and all listed sockets will be passed to
233 the service, regardless of whether there is incoming traffic
234 on them or not. If the empty string is assigned to any of
235 these options, the list of addresses to listen on is reset,
236 all prior uses of any of these options will have no
237 effect.</para>
238
239 <para>It is also possible to have more than one socket unit
240 for the same service when using <varname>Service=</varname>,
241 and the service will receive all the sockets configured in all
242 the socket units. Sockets configured in one unit are passed in
243 the order of configuration, but no ordering between socket
244 units is specified.</para>
245
246 <para>If an IP address is used here, it is often desirable to
247 listen on it before the interface it is configured on is up
248 and running, and even regardless of whether it will be up and
249 running at any point. To deal with this, it is recommended to
250 set the <varname>FreeBind=</varname> option described
251 below.</para></listitem>
252 </varlistentry>
253
254 <varlistentry>
255 <term><varname>ListenFIFO=</varname></term>
256 <listitem><para>Specifies a file system FIFO (see <citerefentry
257 project='man-pages'><refentrytitle>fifo</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
258 details) to listen on. This expects an absolute file system path as argument. Behavior otherwise is
259 very similar to the <varname>ListenDatagram=</varname> directive above.</para></listitem>
260 </varlistentry>
261
262 <varlistentry>
263 <term><varname>ListenSpecial=</varname></term>
264 <listitem><para>Specifies a special file in the file system to
265 listen on. This expects an absolute file system path as
266 argument. Behavior otherwise is very similar to the
267 <varname>ListenFIFO=</varname> directive above. Use this to
268 open character device nodes as well as special files in
269 <filename>/proc/</filename> and
270 <filename>/sys/</filename>.</para></listitem>
271 </varlistentry>
272
273 <varlistentry>
274 <term><varname>ListenNetlink=</varname></term>
275 <listitem><para>Specifies a Netlink family to create a socket
276 for to listen on. This expects a short string referring to the
277 <constant>AF_NETLINK</constant> family name (such as
278 <varname>audit</varname> or <varname>kobject-uevent</varname>)
279 as argument, optionally suffixed by a whitespace followed by a
280 multicast group integer. Behavior otherwise is very similar to
281 the <varname>ListenDatagram=</varname> directive
282 above.</para></listitem>
283 </varlistentry>
284
285 <varlistentry>
286 <term><varname>ListenMessageQueue=</varname></term>
287 <listitem><para>Specifies a POSIX message queue name to listen on (see <citerefentry
288 project='man-pages'><refentrytitle>mq_overview</refentrytitle><manvolnum>7</manvolnum></citerefentry>
289 for details). This expects a valid message queue name (i.e. beginning with
290 <literal>/</literal>). Behavior otherwise is very similar to the <varname>ListenFIFO=</varname>
291 directive above. On Linux message queue descriptors are actually file descriptors and can be
292 inherited between processes.</para></listitem>
293 </varlistentry>
294
295 <varlistentry>
296 <term><varname>ListenUSBFunction=</varname></term>
297 <listitem><para>Specifies a <ulink
298 url="https://www.kernel.org/doc/Documentation/usb/functionfs.txt">USB
299 FunctionFS</ulink> endpoints location to listen on, for
300 implementation of USB gadget functions. This expects an
301 absolute file system path of a FunctionFS mount point as the argument.
302 Behavior otherwise is very similar to the <varname>ListenFIFO=</varname>
303 directive above. Use this to open the FunctionFS endpoint
304 <filename>ep0</filename>. When using this option, the
305 activated service has to have the
306 <varname>USBFunctionDescriptors=</varname> and
307 <varname>USBFunctionStrings=</varname> options set.
308 </para></listitem>
309 </varlistentry>
310
311 <varlistentry>
312 <term><varname>SocketProtocol=</varname></term>
313 <listitem><para>Takes one of <option>udplite</option>
314 or <option>sctp</option>. The socket will use the UDP-Lite
315 (<constant>IPPROTO_UDPLITE</constant>) or SCTP
316 (<constant>IPPROTO_SCTP</constant>) protocol, respectively.</para>
317 </listitem>
318 </varlistentry>
319
320 <varlistentry>
321 <term><varname>BindIPv6Only=</varname></term>
322 <listitem><para>Takes one of <option>default</option>,
323 <option>both</option> or <option>ipv6-only</option>. Controls
324 the IPV6_V6ONLY socket option (see
325 <citerefentry project='die-net'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry>
326 for details). If <option>both</option>, IPv6 sockets bound
327 will be accessible via both IPv4 and IPv6. If
328 <option>ipv6-only</option>, they will be accessible via IPv6
329 only. If <option>default</option> (which is the default,
330 surprise!), the system wide default setting is used, as
331 controlled by
332 <filename>/proc/sys/net/ipv6/bindv6only</filename>, which in
333 turn defaults to the equivalent of
334 <option>both</option>.</para>
335 </listitem>
336 </varlistentry>
337
338 <varlistentry>
339 <term><varname>Backlog=</varname></term>
340 <listitem><para>Takes an unsigned integer argument. Specifies
341 the number of connections to queue that have not been accepted
342 yet. This setting matters only for stream and sequential
343 packet sockets. See
344 <citerefentry><refentrytitle>listen</refentrytitle><manvolnum>2</manvolnum></citerefentry>
345 for details. Defaults to SOMAXCONN (128).</para></listitem>
346 </varlistentry>
347
348 <varlistentry>
349 <term><varname>BindToDevice=</varname></term>
350 <listitem><para>Specifies a network interface name to bind this socket to. If set, traffic will only
351 be accepted from the specified network interfaces. This controls the
352 <constant>SO_BINDTODEVICE</constant> socket option (see <citerefentry
353 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
354 details). If this option is used, an implicit dependency from this socket unit on the network
355 interface device unit is created
356 (see <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
357 Note that setting this parameter might result in additional dependencies to be added to the unit (see
358 above).</para></listitem>
359 </varlistentry>
360
361 <varlistentry>
362 <term><varname>SocketUser=</varname></term>
363 <term><varname>SocketGroup=</varname></term>
364
365 <listitem><para>Takes a UNIX user/group name. When specified, all <constant>AF_UNIX</constant>
366 sockets and FIFO nodes in the file system are owned by the specified user and group. If unset (the
367 default), the nodes are owned by the root user/group (if run in system context) or the invoking
368 user/group (if run in user context). If only a user is specified but no group, then the group is
369 derived from the user's default group.</para></listitem>
370 </varlistentry>
371
372 <varlistentry>
373 <term><varname>SocketMode=</varname></term>
374 <listitem><para>If listening on a file system socket or FIFO,
375 this option specifies the file system access mode used when
376 creating the file node. Takes an access mode in octal
377 notation. Defaults to 0666.</para></listitem>
378 </varlistentry>
379
380 <varlistentry>
381 <term><varname>DirectoryMode=</varname></term>
382 <listitem><para>If listening on a file system socket or FIFO,
383 the parent directories are automatically created if needed.
384 This option specifies the file system access mode used when
385 creating these directories. Takes an access mode in octal
386 notation. Defaults to 0755.</para></listitem>
387 </varlistentry>
388
389 <varlistentry>
390 <term><varname>Accept=</varname></term>
391 <listitem><para>Takes a boolean argument. If yes, a service
392 instance is spawned for each incoming connection and only the
393 connection socket is passed to it. If no, all listening
394 sockets themselves are passed to the started service unit, and
395 only one service unit is spawned for all connections (also see
396 above). This value is ignored for datagram sockets and FIFOs
397 where a single service unit unconditionally handles all
398 incoming traffic. Defaults to <option>no</option>. For
399 performance reasons, it is recommended to write new daemons
400 only in a way that is suitable for
401 <option>Accept=no</option>. A daemon listening on an
402 <constant>AF_UNIX</constant> socket may, but does not need to,
403 call
404 <citerefentry><refentrytitle>close</refentrytitle><manvolnum>2</manvolnum></citerefentry>
405 on the received socket before exiting. However, it must not
406 unlink the socket from a file system. It should not invoke
407 <citerefentry><refentrytitle>shutdown</refentrytitle><manvolnum>2</manvolnum></citerefentry>
408 on sockets it got with <varname>Accept=no</varname>, but it
409 may do so for sockets it got with
410 <varname>Accept=yes</varname> set. Setting
411 <varname>Accept=yes</varname> is mostly useful to allow
412 daemons designed for usage with
413 <citerefentry project='freebsd'><refentrytitle>inetd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
414 to work unmodified with systemd socket
415 activation.</para>
416
417 <para>For IPv4 and IPv6 connections, the <varname>REMOTE_ADDR</varname> environment variable will
418 contain the remote IP address, and <varname>REMOTE_PORT</varname> will contain the remote port. This
419 is the same as the format used by CGI. For <constant>SOCK_RAW</constant>, the port is the IP
420 protocol.</para></listitem>
421 </varlistentry>
422
423 <varlistentry>
424 <term><varname>Writable=</varname></term>
425 <listitem><para>Takes a boolean argument. May only be used in
426 conjunction with <varname>ListenSpecial=</varname>. If true,
427 the specified special file is opened in read-write mode, if
428 false, in read-only mode. Defaults to false.</para></listitem>
429 </varlistentry>
430
431 <varlistentry>
432 <term><varname>FlushPending=</varname></term>
433 <listitem><para>Takes a boolean argument. May only be used when
434 <option>Accept=no</option>. If yes, the socket's buffers are cleared after the
435 triggered service exited. This causes any pending data to be
436 flushed and any pending incoming connections to be rejected. If no, the
437 socket's buffers won't be cleared, permitting the service to handle any
438 pending connections after restart, which is the usually expected behaviour.
439 Defaults to <option>no</option>.
440 </para></listitem>
441 </varlistentry>
442
443 <varlistentry>
444 <term><varname>MaxConnections=</varname></term>
445 <listitem><para>The maximum number of connections to
446 simultaneously run services instances for, when
447 <option>Accept=yes</option> is set. If more concurrent
448 connections are coming in, they will be refused until at least
449 one existing connection is terminated. This setting has no
450 effect on sockets configured with
451 <option>Accept=no</option> or datagram sockets. Defaults to
452 64.</para></listitem>
453 </varlistentry>
454
455 <varlistentry>
456 <term><varname>MaxConnectionsPerSource=</varname></term>
457 <listitem><para>The maximum number of connections for a service per source IP address.
458 This is very similar to the <varname>MaxConnections=</varname> directive
459 above. Disabled by default.</para>
460 </listitem>
461 </varlistentry>
462
463 <varlistentry>
464 <term><varname>KeepAlive=</varname></term>
465 <listitem><para>Takes a boolean argument. If true, the TCP/IP stack will send a keep alive message
466 after 2h (depending on the configuration of
467 <filename>/proc/sys/net/ipv4/tcp_keepalive_time</filename>) for all TCP streams accepted on this
468 socket. This controls the <constant>SO_KEEPALIVE</constant> socket option (see <citerefentry
469 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
470 the <ulink url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP Keepalive
471 HOWTO</ulink> for details.) Defaults to <option>false</option>.</para></listitem>
472 </varlistentry>
473
474 <varlistentry>
475 <term><varname>KeepAliveTimeSec=</varname></term>
476 <listitem><para>Takes time (in seconds) as argument. The connection needs to remain
477 idle before TCP starts sending keepalive probes. This controls the TCP_KEEPIDLE
478 socket option (see
479 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
480 and the <ulink
481 url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP
482 Keepalive HOWTO</ulink> for details.)
483 Defaults value is 7200 seconds (2 hours).</para></listitem>
484 </varlistentry>
485
486 <varlistentry>
487 <term><varname>KeepAliveIntervalSec=</varname></term>
488 <listitem><para>Takes time (in seconds) as argument between individual keepalive probes, if the
489 socket option <constant>SO_KEEPALIVE</constant> has been set on this socket. This controls the
490 <constant>TCP_KEEPINTVL</constant> socket option (see <citerefentry
491 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
492 the <ulink url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP Keepalive
493 HOWTO</ulink> for details.) Defaults value is 75 seconds.</para></listitem>
494 </varlistentry>
495
496 <varlistentry>
497 <term><varname>KeepAliveProbes=</varname></term>
498 <listitem><para>Takes an integer as argument. It is the number of
499 unacknowledged probes to send before considering the
500 connection dead and notifying the application layer. This
501 controls the TCP_KEEPCNT socket option (see
502 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>
503 and the <ulink
504 url="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP
505 Keepalive HOWTO</ulink> for details.) Defaults value is
506 9.</para></listitem>
507 </varlistentry>
508
509 <varlistentry>
510 <term><varname>NoDelay=</varname></term>
511 <listitem><para>Takes a boolean argument. TCP Nagle's
512 algorithm works by combining a number of small outgoing
513 messages, and sending them all at once. This controls the
514 TCP_NODELAY socket option (see
515 <citerefentry project='die-net'><refentrytitle>tcp</refentrytitle><manvolnum>7</manvolnum></citerefentry>).
516 Defaults to <option>false</option>.</para></listitem>
517 </varlistentry>
518
519 <varlistentry>
520 <term><varname>Priority=</varname></term>
521 <listitem><para>Takes an integer argument controlling the priority for all traffic sent from this
522 socket. This controls the <constant>SO_PRIORITY</constant> socket option (see <citerefentry
523 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
524 details.).</para></listitem>
525 </varlistentry>
526
527 <varlistentry>
528 <term><varname>DeferAcceptSec=</varname></term>
529
530 <listitem><para>Takes time (in seconds) as argument. If set,
531 the listening process will be awakened only when data arrives
532 on the socket, and not immediately when connection is
533 established. When this option is set, the
534 <constant>TCP_DEFER_ACCEPT</constant> socket option will be
535 used (see
536 <citerefentry project='die-net'><refentrytitle>tcp</refentrytitle><manvolnum>7</manvolnum></citerefentry>),
537 and the kernel will ignore initial ACK packets without any
538 data. The argument specifies the approximate amount of time
539 the kernel should wait for incoming data before falling back
540 to the normal behavior of honoring empty ACK packets. This
541 option is beneficial for protocols where the client sends the
542 data first (e.g. HTTP, in contrast to SMTP), because the
543 server process will not be woken up unnecessarily before it
544 can take any action.
545 </para>
546
547 <para>If the client also uses the
548 <constant>TCP_DEFER_ACCEPT</constant> option, the latency of
549 the initial connection may be reduced, because the kernel will
550 send data in the final packet establishing the connection (the
551 third packet in the "three-way handshake").</para>
552
553 <para>Disabled by default.</para>
554 </listitem>
555 </varlistentry>
556
557 <varlistentry>
558 <term><varname>ReceiveBuffer=</varname></term>
559 <term><varname>SendBuffer=</varname></term>
560 <listitem><para>Takes an integer argument controlling the receive or send buffer sizes of this
561 socket, respectively. This controls the <constant>SO_RCVBUF</constant> and
562 <constant>SO_SNDBUF</constant> socket options (see <citerefentry
563 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
564 details.). The usual suffixes K, M, G are supported and are understood to the base of
565 1024.</para></listitem>
566 </varlistentry>
567
568 <varlistentry>
569 <term><varname>IPTOS=</varname></term>
570 <listitem><para>Takes an integer argument controlling the IP Type-Of-Service field for packets
571 generated from this socket. This controls the <constant>IP_TOS</constant> socket option (see
572 <citerefentry
573 project='die-net'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
574 details.). Either a numeric string or one of <option>low-delay</option>, <option>throughput</option>,
575 <option>reliability</option> or <option>low-cost</option> may be specified.</para></listitem>
576 </varlistentry>
577
578 <varlistentry>
579 <term><varname>IPTTL=</varname></term>
580 <listitem><para>Takes an integer argument controlling the IPv4 Time-To-Live/IPv6 Hop-Count field for
581 packets generated from this socket. This sets the
582 <constant>IP_TTL</constant>/<constant>IPV6_UNICAST_HOPS</constant> socket options (see <citerefentry
583 project='die-net'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry> and
584 <citerefentry
585 project='die-net'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
586 details.)</para></listitem>
587 </varlistentry>
588
589 <varlistentry>
590 <term><varname>Mark=</varname></term>
591 <listitem><para>Takes an integer value. Controls the firewall mark of packets generated by this
592 socket. This can be used in the firewall logic to filter packets from this socket. This sets the
593 <constant>SO_MARK</constant> socket option. See <citerefentry
594 project='die-net'><refentrytitle>iptables</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
595 details.</para></listitem>
596 </varlistentry>
597
598 <varlistentry>
599 <term><varname>ReusePort=</varname></term>
600 <listitem><para>Takes a boolean value. If true, allows multiple
601 <citerefentry><refentrytitle>bind</refentrytitle><manvolnum>2</manvolnum></citerefentry>s to this TCP
602 or UDP port. This controls the <constant>SO_REUSEPORT</constant> socket option. See <citerefentry
603 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
604 details.</para></listitem>
605 </varlistentry>
606
607 <varlistentry>
608 <term><varname>SmackLabel=</varname></term>
609 <term><varname>SmackLabelIPIn=</varname></term>
610 <term><varname>SmackLabelIPOut=</varname></term>
611 <listitem><para>Takes a string value. Controls the extended
612 attributes <literal>security.SMACK64</literal>,
613 <literal>security.SMACK64IPIN</literal> and
614 <literal>security.SMACK64IPOUT</literal>, respectively, i.e.
615 the security label of the FIFO, or the security label for the
616 incoming or outgoing connections of the socket, respectively.
617 See <ulink
618 url="https://www.kernel.org/doc/Documentation/security/Smack.txt">Smack.txt</ulink>
619 for details.</para></listitem>
620 </varlistentry>
621
622 <varlistentry>
623 <term><varname>SELinuxContextFromNet=</varname></term>
624 <listitem><para>Takes a boolean argument. When true, systemd
625 will attempt to figure out the SELinux label used for the
626 instantiated service from the information handed by the peer
627 over the network. Note that only the security level is used
628 from the information provided by the peer. Other parts of the
629 resulting SELinux context originate from either the target
630 binary that is effectively triggered by socket unit or from
631 the value of the <varname>SELinuxContext=</varname> option.
632 This configuration option only affects sockets with
633 <varname>Accept=</varname> mode set to
634 <literal>yes</literal>. Also note that this option is useful
635 only when MLS/MCS SELinux policy is deployed. Defaults to
636 <literal>false</literal>. </para></listitem>
637 </varlistentry>
638
639 <varlistentry>
640 <term><varname>PipeSize=</varname></term>
641 <listitem><para>Takes a size in bytes. Controls the pipe
642 buffer size of FIFOs configured in this socket unit. See
643 <citerefentry><refentrytitle>fcntl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
644 for details. The usual suffixes K, M, G are supported and are
645 understood to the base of 1024.</para></listitem>
646 </varlistentry>
647
648 <varlistentry>
649 <term><varname>MessageQueueMaxMessages=</varname>,
650 <varname>MessageQueueMessageSize=</varname></term>
651 <listitem><para>These two settings take integer values and
652 control the mq_maxmsg field or the mq_msgsize field,
653 respectively, when creating the message queue. Note that
654 either none or both of these variables need to be set. See
655 <citerefentry project='die-net'><refentrytitle>mq_setattr</refentrytitle><manvolnum>3</manvolnum></citerefentry>
656 for details.</para></listitem>
657 </varlistentry>
658
659 <varlistentry>
660 <term><varname>FreeBind=</varname></term>
661 <listitem><para>Takes a boolean value. Controls whether the socket can be bound to non-local IP
662 addresses. This is useful to configure sockets listening on specific IP addresses before those IP
663 addresses are successfully configured on a network interface. This sets the
664 <constant>IP_FREEBIND</constant>/<constant>IPV6_FREEBIND</constant> socket option. For robustness
665 reasons it is recommended to use this option whenever you bind a socket to a specific IP
666 address. Defaults to <option>false</option>.</para></listitem>
667 </varlistentry>
668
669 <varlistentry>
670 <term><varname>Transparent=</varname></term>
671 <listitem><para>Takes a boolean value. Controls the
672 <constant>IP_TRANSPARENT</constant>/<constant>IPV6_TRANSPARENT</constant> socket option. Defaults to
673 <option>false</option>.</para></listitem>
674 </varlistentry>
675
676 <varlistentry>
677 <term><varname>Broadcast=</varname></term>
678 <listitem><para>Takes a boolean value. This controls the <constant>SO_BROADCAST</constant> socket
679 option, which allows broadcast datagrams to be sent from this socket. Defaults to
680 <option>false</option>.</para></listitem>
681 </varlistentry>
682
683 <varlistentry>
684 <term><varname>PassCredentials=</varname></term>
685 <listitem><para>Takes a boolean value. This controls the <constant>SO_PASSCRED</constant> socket
686 option, which allows <constant>AF_UNIX</constant> sockets to receive the credentials of the sending
687 process in an ancillary message. Defaults to <option>false</option>.</para></listitem>
688 </varlistentry>
689
690 <varlistentry>
691 <term><varname>PassSecurity=</varname></term>
692 <listitem><para>Takes a boolean value. This controls the <constant>SO_PASSSEC</constant> socket
693 option, which allows <constant>AF_UNIX</constant> sockets to receive the security context of the
694 sending process in an ancillary message. Defaults to <option>false</option>.</para></listitem>
695 </varlistentry>
696
697 <varlistentry>
698 <term><varname>PassPacketInfo=</varname></term>
699 <listitem><para>Takes a boolean value. This controls the <constant>IP_PKTINFO</constant>,
700 <constant>IPV6_RECVPKTINFO</constant>, <constant>NETLINK_PKTINFO</constant> or
701 <constant>PACKET_AUXDATA</constant> socket options, which enable reception of additional per-packet
702 metadata as ancillary message, on <constant>AF_INET</constant>, <constant>AF_INET6</constant>,
703 <constant>AF_UNIX</constant> and <constant>AF_PACKET</constant> sockets. Defaults to
704 <option>false</option>.</para></listitem>
705 </varlistentry>
706
707 <varlistentry>
708 <term><varname>Timestamping=</varname></term>
709 <listitem><para>Takes one of <literal>off</literal>, <literal>us</literal> (alias:
710 <literal>usec</literal>, <literal>µs</literal>) or <literal>ns</literal> (alias:
711 <literal>nsec</literal>). This controls the <constant>SO_TIMESTAMP</constant> or
712 <constant>SO_TIMESTAMPNS</constant> socket options, and enables whether ingress network traffic shall
713 carry timestamping metadata. Defaults to <option>off</option>.</para></listitem>
714 </varlistentry>
715
716 <varlistentry>
717 <term><varname>TCPCongestion=</varname></term>
718 <listitem><para>Takes a string value. Controls the TCP congestion algorithm used by this
719 socket. Should be one of <literal>westwood</literal>, <literal>veno</literal>,
720 <literal>cubic</literal>, <literal>lp</literal> or any other available algorithm supported by the IP
721 stack. This setting applies only to stream sockets.</para></listitem>
722 </varlistentry>
723
724 <varlistentry>
725 <term><varname>ExecStartPre=</varname></term>
726 <term><varname>ExecStartPost=</varname></term>
727 <listitem><para>Takes one or more command lines, which are
728 executed before or after the listening sockets/FIFOs are
729 created and bound, respectively. The first token of the
730 command line must be an absolute filename, then followed by
731 arguments for the process. Multiple command lines may be
732 specified following the same scheme as used for
733 <varname>ExecStartPre=</varname> of service unit
734 files.</para></listitem>
735 </varlistentry>
736
737 <varlistentry>
738 <term><varname>ExecStopPre=</varname></term>
739 <term><varname>ExecStopPost=</varname></term>
740 <listitem><para>Additional commands that are executed before
741 or after the listening sockets/FIFOs are closed and removed,
742 respectively. Multiple command lines may be specified
743 following the same scheme as used for
744 <varname>ExecStartPre=</varname> of service unit
745 files.</para></listitem>
746 </varlistentry>
747
748 <varlistentry>
749 <term><varname>TimeoutSec=</varname></term>
750 <listitem><para>Configures the time to wait for the commands
751 specified in <varname>ExecStartPre=</varname>,
752 <varname>ExecStartPost=</varname>,
753 <varname>ExecStopPre=</varname> and
754 <varname>ExecStopPost=</varname> to finish. If a command does
755 not exit within the configured time, the socket will be
756 considered failed and be shut down again. All commands still
757 running will be terminated forcibly via
758 <constant>SIGTERM</constant>, and after another delay of this
759 time with <constant>SIGKILL</constant>. (See
760 <option>KillMode=</option> in
761 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.)
762 Takes a unit-less value in seconds, or a time span value such
763 as "5min 20s". Pass <literal>0</literal> to disable the
764 timeout logic. Defaults to
765 <varname>DefaultTimeoutStartSec=</varname> from the manager
766 configuration file (see
767 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
768 </para></listitem>
769 </varlistentry>
770
771 <varlistentry>
772 <term><varname>Service=</varname></term>
773 <listitem><para>Specifies the service unit name to activate on
774 incoming traffic. This setting is only allowed for sockets
775 with <varname>Accept=no</varname>. It defaults to the service
776 that bears the same name as the socket (with the suffix
777 replaced). In most cases, it should not be necessary to use
778 this option. Note that setting this parameter might result in
779 additional dependencies to be added to the unit (see
780 above).</para></listitem>
781 </varlistentry>
782
783 <varlistentry>
784 <term><varname>RemoveOnStop=</varname></term>
785 <listitem><para>Takes a boolean argument. If enabled, any file nodes created by this socket unit are
786 removed when it is stopped. This applies to <constant>AF_UNIX</constant> sockets in the file system,
787 POSIX message queues, FIFOs, as well as any symlinks to them configured with
788 <varname>Symlinks=</varname>. Normally, it should not be necessary to use this option, and is not
789 recommended as services might continue to run after the socket unit has been terminated and it should
790 still be possible to communicate with them via their file system node. Defaults to
791 off.</para></listitem>
792 </varlistentry>
793
794 <varlistentry>
795 <term><varname>Symlinks=</varname></term>
796 <listitem><para>Takes a list of file system paths. The specified paths will be created as symlinks to the
797 <constant>AF_UNIX</constant> socket path or FIFO path of this socket unit. If this setting is used, only one
798 <constant>AF_UNIX</constant> socket in the file system or one FIFO may be configured for the socket unit. Use
799 this option to manage one or more symlinked alias names for a socket, binding their lifecycle together. Note
800 that if creation of a symlink fails this is not considered fatal for the socket unit, and the socket unit may
801 still start. If an empty string is assigned, the list of paths is reset. Defaults to an empty
802 list.</para></listitem>
803 </varlistentry>
804
805 <varlistentry>
806 <term><varname>FileDescriptorName=</varname></term>
807 <listitem><para>Assigns a name to all file descriptors this
808 socket unit encapsulates. This is useful to help activated
809 services identify specific file descriptors, if multiple fds
810 are passed. Services may use the
811 <citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>
812 call to acquire the names configured for the received file
813 descriptors. Names may contain any ASCII character, but must
814 exclude control characters and <literal>:</literal>, and must
815 be at most 255 characters in length. If this setting is not
816 used, the file descriptor name defaults to the name of the
817 socket unit, including its <filename>.socket</filename>
818 suffix.</para></listitem>
819 </varlistentry>
820
821 <varlistentry>
822 <term><varname>TriggerLimitIntervalSec=</varname></term>
823 <term><varname>TriggerLimitBurst=</varname></term>
824
825 <listitem><para>Configures a limit on how often this socket unit my be activated within a specific time
826 interval. The <varname>TriggerLimitIntervalSec=</varname> may be used to configure the length of the time
827 interval in the usual time units <literal>us</literal>, <literal>ms</literal>, <literal>s</literal>,
828 <literal>min</literal>, <literal>h</literal>, … and defaults to 2s (See
829 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry> for details on
830 the various time units understood). The <varname>TriggerLimitBurst=</varname> setting takes a positive integer
831 value and specifies the number of permitted activations per time interval, and defaults to 200 for
832 <varname>Accept=yes</varname> sockets (thus by default permitting 200 activations per 2s), and 20 otherwise (20
833 activations per 2s). Set either to 0 to disable any form of trigger rate limiting. If the limit is hit, the
834 socket unit is placed into a failure mode, and will not be connectible anymore until restarted. Note that this
835 limit is enforced before the service activation is enqueued.</para></listitem>
836 </varlistentry>
837
838 </variablelist>
839
840 <para>Check
841 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
842 and
843 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
844 for more settings.</para>
845
846 </refsect1>
847
848 <refsect1>
849 <title>See Also</title>
850 <para>
851 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
852 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
853 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
854 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
855 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
856 <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
857 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
858 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
859 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
860 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
861 <citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>
862 </para>
863 <para>
864 For more extensive descriptions see the "systemd for Developers" series:
865 <ulink url="http://0pointer.de/blog/projects/socket-activation.html">Socket Activation</ulink>,
866 <ulink url="http://0pointer.de/blog/projects/socket-activation2.html">Socket Activation, part II</ulink>,
867 <ulink url="http://0pointer.de/blog/projects/inetd.html">Converting inetd Services</ulink>,
868 <ulink url="http://0pointer.de/blog/projects/socket-activated-containers.html">Socket Activated Internet Services and OS Containers</ulink>.
869 </para>
870 </refsect1>
871
872 </refentry>