Closed rwmjones closed 3 months ago
(Adding @ebblake)
Similarly to https://github.com/pojntfx/go-nbd/issues/11#issuecomment-2259370646 this isn't really something that would be part of the scope of this library. We don't create the listener in this library, that is up to the consumer.
To make go-nbd easier to use from libnbd or systemd, you should probably add support for systemd socket activation. This doesn't require or involve libnbd or systemd, it just means you parse a few environment variables in a standardized way. Many, many servers of all kinds support this protocol, eg. Apache.
In its simplest form:
LISTEN_PID
to your PID. Check that getpid() matches this, otherwise ignore the systemd socket activationLISTEN_FDS
to some number, usually1
. Inherited file descriptors 3, 4, ... (up to the number ofLISTEN_FDS
) are listening sockets that you should accept on.If this was enabled, then you'd be able to start up go-nbd either from a systemd unit or (more interesting to me) from this libnbd call: https://libguestfs.org/nbd_connect_systemd_socket_activation.3.html
Example of code that does this in nbdkit:
https://gitlab.com/nbdkit/nbdkit/-/blob/master/server/socket-activation.c?ref_type=heads