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 except operation for:

  * --version
  * --dry-run
  * --reg-winsvc
  * --reg-winsvc-fluentdopt
  * --winsvc-name
  * --winsvc-display-name
  * --winsvc-desc

  In other cases, block to launch Fluentd instance by default.
  (It is better to distinguish the actual configuration file.)

Signed-off-by: Kentaro Hayashi <[email protected]>
  • Loading branch information
kenhys committed Feb 19, 2024
1 parent eada0a7 commit e2056b9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions fluent-package/msi/assets/fluentd.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,42 @@ 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_DUP=1
for %%p in (%*) do (
if "%%p"=="--version" (
ruby "%FLUENT_PACKAGE_VERSION%"
goto last
)
if %%p=="--dry-run" (
set FLUENT_GUARD_DUP=0
)
if %%p=="--reg-winsvc" (
set FLUENT_GUARD_DUP=0
)
if %%p=="--reg-winsvc-fluentdopt" (
set FLUENT_GUARD_DUP=0
)
if %%p=="--winsvc-name" (
set FLUENT_GUARD_DUP=0
)
if %%p=="--winsvc-display-name" (
set FLUENT_GUARD_DUP=0
)
if %%p=="--winsvc-desc" (
set FLUENT_GUARD_DUP=0
)
)

@rem Abort if the following conditions are met:
@rem * already service is running
@rem * no registry operation
if %FLUENT_GUARD% eq 1 (
sc query fluentdwinsvc | findstr RUNNING
if !ERRORLEVEL! eq 0 (
exit 2
)
)

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

Expand Down

0 comments on commit e2056b9

Please sign in to comment.