couchdb
couchdb copied to clipboard
Implement socket activation for couchdb
Hi,
systemd offers a particular way to start daemons called "socket activation", where systemd does not start a daemon at boot time as a service unit, but itself occupies an inet or unix domain socket, and once that socket is connected for the first time, starts a daemon and passes the socket to the daemon. Very similar to what inetd did on older linux systems, but there is two ways to pass the socket now. See man systemd.socket or google for "socket activation".
Advantage is, that a daemon (here: couchdb server) is not always running, but started only, if it is actually used for the first time.
A daemon/server needs to be able to take a socket handed over instead of a regular bind. Furthermore, it should have some timeout parameter to shut itself down after a given time without connections.
I did not find any documentation about for couchdb, so my guess is that it hasn't been implemented yet.
regards
Thanks for reaching out @hadmut, and thanks for the neat idea! I think it might be interesting to have it, but yeah, agree, I think it would depend first of all on a solid support from Erlang OTP + mochiweb (our web library) to be able to take a file descriptor from systemd. I think it would be quite a bit for work implement that from scratch ourselves.
Caching is vital to couchdb as is the processing we do when opening databases and indexes, it doesn't make sense to me for couchdb to start on demand.
Oh, it doesn't mean to restart it for every single request. And it doesn't mean terminating after a connection. Once started, it should run for a given time period after last use.
But if you do use CouchDB only occasionally, as I do, why should it consume memory, boot time, battery power, if it isn't used most of the time? After all, I am just asking for supporting it, not for enforcing it, thus leaving the decision to the admin.
Especially for a non-centralized structure as couchdb has, it makes sense to start couchdb (e.g. on desktop machines, notebooks, ...) only if actually needed, and not on every boot.
And, btw., that's what good 'ole inetd or modern systemd socket activation is made for.
Ok, I get it. It might be a nice (if niche) feature though I wouldn't want to tie it to systemd.
Couchdb is already tied to systemd, because that's the way it is started on modern systems. We're not in the System V or BSD days anymore.
It's just a modification of the way systemd starts couchdb, to make it even more modern. As an option.
Couchdb is already tied to systemd, because that's the way it is started on modern systems. We're not in the System V or BSD days anymore.
For what it is worth, the FreeBSD port of CouchDB still uses an rc.d script to start and stop the application. I believe that is a different conversation to decide if FreeBSD constitutes a modern system, but it proves that CouchDB could be managed without systemd.
systemd certainly not a requirement for couchdb, and I agree that's a separate discussion.
A pull request adding this as an option (off by default) against https://github.com/apache/couchdb-pkg seems the next step. we can review the details there.