diff --git a/fluent-package/msi/assets/fluentd.bat b/fluent-package/msi/assets/fluentd.bat index d3ca83a87..6220f71fe 100644 --- a/fluent-package/msi/assets/fluentd.bat +++ b/fluent-package/msi/assets/fluentd.bat @@ -14,12 +14,46 @@ 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_CLI= +set /a n=0 +set /a conf_index=0 for %%p in (%*) do ( if "%%p"=="--version" ( ruby "%FLUENT_PACKAGE_VERSION%" goto last ) + if "%%p"=="-c" ( + set /a conf_index=n+1 + ) + if !n! equ !conf_index! ( + set FLUENT_CONF_CLI="%%p" + ) + set /a n=n+1 ) + +@rem Abort if the fluentdwinsvc service is running and conflict with -c ...: +sc query fluentdwinsvc | findstr RUNNING > nul +if !ERRORLEVEL! neq 0 ( + goto noguard +) +@rem extract fluentdopt from registry: (e.g. fluentdopt REG_SZ -c ...) +for /f "usebackq delims=" %%v in (`reg query HKLM\SYSTEM\CurrentControlSet\Services\fluentdwinsvc /v fluentdopt ^| findstr fluentdopt`) do set FLUENTDOPT=%%v +if not "!FLUENT_CONF_CLI!"=="" ( + echo "!FLUENTDOPT:\=/!" | findstr /I /C:!FLUENT_CONF_CLI:\=/! > nul + if !ERRORLEVEL! equ 0 ( + echo Error: can't start duplicate Fluentd instance with same !FLUENT_CONF_CLI! + exit /b 2 + ) +) +if not "!FLUENT_CONF!"=="" ( + echo "!FLUENTDOPT:\=/!" | findstr /I /C:!FLUENT_CONF! > nul + if !ERRORLEVEL! equ 0 ( + echo Error: can't start duplicate Fluentd instance with same !FLUENT_CONF! + exit /b 2 + ) +) + +:noguard "%FLUENT_PACKAGE_TOPDIR%/bin/fluentd" %* endlocal diff --git a/fluent-package/msi/update-from-v4-test.ps1 b/fluent-package/msi/update-from-v4-test.ps1 index 91cf4259a..9836a6596 100644 --- a/fluent-package/msi/update-from-v4-test.ps1 +++ b/fluent-package/msi/update-from-v4-test.ps1 @@ -50,3 +50,20 @@ $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: The previous config works as before +Start-Process "C:\\opt\\fluent\\fluentd.bat" -ArgumentList "/c", "c:\\opt\\fluent\\etc\\fluent\\fluentd.conf" -Wait -NoNewWindow +$exitcode = $LASTEXITCODE +if ($exitcode -ne 2) { + Write-Host "Failed to abort when it is conflict with running fluentdwinsvc" + [Environment]::Exit(1) +} +Write-Host "Succeeded to abort if trying to launch duplicated Fluentd instance" + +Start-Process "C:\\opt\\fluent\\fluentd.bat" -Wait -NoNewWindow +$exitcode = $LASTEXITCODE +if ($exitcode -ne 2) { + Write-Host "Failed to abort without arguments when it is conflict with running fluentdwinsvc" + [Environment]::Exit(1) +} +Write-Host "Succeeded to abort if trying to launch duplicated Fluentd instance without arguments"