How to reload or stop the nbd-server

block-devicenetworkingservice

I'm running nbd-server on Debian (nbd-server package) with my config at /etc/nbd-server/config, but then I might change the config and need to reload. How can I do that?

  • man nbd-server has nothing on this

All I can use is kill PID and killall nbd-server to stop or restart it. There must be a command like nbd-server --reload or somehting.

What is the right way to do this to reload the ndb-server config after making changes?

What is the right way to stop the nbd-server if I don't want it running anymore?

Best Answer

In my version of the nbd-server man page, it says in the "DESCRIPTION" section:

While nbd-server is running, new exports can be added by re-writing configuration files and then sending SIGHUP to nbd-server. SIGHUP causes nbd-server to re-read its configuration files and to start serving all new exports which were not served earlier. Reconfiguration does not modify any existing export, it only appends new ones.

You can see this online here.

You can send SIGHUP to nbd-server using the kill command:

kill -HUP <ndb-server pid>

You can try signalling it by name, using either killall or pkill...

killall -HUP nbd-server

Or:

pkill -HUP nbd-server

...but note that there is an additional nbd-server process for every active connection, and I'm not sure how these processes respond to SIGHUP. A better option is just to configure a systemd unit for the service and then use systemctl reload nbd-server, and let systemd worry about keeping track of the main pid.


Update: It looks like the version of nbd-server in Debian stable (3.24) is buggy. Sending SIGHUP to the nbd-server process causes it to fail with an invalid pointer error:

root@1f457c3e03fd:/etc/nbd-server/conf.d# nbd-server -d
free(): invalid pointer
Aborted (core dumped)

If you upgrade to the version in sid (3.26.1), it behaves as expected: sending SIGHUP to the process causes it to load any new configuration files, but does not impact existing clients. The server continues to run instead of crashing.