Commit a8da753
committed
Support socket activation for
Add a `--socket-activate` flag that adopts a pre-bound TCP listener
from `LISTEN_FDS` instead of binding a new one. This allows process
managers like foreman (with Socketfile support) or systemd to own the
socket, so it survives server restarts.
Three modes:
- `--socket-activate`: require a passed-in socket, fail if absent
- `--port N` / `--hostname H`: always bind, ignore `LISTEN_FDS`
- Neither: try `LISTEN_FDS` first, fall back to binding the default
The listener is now bound in the main thread before spawning the
server, so the actual address is always known for logging and
`--open`.
Also parse `--port` as `u16` at arg-parse time instead of leaving
it as a string.
Socket activation is normally associated with systemd. And indeed, it
would be peculiar to wire up this development command with systemd, but
it is also used in other contexts more appropriate to this command, like
https://github.com/mitsuhiko/systemfd, a development tool. From a
Capsicum/WASI perspective, it also is generally better when tools can
consume resources provided by a more privileged caller, rather than
having to open them themselves. For these reasons, I think everything
should support socket-activation.mdbook serve
1 parent 9190b5d commit a8da753
3 files changed
Lines changed: 174 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
129 | | - | |
| 130 | + | |
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
| |||
52 | 58 | | |
53 | 59 | | |
54 | 60 | | |
55 | | - | |
| 61 | + | |
56 | 62 | | |
57 | 63 | | |
58 | | - | |
59 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
| |||
69 | 82 | | |
70 | 83 | | |
71 | 84 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
76 | 110 | | |
77 | 111 | | |
78 | 112 | | |
| |||
82 | 116 | | |
83 | 117 | | |
84 | 118 | | |
85 | | - | |
| 119 | + | |
86 | 120 | | |
87 | 121 | | |
88 | | - | |
89 | | - | |
| 122 | + | |
| 123 | + | |
90 | 124 | | |
91 | 125 | | |
92 | 126 | | |
| |||
108 | 142 | | |
109 | 143 | | |
110 | 144 | | |
111 | | - | |
| 145 | + | |
112 | 146 | | |
113 | 147 | | |
114 | 148 | | |
| |||
132 | 166 | | |
133 | 167 | | |
134 | 168 | | |
135 | | - | |
136 | | - | |
137 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
138 | 174 | | |
139 | 175 | | |
140 | 176 | | |
141 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
142 | 186 | | |
143 | 187 | | |
144 | 188 | | |
| |||
0 commit comments