.\" Automatically generated by Podwrapper::Man 1.32.5 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "nbdkit-exitwhen-filter 1" .TH nbdkit-exitwhen-filter 1 "2023-01-04" "nbdkit-1.32.5" "NBDKIT" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" nbdkit\-exitwhen\-filter \- exit gracefully when an event occurs .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 7 \& nbdkit \-\-filter=exitwhen PLUGIN \& [exit\-when\-file\-created=FILENAME] \& [exit\-when\-file\-deleted=FILENAME] \& [exit\-when\-pipe\-closed=FD] \& [exit\-when\-process\-exits=PID] \& [exit\-when\-script=SCRIPT] \& [exit\-when\-poll=SECS] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`nbdkit\-exitwhen\-filter\*(C'\fR is an nbdkit filter that causes nbdkit to exit gracefully when some external event occurs. Built-in events are: a file being created or deleted, a pipe being closed, or a process exiting. You can also define custom events using an external script or command. .PP After the event occurs nbdkit refuses new connections, waits for all current clients to disconnect, and then exits. .PP A similar filter is \fBnbdkit\-exitlast\-filter\fR\|(1). For other ways to ensure that nbdkit exits when you want see \fBnbdkit\-captive\fR\|(1) and \&\fBnbdkit\-service\fR\|(1). .SH "EXAMPLES" .IX Header "EXAMPLES" .Vb 1 \& nbdkit \-\-filter=exitwhen memory 1G exit\-when\-file\-created=/tmp/stop .Ve .PP nbdkit will run normally until something creates \fI/tmp/stop\fR, whereupon nbdkit will refuse new connections and exit as soon as the last client has disconnected. If \fI/tmp/stop\fR exists before nbdkit starts, it will exit immediately. .PP .Vb 1 \& nbdkit \-\-filter=exitwhen memory 1G exit\-when\-process\-exits=1234 .Ve .PP nbdkit will exit gracefully when \s-1PID 1234\s0 exits and all connections close. If you want to exit when the parent process of nbdkit exits, consider using the \fI\-\-exit\-with\-parent\fR flag instead. .SH "PARAMETERS" .IX Header "PARAMETERS" You can define multiple \f(CW\*(C`exit\-when\-*\*(C'\fR events on the command line: nbdkit will exit if any of the events happens. If there are no \&\f(CW\*(C`exit\-when\-*\*(C'\fR events then the filter does nothing. .IP "\fBexit\-when\-file\-created=\fR\s-1FILENAME\s0" 4 .IX Item "exit-when-file-created=FILENAME" .PD 0 .IP "\fBexit\-when\-file\-deleted=\fR\s-1FILENAME\s0" 4 .IX Item "exit-when-file-deleted=FILENAME" .PD Exit when the named file is created or deleted. .IP "\fBexit\-when\-pipe\-closed=\fR\s-1FD\s0" 4 .IX Item "exit-when-pipe-closed=FD" The read end of a \fBpipe\fR\|(2) is passed to nbdkit in the given file descriptor number. Exit when the pipe is closed. The filter does not read any data from the pipe. .Sp For an example of how to use this parameter, see: https://gitlab.com/nbdkit/nbdkit/\-/blob/master/tests/test\-exitwhen\-pipe\-closed.c .IP "\fBexit\-when\-process\-exits=\fR\s-1PID\s0" 4 .IX Item "exit-when-process-exits=PID" Exit when process \s-1ID\s0 \f(CW\*(C`PID\*(C'\fR exits. .Sp Note there is a small race between passing the process \s-1ID\s0 to the filter and the filter checking it for the first time. During this window the original \s-1PID\s0 might exit and an unrelated program might get the same \s-1PID,\s0 thus holding nbdkit open for longer than wanted. The pipe method above is more reliable if you are able to modify the other process. .ie n .IP "\fBexit\-when\-script=""\fR\s-1SCRIPT\s0\fB""\fR" 4 .el .IP "\fBexit\-when\-script=``\fR\s-1SCRIPT\s0\fB''\fR" 4 .IX Item "exit-when-script=""SCRIPT""" Create a custom event using the script or command \f(CW\*(C`SCRIPT\*(C'\fR. The \&\f(CW\*(C`SCRIPT\*(C'\fR can be a program, shell script or a command with optional parameters. Note if using a filename here: you may need to use the absolute path because nbdkit changes directory when it daemonizes. .Sp The script should exit with code 88 if the event is detected. The filter does different things depending on the exit code of the script: .RS 4 .ie n .IP "0" 4 .el .IP "\f(CW0\fR" 4 .IX Item "0" \&\fIThe event has not been triggered\fR, so nbdkit continues to process requests as normal. .ie n .IP """1\-87""" 4 .el .IP "\f(CW1\-87\fR" 4 .IX Item "1-87" An error is logged, but the event is \fInot\fR triggered and nbdkit continues to process requests as normal. .ie n .IP "88" 4 .el .IP "\f(CW88\fR" 4 .IX Item "88" \&\fIThe event has been triggered\fR. nbdkit will refuse new connections and exit gracefully as soon as all current clients disconnect. .ie n .IP """89\-""" 4 .el .IP "\f(CW89\-\fR" 4 .IX Item "89-" Exit codes 89 and above are reserved for future use. The behaviour may change in future if scripts return any of these exit codes. .RE .RS 4 .RE .IP "\fBexit\-when\-poll=\fR\s-1SECS\s0" 4 .IX Item "exit-when-poll=SECS" When nbdkit is serving clients this filter does not need to poll because it can check for events when a client connects or disconnects. However when nbdkit is idle the filter needs to poll for events every \&\f(CW\*(C`SECS\*(C'\fR seconds and if any event happens exit immediately. .Sp The default is 60 seconds. .SH "NOTES" .IX Header "NOTES" .SS "Compared to \fI\-\-exit\-with\-parent\fP" .IX Subsection "Compared to --exit-with-parent" The nbdkit server option \fI\-\-exit\-with\-parent\fR causes nbdkit to exit when the parent process exits. It seems similar to: .PP .Vb 1 \& nbdkit \-\-filter=exitwhen ... exit\-when\-process\-exits=$$ .Ve .PP (\f(CW$$\fR is the parent \s-1PID\s0 of nbdkit). .PP But there are significant differences caused by the implementation. \&\fI\-\-exit\-with\-parent\fR is implemented using the Linux feature \&\f(CW\*(C`PR_SET_PDEATHSIG\*(C'\fR (\f(CW\*(C`PROC_PDEATHSIG_CTL\*(C'\fR on FreeBSD). This causes a signal to be sent to the server when the parent process dies. On receiving the signal nbdkit closes client connections and terminates at once. .PP On the other hand \f(CW\*(C`exit\-when\-process\-exits\*(C'\fR monitors the other process (which does not need to be the parent) and shuts down the server in a different way: currently open connections are allowed to continue until they close. .PP Neither of these methods is completely reliable in all cases: signals can be lost and there is a possible (albeit very small) race when passing the \s-1PID\s0 to \f(CW\*(C`exit\-when\-process\-exits\*(C'\fR. More reliable methods of clean up are \f(CW\*(C`exit\-when\-pipe\-closed\*(C'\fR or putting all of the processes into a cgroup. (See \fBnbdkit\-captive\fR\|(1) and \&\fBnbdkit\-service\fR\|(1)). .SH "FILES" .IX Header "FILES" .IP "\fI\f(CI$filterdir\fI/nbdkit\-exitwhen\-filter.so\fR" 4 .IX Item "$filterdir/nbdkit-exitwhen-filter.so" The filter. .Sp Use \f(CW\*(C`nbdkit \-\-dump\-config\*(C'\fR to find the location of \f(CW$filterdir\fR. .SH "VERSION" .IX Header "VERSION" \&\f(CW\*(C`nbdkit\-exitwhen\-filter\*(C'\fR first appeared in nbdkit 1.24. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBnbdkit\fR\|(1), \&\fBnbdkit\-exitlast\-filter\fR\|(1), \&\fBnbdkit\-ip\-filter\fR\|(1), \&\fBnbdkit\-limit\-filter\fR\|(1), \&\fBnbdkit\-rate\-filter\fR\|(1), \&\fBnbdkit\-captive\fR\|(1), \&\fBnbdkit\-service\fR\|(1), \&\fBnbdkit\-filter\fR\|(3), \&\fBnbdkit\-plugin\fR\|(3). .SH "AUTHORS" .IX Header "AUTHORS" Richard W.M. Jones .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2020 Red Hat Inc. .SH "LICENSE" .IX Header "LICENSE" Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: .IP "\(bu" 4 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. .IP "\(bu" 4 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. .IP "\(bu" 4 Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. .PP \&\s-1THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS\s0 ''\s-1AS IS\s0'' \s-1AND 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\s0 (\s-1INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES\s0; \s-1LOSS OF USE, DATA, OR PROFITS\s0; \s-1OR BUSINESS INTERRUPTION\s0) \s-1HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\s0 (\s-1INCLUDING NEGLIGENCE OR OTHERWISE\s0) \s-1ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\s0