From 2a68179773d46f6ff0becd02001c64c5c76f6593 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Mon, 19 Feb 2024 18:20:33 +0900 Subject: [PATCH 1/2] msi: guard multiple Fluentd instance 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 --- fluent-package/msi/assets/fluentd.bat | 22 +++++++++++++++++++++- fluent-package/msi/update-from-v4-test.ps1 | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/fluent-package/msi/assets/fluentd.bat b/fluent-package/msi/assets/fluentd.bat index d3ca83a87..81bd06fa4 100644 --- a/fluent-package/msi/assets/fluentd.bat +++ b/fluent-package/msi/assets/fluentd.bat @@ -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 diff --git a/fluent-package/msi/update-from-v4-test.ps1 b/fluent-package/msi/update-from-v4-test.ps1 index 1fa41ef4f..c4a764e7a 100644 --- a/fluent-package/msi/update-from-v4-test.ps1 +++ b/fluent-package/msi/update-from-v4-test.ps1 @@ -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" From 230c25a6d16db25f436cfa84b4b6ee5eafd66102 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Thu, 29 Feb 2024 18:09:01 +0900 Subject: [PATCH 2/2] msi: remove extra trailing / %FLUENT_PACKAGE_TOPDIR% contains trailing /, so it is redundant to add /. Signed-off-by: Kentaro Hayashi --- fluent-package/msi/assets/fluentd.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fluent-package/msi/assets/fluentd.bat b/fluent-package/msi/assets/fluentd.bat index 81bd06fa4..33fa4d668 100644 --- a/fluent-package/msi/assets/fluentd.bat +++ b/fluent-package/msi/assets/fluentd.bat @@ -11,9 +11,9 @@ set FLUENT_PACKAGE_TOPDIR=!FLUENT_PACKAGE_TOPDIR:\=/! set PATH=%FLUENT_PACKAGE_TOPDIR%bin;%PATH% 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_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 (