.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Podwrapper::Man 1.36.3 (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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 2024-01-17 nbdkit-1.36.3 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 PID 1234 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=\fRFILENAME 4 .IX Item "exit-when-file-created=FILENAME" .PD 0 .IP \fBexit\-when\-file\-deleted=\fRFILENAME 4 .IX Item "exit-when-file-deleted=FILENAME" .PD Exit when the named file is created or deleted. .IP \fBexit\-when\-pipe\-closed=\fRFD 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=\fRPID 4 .IX Item "exit-when-process-exits=PID" Exit when process ID \f(CW\*(C`PID\*(C'\fR exits. .Sp Note there is a small race between passing the process ID to the filter and the filter checking it for the first time. During this window the original PID might exit and an unrelated program might get the same PID, thus holding nbdkit open for longer than wanted. The pipe method above is more reliable if you are able to modify the other process. .IP "\fBexit\-when\-script=""\fRSCRIPT\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=\fRSECS 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 PID 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 PID 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)). .SS "Query \-\-dump\-plugin output" .IX Subsection "Query --dump-plugin output" Not all events are supported on all platforms. To query which events the filter supports use: .PP .Vb 7 \& $ nbdkit null \-\-filter=exitwhen \-\-dump\-plugin \& [...] \& exitwhen_file_created=yes \& exitwhen_file_deleted=yes \& exitwhen_process_exits=yes \& exitwhen_pipe_closed=yes \& exitwhen_script=yes .Ve .SH FILES .IX Header "FILES" .ie n .IP \fR\fI$filterdir\fR\fI/nbdkit\-exitwhen\-filter.so\fR 4 .el .IP \fR\f(CI$filterdir\fR\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 Red Hat .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 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.