Feature request: systemd notification and socket activation
Please support systemd service notification (i.e. tell systemd when the service is up and running) sd_notify and socket activation sd_listen_fds_with_names.
sd_notify should be a no-brainer (its manpage has a standalone implementation if you don't want to link to systemd's libraries) and is somewhat essential; socket activation is kindof optional but would be very-nice-to-have.
My usecase for this is that I start several services which want to talk MQTT, and occasionally one of them is "too fast" and tries to open the MQTT socket before FlashMQ has opened it. I'd rather solve this like it's supposed to be solved instead of adding ExecStartPre=sleep 1 stanzas everywhere.
Both are tricky. Socket activation is (probably) incompatible with FlashMQ's ability to add and create listeners at random on SIGHUP. I've had similar issues before with Ubuntu's socket activcation, that changing the SSH port doesn't take effect.
As for the sd_notify; I'd have to look at the stand-alone implementation, because I indeed don't want to link against systemd; see the whole libzma hack. Had distros not patched SSHd to link to systemd, that hack would not have been possible.
Anyway, 'being ready' is complicated when you have a plugin. I run servers that take 30s until the auth data is loaded. The plugin code returns 'server not available' until then. In this case, the sd_notify needs to be tied to the plugin being ready.
Needs some thinking.
Fortunately, socket activation is just a list of named file descriptors (names are optional on systemd's side but flashmq should insist on them). So your initial setup would do "if this listener's name is in the list we got from systemd, use the corresponding file descriptor, instead call socket+bind as usual".
While systemd would keep the sockets open independently as long as the socket unit is active, incoming connections on them are ignored while flashmq is running … and on (re)start you can always check that the incoming socket's local port does match your configuration, and that systemd doesn't pass you file descriptors you can't associate with a listener. It's just a couple of environment variables, after all.
NB one additional interesting aspect of socket activation is that even if you don't use systemd's socket units you can use the sd_notify protocol to pass a bunch of (again, named) file descriptors to it so that when flashmq is restarted everything's back up with zero downtime and zero lost connections.