|
NAMEnbdkit-captive - run nbdkit under another process and have it reliably cleaned upSYNOPSISnbdkit PLUGIN [...] --run "CMD ARGS ..." nbdkit --exit-with-parent PLUGIN [...] DESCRIPTIONYou can run nbdkit under another process and have nbdkit reliably clean up. There are two techniques depending on whether you want nbdkit to start the other process ("CAPTIVE NBDKIT"), or if you want the other process to start nbdkit ("EXIT WITH PARENT"). Another way is to have nbdkit exit after the last client connection, see nbdkit-exitlast-filter(1).CAPTIVE NBDKITYou can run nbdkit as a "captive process", using the --run option. This means that nbdkit runs as long as (for example) qemu(1) or guestfish(1) is running. When those exit, nbdkit is killed.Some examples should make this clear. To run nbdkit captive under qemu: nbdkit file disk.img --run 'qemu -drive file=$nbd,if=virtio' On the qemu command line, $nbd is substituted automatically with the right NBD path so it can connect to nbdkit. When qemu exits, nbdkit is killed and cleaned up automatically. Running nbdkit captive under guestfish: nbdkit file disk.img --run 'guestfish --format=raw -a $nbd -i' When guestfish exits, nbdkit is killed. The following shell variables are available in the --run argument:
--run implies --foreground. It is not possible, and probably not desirable, to have nbdkit fork into the background when using --run. Even when running captive, nbdkit still listens on the regular TCP/IP port, unless you specify the -p/-U options. If you want a truly private captive nbdkit, then you should create a private random Unix socket, like this: nbdkit -U - plugin [args] --run '...' Copying data in and out of plugins with captive nbdkitCaptive nbdkit + qemu-img(1) can be used to copy data into and out of nbdkit plugins. For example nbdkit-example1-plugin(1) contains an embedded disk image. To copy it out:nbdkit -U - example1 --run 'qemu-img convert $nbd disk.img' If plugin requests have a high overhead (for example making HTTP requests to a remote server), adding nbdkit-readahead-filter(1) may help performance: nbdkit -U - --filter=readahead curl https://example.com/disk.img \ --run 'qemu-img convert $nbd disk.img' If the source suffers from temporary network failures nbdkit-retry-filter(1) may help. To overwrite a file inside an uncompressed tar file (the file being overwritten must be the same size), use nbdkit-tar-plugin(1) like this: nbdkit -U - tar tar=data.tar file=disk.img \ --run 'qemu-img convert -n disk.img $nbd' EXIT WITH PARENTThe --exit-with-parent option is almost the opposite of "CAPTIVE NBDKIT" described in the previous section.Running nbdkit with this option, for example from a script: nbdkit --exit-with-parent plugin ... & means that nbdkit will exit automatically if the parent program exits for any reason. This can be used to avoid complicated cleanups or orphaned nbdkit processes. --exit-with-parent is incompatible with forking into the background (because when we fork into the background we lose track of the parent process). Therefore -f / --foreground is implied. This is currently implemented using a non-POSIX feature available in Linux ≥ 2.1.57 and FreeBSD ≥ 11.2, so it won't work on other operating systems (patches welcome to make it work). If the parent application is multithreaded, then (in the Linux implementation) if the parent thread exits, that will cause nbdkit to exit. Thus in multithreaded applications you usually want to run "nbdkit --exit-with-parent" only from the main thread (unless you actually want nbdkit to exit with the thread, but that may not work reliably on all operating systems). SEE ALSOnbdkit(1), nbdkit-exitlast-filter(1), prctl(2) (on Linux), procctl(2) (on FreeBSD).AUTHORSEric BlakeRichard W.M. Jones Pino Toscano COPYRIGHTCopyright (C) 2013-2020 Red Hat Inc.LICENSERedistribution 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.
Visit the GSP FreeBSD Man Page Interface. |