go-nbd icon indicating copy to clipboard operation
go-nbd copied to clipboard

Support socket activation

Open rwmjones opened this issue 11 months ago • 1 comments

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:

  • the parent process will set LISTEN_PID to your PID. Check that getpid() matches this, otherwise ignore the systemd socket activation
  • the parent process will set LISTEN_FDS to some number, usually 1. Inherited file descriptors 3, 4, ... (up to the number of LISTEN_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

rwmjones avatar Mar 24 '24 15:03 rwmjones

(Adding @ebblake)

rwmjones avatar Mar 24 '24 15:03 rwmjones

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.

pojntfx avatar Jul 30 '24 23:07 pojntfx