Debian Codegraph @

socket-activate.md

raw symbols SCIP
1 ---
2 title: SOCKET-ACTIVATE
3 section: 1
4 header: User Commands
5 footer: July 2024
6 ---
7
8 NAME
9 ====
10
11 `socket-activate` - open sockets and `exec` a systemd-style socket-activated service
12
13 SYNOPSIS
14 ========
15
16 **socket-activate** [**-v**] [*socketinfo* ...] [**\-\-**] *prog* [*args*]
17
18 where *socketinfo* is of the form:
19
20 \-\-*family*:[*option*=*value*,...]:*address*
21
22 See `EXAMPLES` below.
23
24 DESCRIPTION
25 ===========
26
27 The `socket-activate` program opens the requested sockets and then
28 waits for incoming activity on them. When this happens, it execs
29 *prog*, which inherits these open file descriptors. The first
30 requested socket will be opened on file descriptor 3, and subsequent
31 ones follow in order.
32
33 If `-v` or `--verbose` is present, `socket-activate` will write
34 details of what it is doing to stderr before it execs *prog*.
35
36 *prog* is the first argument that does not start with a `-`, or the
37 first argument after a `--`.
38
39 SOCKET FAMILIES
40 ===============
41
42 *family* can be one of several different values.
43
44 For the following values of *family*, if *address* is a single decimal
45 number, it is treated as a port number and socket-activate will bind to all
46 available addresses on that port. If *address* contains a /, the part
47 before the / is interpreted as a network address of the requested
48 family, and the part after the / is treated as a port number.
49
50 - `tcp`: TCP on IPv4 and/or IPv6
51 - `udp`: UDP on IPv4 and/or IPv6
52
53 For the following values of *family*, *address* is interpreted as a
54 filesystem path.
55
56 - `unix`: Unix-domain streaming socket
57 - `unix-dgram`: Unix-domain datagram socket
58
59 SOCKET OPTIONS
60 ==============
61
62 Each *socketinfo* can have 0 or more options appended to it, separated
63 by the comma character (`,`) with their value appended after an equals
64 sign (`=`).
65
66 Available options are:
67
68 - `label`: simple text string to identify this socket to the
69 inheriting process
70
71 - `backlog`: For streaming sockets (`tcp` and `unix`), the maximum
72 queue for pending connections (see listen(2) -- defaults
73 to `SOMAXCONN`).
74
75 - `mode`: octal mode for Unix-domain socket (defaults to relying on
76 umask(2))
77
78 - `user`: a numeric User ID value for Unix-domain socket ownership
79
80 - `group`: a numeric Group ID value for Unix-domain socket ownership
81
82 EXIT CODES
83 ==========
84
85 `socket-activate` exits 100 when called with unparseable options. It prints an
86 error message to stderr and exits 11 if it cannot successfully bind
87 all of the requested sockets. It prints an error message to stderr
88 and exits with the value of errno if it is unable to exec(3) the
89 intended process. Otherwise, its exit code is the same as that of
90 *prog*.
91
92 ENVIRONMENT VARIABLES
93 =====================
94
95 `socket-activate` stores the number of opened file descriptors in the
96 environment variable `$LISTEN_FDS`, sets `$LISTEN_PID` to getpid(2),
97 and stores the list of colon-separated labels in `$LISTEN_FDNAMES`.
98
99 These environment variables follow the convention understood by
100 libsystemd (see sd_listen_fds(3)) so it should be usable with any
101 socket-activated daemon that expects this behavior.
102
103 EXAMPLES
104 ========
105
106 Run a webserver as a non-privileged user, using privileged ports, and
107 indicating to the webserver which ports should offer HTTPS:
108
109 socket-activate --tcp::80 --tcp:label=tls:443 -- \
110 runuser -u httpd -- \
111 webserver
112
113 Expose a foregrounded (supervised) pulseaudio daemon to the network:
114
115 socket-activate --tcp:backlog=5:1000 -- \
116 pulseaudio --daemonize=no
117
118 Run a network daemon only on the IPv4 loopback:
119
120 socket-activate --tcp::127.0.0.1/9999 -- \
121 network-daemon
122
123 Run a network daemon over a unix-domain socket instead of IP:
124
125 socket-activate --unix::/srv/network-access -- \
126 network-daemon
127
128 Run a public-facing network daemon with a local socket for the local
129 administrator to control it:
130
131 socket-activate --tcp::443 --unix:label=control,user=1000,mode=0600:/run/xyz/control -- \
132 xyzd
133
134
135 SEE ALSO
136 ========
137
138 exec(3), listen(2), runuser(1), sd_listen_fds(3), umask(2)
139
140 AUTHOR
141 ======
142
143 Mark Hindley <[email protected]>
144
145 Originally written for (socket-activate)[https://gitlab.com/dkg/socket-activate] by Daniel Kahn Gillmor <[email protected]>