Fluentd
Search…
Plugin Helper: Child Process
The child_process helper manages the child processes' lifecycle.
Here is an example:
1
require 'fluent/plugin/output'
2
3
module Fluent::Plugin
4
class ExampleOutput < Output
5
Fluent::Plugin.register_output('example', self)
6
7
# 1. Load child_process helper
8
helpers :child_process
9
10
# Omit configure, shutdown and other plugin API
11
12
def start
13
super
14
# 2. Execute child process with unique name
15
child_process_execute(:exec_external_command, 'external_command', immediate: true, mode: [:read]) do
16
# ...
17
end
18
end
19
end
20
end
Copied!
The launched child process is managed by the plugin helper which automatically shutdowns it.

Methods

child_process_execute(title, sub_process_name, arguments: nil, subprocess_name: nil, interval: nil, immediate: false, parallel: false, mode: [:read, :write], stderr: :discard, env: {}, unsetenv: false, chdir: nil, internal_encoding: 'utf-8', external_encoding: 'ascii-8bit', scrub: true, replace_string: nil, wait_timeout: nil, on_exit_callback: nil, &block)

This method executes child_process with the given parameters and routine.
    title: unique symbol value
    sub_process_name: sub process name value
    interval: Second unit integer/float value.
    immediate: true/false. Default is false.
    parallel: true/false. Default is false.
    mode: [:read, :write]. Default is [:read, :write].
    stderr: Connect stderr or not. Default is :discard.
    env: Environment valuables. Default is {}.
    unsetenv: true/false. Default is false
    chdir: Working directory. Default is nil.
    internal_encoding: Internal character encoding. Default is utf-8.
    external_encoding: External character encoding. Default is ascii-8bit'
    scrub: true/false. Default is true.
    replace_string: Replace the invalid code point with the specified character.
    Default is nil.
    wait_timeout: Set timeout seconds. Default is nil.
    on_exit_callback: Set callback function. Default is nil
Code examples:
1
# Pass block directly. block is executed with 10 second interval.
2
child_process_execute(:exec_awesome_command, @command, interval: 10, mode: [:read]) do |io|
3
# ...
4
end
5
6
# Pass block with existing method. block is executed once.
7
child_process_execute(:exec_awesome_command, @command, immediate: true, mode: [:read], &method(:run))
8
9
def run(io)
10
# ...
11
end
Copied!

Plugins using child_process

If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.
Last modified 4mo ago