diff --git a/fluent-package/msi/assets/fluentd.bat b/fluent-package/msi/assets/fluentd.bat index 061497626..b4ba3d97a 100644 --- a/fluent-package/msi/assets/fluentd.bat +++ b/fluent-package/msi/assets/fluentd.bat @@ -15,11 +15,37 @@ set "FLUENT_PLUGIN=%FLUENT_PACKAGE_TOPDIR%etc/fluent/plugin" setlocal set "FLUENT_PACKAGE_VERSION=%FLUENT_PACKAGE_TOPDIR%bin/fluent-package-version.rb" +set HAS_DRY_RUN_OPTION=0 +set HAS_CONFIG_OPTION=0 +set HAS_SHORT_VERBOSE_OPTION=0 + for %%p in (%*) do ( if "%%p"=="--version" ( ruby "%FLUENT_PACKAGE_VERSION%" goto last ) + if "%%p"=="--dry-run" set HAS_DRY_RUN_OPTION=1 + if "%%p"=="-c" set HAS_CONFIG_OPTION=1 + if "%%p"=="--config" set HAS_CONFIG_OPTION=1 + if "%%p"=="-v" set HAS_SHORT_VERBOSE_OPTION=1 +) + +@rem Abort if the fluentdwinsvc service is running and the config path is not specified. +if %HAS_DRY_RUN_OPTION% equ 0 if %HAS_CONFIG_OPTION% equ 0 ( + sc query fluentdwinsvc | findstr RUNNING > nul 2>&1 + if %ERRORLEVEL% equ 0 ( + echo Error: Can't start duplicate Fluentd instance with the default config. + if %HAS_SHORT_VERBOSE_OPTION% equ 1 ( + echo. + echo To take the version, please use '--version', not '-v' ^('--verbose'^). + ) + echo. + echo To start Fluentd, please do one of the following: + echo ^(Caution: Please be careful not to start multiple instances with the same config.^) + echo - Stop the Fluentd Windows service 'fluentdwinsvc'. + echo - Specify the config path explicitly by '-c' ^('--config'^). + exit /b 2 + ) ) endlocal diff --git a/fluent-package/msi/install-test.ps1 b/fluent-package/msi/install-test.ps1 index e5cb99a78..430d91971 100644 --- a/fluent-package/msi/install-test.ps1 +++ b/fluent-package/msi/install-test.ps1 @@ -41,6 +41,29 @@ Get-ChildItem "C:\\opt\\fluent\\*.log" | %{ } } +# Test: fluentd.bat +$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 when already fluentdwinsvc service is running" + +$proc = Start-Process "C:\\opt\\fluent\\fluentd.bat" -ArgumentList "--version" -Wait -NoNewWindow -PassThru +if ($proc.ExitCode -ne 0) { + Write-Host "Failed to take the version" + [Environment]::Exit(1) +} +Write-Host "Succeeded to take the version" + +$proc = Start-Process "C:\\opt\\fluent\\fluentd.bat" -ArgumentList "--dry-run" -Wait -NoNewWindow -PassThru +if ($proc.ExitCode -ne 0) { + Write-Host "Failed to dry-run" + [Environment]::Exit(1) +} +Write-Host "Succeeded to dry-run" + +# Test: Uninstall $msi -Match "fluent-package-([0-9\.]+)-.+\.msi" $name = "Fluent Package v" + $matches[1] Write-Host "Uninstalling ...${name}"