Skip to content
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

Add support for "sd_listen_fds" socket activation socket support for gRPC and HTTP listeners #589

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

networkException
Copy link

@networkException networkException commented Sep 30, 2024

What this PR does:

This pull request adds support for server to be used with systemd's socket activation by expecting an open file descriptor to be announced using environment variables.

To make use of this set either HTTPListenNetwork or GRPCListenNetwork to "sd_listen_fd" and HTTPListenAddress or GRPCListenAddress either to an ASCII string passed as the FileDescriptorName= from a systemd.socket unit or "LISTEN_FD_$n", where $n is the file descriptor number, starting with 3 (SD_LISTEN_FDS_START).

By default, when using "sd_listen_fd", the address will be "LISTEN_FD_3".

This patch makes use of the coreos/go-systemd/v22/activation library (which was already included as an indirect dependency). Unfortunately their implementation doesn't allow call sites to get a view of the listeners both by file descriptor number and file descriptor name, as the highlevel helpers cannot be used.

This is similar in spirit to #511, I'll happily include unix socket support in the listen helper this change introduces as part of the rebase.

Which issue(s) this PR fixes:

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@CLAassistant
Copy link

CLAassistant commented Sep 30, 2024

CLA assistant check
All committers have signed the CLA.

@networkException networkException force-pushed the network-sd_listen_fd branch 2 times, most recently from a8486aa to e379e75 Compare September 30, 2024 21:12
@networkException networkException force-pushed the network-sd_listen_fd branch 7 times, most recently from 3a887b3 to 7a0b45a Compare October 9, 2024 20:00
This patch adds support for server to be used with systemd's
socket activation by expecting an open file descriptor to be
announced using environment variables.

To make use of this set either HTTPListenNetwork or
GRPCListenNetwork to "sd_listen_fd" and HTTPListenAddress
or GRPCListenAddress either to an ASCII string passed as
the "FileDescriptorName" from a systemd.socket unit or
"LISTEN_FD_$n", where $n is the file descriptor number.

By default, when using "sd_listen_fd", the address will
be "LISTEN_FD_3".

This patch makes use of the coreos/go-systemd/v22/activation
library (which was already included as an indirect dependency).
Unfortunately their implementation doesn't allow call sites to
get a view of the listeners both by file descriptor number and
file descriptor name, as the highlevel helpers cannot be used.

See https://www.freedesktop.org/software/systemd/man/latest/systemd.socket.html#FileDescriptorName=
@networkException networkException marked this pull request as ready for review October 9, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants