nbdkit-service(1) | NBDKIT | nbdkit-service(1) |
nbdkit-service - running nbdkit as a service, and systemd socket activation
Most people start nbdkit from the command line or run it from another program (see nbdkit-captive(1). It is also possible to run nbdkit as a standalone service, which is what this page describes.
nbdkit supports socket activation (sometimes called systemd socket activation). This is a simple protocol where instead of nbdkit itself opening the listening socket(s), the parent process (typically systemd) passes in pre-opened file descriptors. Socket activation lets you serve infrequent NBD requests using a superserver without needing nbdkit to be running the whole time.
Socket activation is triggered when both the "LISTEN_FDS" and "LISTEN_PID" environment variables are set. In this mode using -i, -p, --run, -s or -U flags on the command line is illegal and will cause an error. Also in this mode nbdkit does not fork into the background (ie. -f is implied).
To use nbdkit with socket activation from systemd, create a unit file ending in ".socket" (eg. "/etc/systemd/system/nbdkit.socket") containing:
[Unit] Description=NBDKit Network Block Device server [Socket] ListenStream=10809 [Install] WantedBy=sockets.target
There are various formats for the "ListenStream" key. See systemd.socket(5) for more information.
Also create a service unit (eg. "/etc/systemd/system/nbdkit.service") containing:
[Service] ExecStart=/usr/sbin/nbdkit file /path/to/serve
For more information on systemd and socket activation, see http://0pointer.de/blog/projects/socket-activation.html
Error messages from nbdkit can be sent to either standard error (--log=stderr) or to the system log (--log=syslog).
The default, if --log is not specified on the command line, is to send error messages to stderr, unless nbdkit forks into the background in which case they are sent to syslog.
In detail:
When using systemd socket activation.
Using --log=stderr forces all messages to go to standard error.
Using --log=syslog forces all messages to go to the system log.
Debug messages (-v/--verbose) always go to standard error and are never sent to the system log.
nbdkit(1), systemd(1), systemd.socket(5), syslog(3), rsyslogd(8), journalctl(1).
Eric Blake
Richard W.M. Jones
Pino Toscano
Copyright (C) 2013-2018 Red Hat Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2019-01-26 | nbdkit-1.10.3 |