1SYSTEMD.SOCKET(5)               systemd.socket               SYSTEMD.SOCKET(5)
2
3
4

NAME

6       systemd.socket - Socket unit configuration
7

SYNOPSIS

9       socket.socket
10

DESCRIPTION

12       A unit configuration file whose name ends in ".socket" encodes
13       information about an IPC or network socket or a file system FIFO
14       controlled and supervised by systemd, for socket-based activation.
15
16       This man page lists the configuration options specific to this unit
17       type. See systemd.unit(5) for the common options of all unit
18       configuration files. The common configuration items are configured in
19       the generic [Unit] and [Install] sections. The socket specific
20       configuration options are configured in the [Socket] section.
21
22       Additional options are listed in systemd.exec(5), which define the
23       execution environment the ExecStartPre=, ExecStartPost=, ExecStopPre=
24       and ExecStopPost= commands are executed in, and in systemd.kill(5),
25       which define the way the processes are terminated, and in
26       systemd.resource-control(5), which configure resource control settings
27       for the processes of the socket.
28
29       For each socket file, a matching service file must exist, describing
30       the service to start on incoming traffic on the socket (see
31       systemd.service(5) for more information about .service files). The name
32       of the .service unit is by default the same as the name of the .socket
33       unit, but can be altered with the Service= option described below.
34       Depending on the setting of the Accept= option described below, this
35       .service unit must either be named like the .socket unit, but with the
36       suffix replaced, unless overridden with Service=; or it must be a
37       template unit named the same way. Example: a socket file foo.socket
38       needs a matching service foo.service if Accept=false is set. If
39       Accept=true is set, a service template file foo@.service must exist
40       from which services are instantiated for each incoming connection.
41
42       No implicit WantedBy= or RequiredBy= dependency from the socket to the
43       service is added. This means that the service may be started without
44       the socket, in which case it must be able to open sockets by itself. To
45       prevent this, an explicit Requires= dependency may be added.
46
47       Socket units may be used to implement on-demand starting of services,
48       as well as parallelized starting of services. See the blog stories
49       linked at the end for an introduction.
50
51       Note that the daemon software configured for socket activation with
52       socket units needs to be able to accept sockets from systemd, either
53       via systemd's native socket passing interface (see sd_listen_fds(3) for
54       details) or via the traditional inetd(8)-style socket passing (i.e.
55       sockets passed in via standard input and output, using
56       StandardInput=socket in the service file).
57

AUTOMATIC DEPENDENCIES

59   Implicit Dependencies
60       The following dependencies are implicitly added:
61
62       ·   Socket units automatically gain a Before= dependency on the service
63           units they activate.
64
65       ·   Socket units referring to file system paths (such as AF_UNIX
66           sockets or FIFOs) implicitly gain Requires= and After= dependencies
67           on all mount units necessary to access those paths.
68
69       ·   Socket units using the BindToDevice= setting automatically gain a
70           BindsTo= and After= dependency on the device unit encapsulating the
71           specified network interface.
72
73       Additional implicit dependencies may be added as result of execution
74       and resource control parameters as documented in systemd.exec(5) and
75       systemd.resource-control(5).
76
77   Default Dependencies
78       The following dependencies are added unless DefaultDependencies=no is
79       set:
80
81       ·   Socket units automatically gain a Before= dependency on
82           sockets.target.
83
84       ·   Socket units automatically gain a pair of After= and Requires=
85           dependency on sysinit.target, and a pair of Before= and Conflicts=
86           dependencies on shutdown.target. These dependencies ensure that the
87           socket unit is started before normal services at boot, and is
88           stopped on shutdown. Only sockets involved with early boot or late
89           system shutdown should disable DefaultDependencies= option.
90

OPTIONS

92       Socket files must include a [Socket] section, which carries information
93       about the socket or FIFO it supervises. A number of options that may be
94       used in this section are shared with other unit types. These options
95       are documented in systemd.exec(5) and systemd.kill(5). The options
96       specific to the [Socket] section of socket units are the following:
97
98       ListenStream=, ListenDatagram=, ListenSequentialPacket=
99           Specifies an address to listen on for a stream (SOCK_STREAM),
100           datagram (SOCK_DGRAM), or sequential packet (SOCK_SEQPACKET)
101           socket, respectively. The address can be written in various
102           formats:
103
104           If the address starts with a slash ("/"), it is read as file system
105           socket in the AF_UNIX socket family.
106
107           If the address starts with an at symbol ("@"), it is read as
108           abstract namespace socket in the AF_UNIX family. The "@" is
109           replaced with a NUL character before binding. For details, see
110           unix(7).
111
112           If the address string is a single number, it is read as port number
113           to listen on via IPv6. Depending on the value of BindIPv6Only= (see
114           below) this might result in the service being available via both
115           IPv6 and IPv4 (default) or just via IPv6.
116
117           If the address string is a string in the format v.w.x.y:z, it is
118           read as IPv4 specifier for listening on an address v.w.x.y on a
119           port z.
120
121           If the address string is a string in the format [x]:y, it is read
122           as IPv6 address x on a port y. Note that this might make the
123           service available via IPv4, too, depending on the BindIPv6Only=
124           setting (see below).
125
126           If the address string is a string in the format "vsock:x:y", it is
127           read as CID "x" on a port "y" address in the AF_VSOCK family. The
128           CID is a unique 32-bit integer identifier in AF_VSOCK analogous to
129           an IP address. Specifying the CID is optional, and may be set to
130           the empty string.
131
132           Note that SOCK_SEQPACKET (i.e.  ListenSequentialPacket=) is only
133           available for AF_UNIX sockets.  SOCK_STREAM (i.e.  ListenStream=)
134           when used for IP sockets refers to TCP sockets, SOCK_DGRAM (i.e.
135           ListenDatagram=) to UDP.
136
137           These options may be specified more than once, in which case
138           incoming traffic on any of the sockets will trigger service
139           activation, and all listed sockets will be passed to the service,
140           regardless of whether there is incoming traffic on them or not. If
141           the empty string is assigned to any of these options, the list of
142           addresses to listen on is reset, all prior uses of any of these
143           options will have no effect.
144
145           It is also possible to have more than one socket unit for the same
146           service when using Service=, and the service will receive all the
147           sockets configured in all the socket units. Sockets configured in
148           one unit are passed in the order of configuration, but no ordering
149           between socket units is specified.
150
151           If an IP address is used here, it is often desirable to listen on
152           it before the interface it is configured on is up and running, and
153           even regardless of whether it will be up and running at any point.
154           To deal with this, it is recommended to set the FreeBind= option
155           described below.
156
157       ListenFIFO=
158           Specifies a file system FIFO to listen on. This expects an absolute
159           file system path as argument. Behavior otherwise is very similar to
160           the ListenDatagram= directive above.
161
162       ListenSpecial=
163           Specifies a special file in the file system to listen on. This
164           expects an absolute file system path as argument. Behavior
165           otherwise is very similar to the ListenFIFO= directive above. Use
166           this to open character device nodes as well as special files in
167           /proc and /sys.
168
169       ListenNetlink=
170           Specifies a Netlink family to create a socket for to listen on.
171           This expects a short string referring to the AF_NETLINK family name
172           (such as audit or kobject-uevent) as argument, optionally suffixed
173           by a whitespace followed by a multicast group integer. Behavior
174           otherwise is very similar to the ListenDatagram= directive above.
175
176       ListenMessageQueue=
177           Specifies a POSIX message queue name to listen on. This expects a
178           valid message queue name (i.e. beginning with /). Behavior
179           otherwise is very similar to the ListenFIFO= directive above. On
180           Linux message queue descriptors are actually file descriptors and
181           can be inherited between processes.
182
183       ListenUSBFunction=
184           Specifies a USB FunctionFS[1] endpoints location to listen on, for
185           implementation of USB gadget functions. This expects an absolute
186           file system path of functionfs mount point as the argument.
187           Behavior otherwise is very similar to the ListenFIFO= directive
188           above. Use this to open the FunctionFS endpoint ep0. When using
189           this option, the activated service has to have the
190           USBFunctionDescriptors= and USBFunctionStrings= options set.
191
192       SocketProtocol=
193           Takes a one of udplite or sctp. Specifies a socket protocol
194           (IPPROTO_UDPLITE) UDP-Lite (IPPROTO_SCTP) SCTP socket respectively.
195
196       BindIPv6Only=
197           Takes a one of default, both or ipv6-only. Controls the IPV6_V6ONLY
198           socket option (see ipv6(7) for details). If both, IPv6 sockets
199           bound will be accessible via both IPv4 and IPv6. If ipv6-only, they
200           will be accessible via IPv6 only. If default (which is the default,
201           surprise!), the system wide default setting is used, as controlled
202           by /proc/sys/net/ipv6/bindv6only, which in turn defaults to the
203           equivalent of both.
204
205       Backlog=
206           Takes an unsigned integer argument. Specifies the number of
207           connections to queue that have not been accepted yet. This setting
208           matters only for stream and sequential packet sockets. See
209           listen(2) for details. Defaults to SOMAXCONN (128).
210
211       BindToDevice=
212           Specifies a network interface name to bind this socket to. If set,
213           traffic will only be accepted from the specified network
214           interfaces. This controls the SO_BINDTODEVICE socket option (see
215           socket(7) for details). If this option is used, an implicit
216           dependency from this socket unit on the network interface device
217           unit (systemd.device(5) is created. Note that setting this
218           parameter might result in additional dependencies to be added to
219           the unit (see above).
220
221       SocketUser=, SocketGroup=
222           Takes a UNIX user/group name. When specified, all AF_UNIX sockets
223           and FIFO nodes in the file system are owned by the specified user
224           and group. If unset (the default), the nodes are owned by the root
225           user/group (if run in system context) or the invoking user/group
226           (if run in user context). If only a user is specified but no group,
227           then the group is derived from the user's default group.
228
229       SocketMode=
230           If listening on a file system socket or FIFO, this option specifies
231           the file system access mode used when creating the file node. Takes
232           an access mode in octal notation. Defaults to 0666.
233
234       DirectoryMode=
235           If listening on a file system socket or FIFO, the parent
236           directories are automatically created if needed. This option
237           specifies the file system access mode used when creating these
238           directories. Takes an access mode in octal notation. Defaults to
239           0755.
240
241       Accept=
242           Takes a boolean argument. If true, a service instance is spawned
243           for each incoming connection and only the connection socket is
244           passed to it. If false, all listening sockets themselves are passed
245           to the started service unit, and only one service unit is spawned
246           for all connections (also see above). This value is ignored for
247           datagram sockets and FIFOs where a single service unit
248           unconditionally handles all incoming traffic. Defaults to false.
249           For performance reasons, it is recommended to write new daemons
250           only in a way that is suitable for Accept=false. A daemon listening
251           on an AF_UNIX socket may, but does not need to, call close(2) on
252           the received socket before exiting. However, it must not unlink the
253           socket from a file system. It should not invoke shutdown(2) on
254           sockets it got with Accept=false, but it may do so for sockets it
255           got with Accept=true set. Setting Accept=true is mostly useful to
256           allow daemons designed for usage with inetd(8) to work unmodified
257           with systemd socket activation.
258
259           For IPv4 and IPv6 connections, the REMOTE_ADDR environment variable
260           will contain the remote IP address, and REMOTE_PORT will contain
261           the remote port. This is the same as the format used by CGI. For
262           SOCK_RAW, the port is the IP protocol.
263
264       Writable=
265           Takes a boolean argument. May only be used in conjunction with
266           ListenSpecial=. If true, the specified special file is opened in
267           read-write mode, if false, in read-only mode. Defaults to false.
268
269       MaxConnections=
270           The maximum number of connections to simultaneously run services
271           instances for, when Accept=true is set. If more concurrent
272           connections are coming in, they will be refused until at least one
273           existing connection is terminated. This setting has no effect on
274           sockets configured with Accept=false or datagram sockets. Defaults
275           to 64.
276
277       MaxConnectionsPerSource=
278           The maximum number of connections for a service per source IP
279           address. This is very similar to the MaxConnections= directive
280           above. Disabled by default.
281
282       KeepAlive=
283           Takes a boolean argument. If true, the TCP/IP stack will send a
284           keep alive message after 2h (depending on the configuration of
285           /proc/sys/net/ipv4/tcp_keepalive_time) for all TCP streams accepted
286           on this socket. This controls the SO_KEEPALIVE socket option (see
287           socket(7) and the TCP Keepalive HOWTO[2] for details.) Defaults to
288           false.
289
290       KeepAliveTimeSec=
291           Takes time (in seconds) as argument. The connection needs to remain
292           idle before TCP starts sending keepalive probes. This controls the
293           TCP_KEEPIDLE socket option (see socket(7) and the TCP Keepalive
294           HOWTO[2] for details.) Defaults value is 7200 seconds (2 hours).
295
296       KeepAliveIntervalSec=
297           Takes time (in seconds) as argument between individual keepalive
298           probes, if the socket option SO_KEEPALIVE has been set on this
299           socket. This controls the TCP_KEEPINTVL socket option (see
300           socket(7) and the TCP Keepalive HOWTO[2] for details.) Defaults
301           value is 75 seconds.
302
303       KeepAliveProbes=
304           Takes an integer as argument. It is the number of unacknowledged
305           probes to send before considering the connection dead and notifying
306           the application layer. This controls the TCP_KEEPCNT socket option
307           (see socket(7) and the TCP Keepalive HOWTO[2] for details.)
308           Defaults value is 9.
309
310       NoDelay=
311           Takes a boolean argument. TCP Nagle's algorithm works by combining
312           a number of small outgoing messages, and sending them all at once.
313           This controls the TCP_NODELAY socket option (see tcp(7) Defaults to
314           false.
315
316       Priority=
317           Takes an integer argument controlling the priority for all traffic
318           sent from this socket. This controls the SO_PRIORITY socket option
319           (see socket(7) for details.).
320
321       DeferAcceptSec=
322           Takes time (in seconds) as argument. If set, the listening process
323           will be awakened only when data arrives on the socket, and not
324           immediately when connection is established. When this option is
325           set, the TCP_DEFER_ACCEPT socket option will be used (see tcp(7)),
326           and the kernel will ignore initial ACK packets without any data.
327           The argument specifies the approximate amount of time the kernel
328           should wait for incoming data before falling back to the normal
329           behavior of honoring empty ACK packets. This option is beneficial
330           for protocols where the client sends the data first (e.g. HTTP, in
331           contrast to SMTP), because the server process will not be woken up
332           unnecessarily before it can take any action.
333
334           If the client also uses the TCP_DEFER_ACCEPT option, the latency of
335           the initial connection may be reduced, because the kernel will send
336           data in the final packet establishing the connection (the third
337           packet in the "three-way handshake").
338
339           Disabled by default.
340
341       ReceiveBuffer=, SendBuffer=
342           Takes an integer argument controlling the receive or send buffer
343           sizes of this socket, respectively. This controls the SO_RCVBUF and
344           SO_SNDBUF socket options (see socket(7) for details.). The usual
345           suffixes K, M, G are supported and are understood to the base of
346           1024.
347
348       IPTOS=
349           Takes an integer argument controlling the IP Type-Of-Service field
350           for packets generated from this socket. This controls the IP_TOS
351           socket option (see ip(7) for details.). Either a numeric string or
352           one of low-delay, throughput, reliability or low-cost may be
353           specified.
354
355       IPTTL=
356           Takes an integer argument controlling the IPv4 Time-To-Live/IPv6
357           Hop-Count field for packets generated from this socket. This sets
358           the IP_TTL/IPV6_UNICAST_HOPS socket options (see ip(7) and ipv6(7)
359           for details.)
360
361       Mark=
362           Takes an integer value. Controls the firewall mark of packets
363           generated by this socket. This can be used in the firewall logic to
364           filter packets from this socket. This sets the SO_MARK socket
365           option. See iptables(8) for details.
366
367       ReusePort=
368           Takes a boolean value. If true, allows multiple bind(2)s to this
369           TCP or UDP port. This controls the SO_REUSEPORT socket option. See
370           socket(7) for details.
371
372       SmackLabel=, SmackLabelIPIn=, SmackLabelIPOut=
373           Takes a string value. Controls the extended attributes
374           "security.SMACK64", "security.SMACK64IPIN" and
375           "security.SMACK64IPOUT", respectively, i.e. the security label of
376           the FIFO, or the security label for the incoming or outgoing
377           connections of the socket, respectively. See Smack.txt[3] for
378           details.
379
380       SELinuxContextFromNet=
381           Takes a boolean argument. When true, systemd will attempt to figure
382           out the SELinux label used for the instantiated service from the
383           information handed by the peer over the network. Note that only the
384           security level is used from the information provided by the peer.
385           Other parts of the resulting SELinux context originate from either
386           the target binary that is effectively triggered by socket unit or
387           from the value of the SELinuxContext= option. This configuration
388           option only affects sockets with Accept= mode set to "true". Also
389           note that this option is useful only when MLS/MCS SELinux policy is
390           deployed. Defaults to "false".
391
392       PipeSize=
393           Takes a size in bytes. Controls the pipe buffer size of FIFOs
394           configured in this socket unit. See fcntl(2) for details. The usual
395           suffixes K, M, G are supported and are understood to the base of
396           1024.
397
398       MessageQueueMaxMessages=, MessageQueueMessageSize=
399           These two settings take integer values and control the mq_maxmsg
400           field or the mq_msgsize field, respectively, when creating the
401           message queue. Note that either none or both of these variables
402           need to be set. See mq_setattr(3) for details.
403
404       FreeBind=
405           Takes a boolean value. Controls whether the socket can be bound to
406           non-local IP addresses. This is useful to configure sockets
407           listening on specific IP addresses before those IP addresses are
408           successfully configured on a network interface. This sets the
409           IP_FREEBIND socket option. For robustness reasons it is recommended
410           to use this option whenever you bind a socket to a specific IP
411           address. Defaults to false.
412
413       Transparent=
414           Takes a boolean value. Controls the IP_TRANSPARENT socket option.
415           Defaults to false.
416
417       Broadcast=
418           Takes a boolean value. This controls the SO_BROADCAST socket
419           option, which allows broadcast datagrams to be sent from this
420           socket. Defaults to false.
421
422       PassCredentials=
423           Takes a boolean value. This controls the SO_PASSCRED socket option,
424           which allows AF_UNIX sockets to receive the credentials of the
425           sending process in an ancillary message. Defaults to false.
426
427       PassSecurity=
428           Takes a boolean value. This controls the SO_PASSSEC socket option,
429           which allows AF_UNIX sockets to receive the security context of the
430           sending process in an ancillary message. Defaults to false.
431
432       TCPCongestion=
433           Takes a string value. Controls the TCP congestion algorithm used by
434           this socket. Should be one of "westwood", "veno", "cubic", "lp" or
435           any other available algorithm supported by the IP stack. This
436           setting applies only to stream sockets.
437
438       ExecStartPre=, ExecStartPost=
439           Takes one or more command lines, which are executed before or after
440           the listening sockets/FIFOs are created and bound, respectively.
441           The first token of the command line must be an absolute filename,
442           then followed by arguments for the process. Multiple command lines
443           may be specified following the same scheme as used for
444           ExecStartPre= of service unit files.
445
446       ExecStopPre=, ExecStopPost=
447           Additional commands that are executed before or after the listening
448           sockets/FIFOs are closed and removed, respectively. Multiple
449           command lines may be specified following the same scheme as used
450           for ExecStartPre= of service unit files.
451
452       TimeoutSec=
453           Configures the time to wait for the commands specified in
454           ExecStartPre=, ExecStartPost=, ExecStopPre= and ExecStopPost= to
455           finish. If a command does not exit within the configured time, the
456           socket will be considered failed and be shut down again. All
457           commands still running will be terminated forcibly via SIGTERM, and
458           after another delay of this time with SIGKILL. (See KillMode= in
459           systemd.kill(5).) Takes a unit-less value in seconds, or a time
460           span value such as "5min 20s". Pass "0" to disable the timeout
461           logic. Defaults to DefaultTimeoutStartSec= from the manager
462           configuration file (see systemd-system.conf(5)).
463
464       Service=
465           Specifies the service unit name to activate on incoming traffic.
466           This setting is only allowed for sockets with Accept=no. It
467           defaults to the service that bears the same name as the socket
468           (with the suffix replaced). In most cases, it should not be
469           necessary to use this option. Note that setting this parameter
470           might result in additional dependencies to be added to the unit
471           (see above).
472
473       RemoveOnStop=
474           Takes a boolean argument. If enabled, any file nodes created by
475           this socket unit are removed when it is stopped. This applies to
476           AF_UNIX sockets in the file system, POSIX message queues, FIFOs, as
477           well as any symlinks to them configured with Symlinks=. Normally,
478           it should not be necessary to use this option, and is not
479           recommended as services might continue to run after the socket unit
480           has been terminated and it should still be possible to communicate
481           with them via their file system node. Defaults to off.
482
483       Symlinks=
484           Takes a list of file system paths. The specified paths will be
485           created as symlinks to the AF_UNIX socket path or FIFO path of this
486           socket unit. If this setting is used, only one AF_UNIX socket in
487           the file system or one FIFO may be configured for the socket unit.
488           Use this option to manage one or more symlinked alias names for a
489           socket, binding their lifecycle together. Note that if creation of
490           a symlink fails this is not considered fatal for the socket unit,
491           and the socket unit may still start. If an empty string is
492           assigned, the list of paths is reset. Defaults to an empty list.
493
494       FileDescriptorName=
495           Assigns a name to all file descriptors this socket unit
496           encapsulates. This is useful to help activated services identify
497           specific file descriptors, if multiple fds are passed. Services may
498           use the sd_listen_fds_with_names(3) call to acquire the names
499           configured for the received file descriptors. Names may contain any
500           ASCII character, but must exclude control characters and ":", and
501           must be at most 255 characters in length. If this setting is not
502           used, the file descriptor name defaults to the name of the socket
503           unit, including its .socket suffix.
504
505       TriggerLimitIntervalSec=, TriggerLimitBurst=
506           Configures a limit on how often this socket unit my be activated
507           within a specific time interval. The TriggerLimitIntervalSec= may
508           be used to configure the length of the time interval in the usual
509           time units "us", "ms", "s", "min", "h", ... and defaults to 2s (See
510           systemd.time(7) for details on the various time units understood).
511           The TriggerLimitBurst= setting takes a positive integer value and
512           specifies the number of permitted activations per time interval,
513           and defaults to 200 for Accept=yes sockets (thus by default
514           permitting 200 activations per 2s), and 20 otherwise (20
515           activations per 2s). Set either to 0 to disable any form of trigger
516           rate limiting. If the limit is hit, the socket unit is placed into
517           a failure mode, and will not be connectible anymore until
518           restarted. Note that this limit is enforced before the service
519           activation is enqueued.
520
521       Check systemd.exec(5) and systemd.kill(5) for more settings.
522

SEE ALSO

524       systemd(1), systemctl(1), systemd.unit(5), systemd.exec(5),
525       systemd.kill(5), systemd.resource-control(5), systemd.service(5),
526       systemd.directives(7), sd_listen_fds(3), sd_listen_fds_with_names(3)
527
528       For more extensive descriptions see the "systemd for Developers"
529       series: Socket Activation[4], Socket Activation, part II[5], Converting
530       inetd Services[6], Socket Activated Internet Services and OS
531       Containers[7].
532

NOTES

534        1. USB FunctionFS
535           https://www.kernel.org/doc/Documentation/usb/functionfs.txt
536
537        2. TCP Keepalive HOWTO
538           http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/
539
540        3. Smack.txt
541           https://www.kernel.org/doc/Documentation/security/Smack.txt
542
543        4. Socket Activation
544           http://0pointer.de/blog/projects/socket-activation.html
545
546        5. Socket Activation, part II
547           http://0pointer.de/blog/projects/socket-activation2.html
548
549        6. Converting inetd Services
550           http://0pointer.de/blog/projects/inetd.html
551
552        7. Socket Activated Internet Services and OS Containers
553           http://0pointer.de/blog/projects/socket-activated-containers.html
554
555
556
557systemd 239                                                  SYSTEMD.SOCKET(5)
Impressum