exec

The `exec` directive in the NGINX RTMP module allows the execution of external commands or scripts when certain streaming events occur.

Syntaxexec command [arg1 ...];
Defaultnone
Context
Arguments1+

Description

The exec directive is designed to facilitate the integration of external processes into the RTMP event lifecycle, enabling NGINX to execute commands based on the streaming activities. For example, this command can be triggered on events like publish, play, and drop, allowing users to intervene in the streaming workflow with custom behaviors such as logging, notifications, or more sophisticated processing through external scripts. The syntax for this directive involves specifying one or more command strings that will be run when the specified event triggers.

The parameters for the exec directive consist of a command string, and it may include arguments that specify how the external process should be executed. The directive can enhance flexibility by allowing dynamic interactions with other software components and can improve stream management by running scripts that handle additional tasks like bitrate adjustment or stream analytics based on content conditions. It's crucial to handle the outputs and potential errors from the executed commands as NGINX will not manage these processes directly, which requires proper monitoring and debugging of external scripts.

Due to its capabilities, the exec directive should be used with caution, as incorrect implementations may lead to security vulnerabilities or performance penalties if the executed commands are resource-intensive. Additionally, consideration must be taken to ensure that the paths to the executables or scripts are correctly defined relative to the NGINX user context.

Config Example

application live {
    live on;
    exec /path/to/script.sh;
}

Ensure that the external command has the correct permissions to execute.

Commands must be thoroughly tested to avoid performance impacts during streaming.

Output and error handling should be implemented within the external script, as NGINX will not buffer or manage errors. When using the exec directive, user authorization and security implications should be considered to prevent potential vulnerabilities.

← Back to all directives