Skip to content

Commit

Permalink
msi: guard multiple Fluentd instance
Browse files Browse the repository at this point in the history
Before:

  Even though fluentdwinsvc is running, you can execute duplicated
  Fluentd instance.
  It may cause inconsistency of buffer or pos file.

After:

  Guard multiple Fluentd instance when fluendwinsvc service is
  running by default.

  Note that --force-running-multiple-instance option is specified, you
  can run additional Fluentd instance explicitly. (it is same as
  previous behavior)

Signed-off-by: Kentaro Hayashi <[email protected]>
  • Loading branch information
kenhys committed Apr 4, 2024
1 parent c5133a4 commit 3c5242d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion fluent-package/msi/assets/fluentd.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,33 @@ set PATH=%FLUENT_PACKAGE_TOPDIR%;%PATH%
set "FLUENT_CONF=%FLUENT_PACKAGE_TOPDIR%/etc/fluent/fluentd.conf"
set "FLUENT_PLUGIN=%FLUENT_PACKAGE_TOPDIR%/etc/fluent/plugin"
set "FLUENT_PACKAGE_VERSION=%FLUENT_PACKAGE_TOPDIR%/bin/fluent-package-version.rb"
set FLUENT_FORCE_RUN=0
set FLUENT_ARGS=
for %%p in (%*) do (
if "%%p"=="--version" (
ruby "%FLUENT_PACKAGE_VERSION%"
goto last
)
if "%%p"=="--force-running-multiple-instance" (
set /a FLUENT_FORCE_RUN=1
) else (
set "FLUENT_ARGS=!FLUENT_ARGS! %%p"
)
)
"%FLUENT_PACKAGE_TOPDIR%/bin/fluentd" %*

@rem Abort if the fluentdwinsvc service is running without --force option.
sc query fluentdwinsvc | findstr RUNNING > nul
if !ERRORLEVEL! equ 0 (
if %FLUENT_FORCE_RUN% equ 1 (
goto noguard
) else (
echo Error: can't start duplicate Fluentd instance. Use --force-running-multiple-instance option explicitly.
exit /b 2
)
)

:noguard
"%FLUENT_PACKAGE_TOPDIR%/bin/fluentd" %FLUENT_ARGS%
endlocal

:last
8 changes: 8 additions & 0 deletions fluent-package/msi/update-from-v4-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ $output_files_after_sleep = Get-ChildItem "C:\\opt\\td-agent\\output"
If ($output_files_after_sleep.Count -le $output_files.Count) {
[Environment]::Exit(1)
}

# Test: Abort if FLUENT_CONF is conflict with fluentdopt
$proc = Start-Process "C:\\opt\\fluent\\fluentd.bat" -Wait -NoNewWindow -PassThru
if ($proc.ExitCode -ne 2) {
Write-Host "Failed to abort when already fluentdwinsvc service is running"
[Environment]::Exit(1)
}
Write-Host "Succeeded to abort if trying to launch multiple Fluentd instance"

0 comments on commit 3c5242d

Please sign in to comment.