Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msi: guard duplicated instance (not adding a new option) #648

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion fluent-package/msi/assets/fluentd.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,40 @@ 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"

setlocal
setlocal enabledelayedexpansion
set "FLUENT_PACKAGE_VERSION=%FLUENT_PACKAGE_TOPDIR%bin/fluent-package-version.rb"
set PREVENT_DUPLICATE_LAUNCH=1
set HAS_SHORT_VERBOSE_OPTION=0

for %%p in (%*) do (
if "%%p"=="--version" (
ruby "%FLUENT_PACKAGE_VERSION%"
goto last
)
if "%%p"=="-c" set PREVENT_DUPLICATE_LAUNCH=0
if "%%p"=="--config" set PREVENT_DUPLICATE_LAUNCH=0
if "%%p"=="--dry-run" set PREVENT_DUPLICATE_LAUNCH=0
if "%%p"=="--reg-winsvc" set PREVENT_DUPLICATE_LAUNCH=0
if "%%p"=="--reg-winsvc-fluentdopt" set PREVENT_DUPLICATE_LAUNCH=0
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 %PREVENT_DUPLICATE_LAUNCH% equ 1 (
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

Expand Down
35 changes: 35 additions & 0 deletions fluent-package/msi/install-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,41 @@ Get-ChildItem "C:\\opt\\fluent\\*.log" | %{
}
}

# Test: fluentd.bat
Start-Service fluentdwinsvc

$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"

$fluentdopt = "-c 'C:\opt\fluent\etc\fluent\fluentd.conf' -o 'C:\opt\fluent\fluentd.log' -v"
$proc = Start-Process "C:\\opt\\fluent\\fluentd.bat" -ArgumentList "--reg-winsvc-fluentdopt ""$fluentdopt""" -Wait -NoNewWindow -PassThru
$fluentdoptResult = Get-ItemPropertyValue -Path HKLM:\SYSTEM\CurrentControlSet\Services\fluentdwinsvc -Name fluentdopt
if ($proc.ExitCode -ne 0 -or $fluentdopt -ne $fluentdoptResult) {
Write-Host "Failed to register fluentdopt"
[Environment]::Exit(1)
}
Write-Host "Succeeded to register fluentdopt"

# Test: Uninstall
Stop-Service fluentdwinsvc
$msi -Match "fluent-package-([0-9\.]+)-.+\.msi"
$name = "Fluent Package v" + $matches[1]
Write-Host "Uninstalling ...${name}"
Expand Down
Loading