Skip to content

Commit

Permalink
msi: guard duplicated 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 duplicated Fluentd instance when the following conditions are
  met:

  * fluentdwinsvc service is running
  * .conf is specified in fluentdopt registry value
  * fluentd.bat -c ... is specified and match to fluentdopt value

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
  • Loading branch information
kenhys committed Feb 20, 2024
1 parent eada0a7 commit 49fe97a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions fluent-package/msi/assets/fluentd.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,43 @@ 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_GUARD_CHECK=0
set FLUENT_CONF=
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
set /a FLUENT_GUARD_CHECK=1
)
if !n! equ !conf_index! (
set FLUENT_CONF="%%p"
)
set /a n=n+1
)

@rem Abort if the fluentdwinsvc service is running and conflict with -c ...:
if !FLUENT_GUARD_CHECK! equ 1 (
sc query fluentdwinsvc | findstr RUNNING > nul
if !ERRORLEVEL! neq 0 (
goto running
)
@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!"=="" (
echo "!FLUENTDOPT!" | findstr /C:!FLUENT_CONF! > nul
if !ERRORLEVEL! equ 0 (
echo Error: can't start duplicate Fluentd instance with same !FLUENT_CONF!
exit /b 2
)
)
)

:running
"%FLUENT_PACKAGE_TOPDIR%/bin/fluentd" %*
endlocal

Expand Down

0 comments on commit 49fe97a

Please sign in to comment.