-
Notifications
You must be signed in to change notification settings - Fork 1.1k
systemd socket activation support #10072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR adds support for binding to a systemd socket. It's a fairly minor internal change, but it could be useful.
prefer-native-transport: true | ||
listeners: | ||
systemd: | ||
fd: 3 # systemd passes the server socket as fd 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this always 3
?
Or is this dependant on when systemd sets up the socket via the below config?
Are you on a Mac? If so, how did you test this? ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's always 3. and no, i'm on linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we not default the value to 3 if it is always 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it could be 0 if you were using inetd for example. the 3 is systemd-specific, but the fd config option is more generic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ive thought about detecting it from the env variables that systemd sets. but it would be a bit more complicated of a PR, there's no way to test it, it might have negative perf impact, and it is pretty niche in the first place.
this pr is basically the minimum to make it work with systemd with config options only, with no adverse impact since it's a niche feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/systemd/systemd/blob/main/src/systemd/sd-daemon.h#L56
If I'm reading that right, it starts at 3, but if you have multiple services, they'll be on 3 + n
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right. i dont really see a use case for micronaut there though, so i didnt add it to the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I can't test it though, as I don't have Epoll :-(
...src/main/java/io/micronaut/http/server/netty/configuration/NettyHttpServerConfiguration.java
Outdated
Show resolved
Hide resolved
…/configuration/NettyHttpServerConfiguration.java Co-authored-by: Tim Yates <tim.yates@gmail.com>
SonarCloud Quality Gate failed.
|
In #10072, I implemented support for inheriting a ServerSocketChannel from a fixed file descriptor to support systemd socket activation. This PR extends that in two ways: - Allow specifying an "accepted FD". That means an established *connection* (SocketChannel), not a listening socket (ServerSocketChannel). This allows for inetd-style socket activation which starts a process for each connection. - Add support for nio when fd=0 or accepted-fd=0, using System.inheritedChannel().
* Accept inetd-style FDs In #10072, I implemented support for inheriting a ServerSocketChannel from a fixed file descriptor to support systemd socket activation. This PR extends that in two ways: - Allow specifying an "accepted FD". That means an established *connection* (SocketChannel), not a listening socket (ServerSocketChannel). This allows for inetd-style socket activation which starts a process for each connection. - Add support for nio when fd=0 or accepted-fd=0, using System.inheritedChannel(). * add since * sonar
This PR adds support for binding to a systemd socket. It's a fairly minor internal change, but it could be useful.