Closed kenhys closed 1 week ago
This is PoC
Basically it will work, but there is one concern.
If user execute directly c:\opt\fluent\bin\fluentd, it can not be blocked. Usually fluent package prompt will be used, so it is a rare case.
NOTE: search path is like this:
c:\opt\fluent>where fluentd.bat
c:\opt\fluent\fluentd.bat
c:\opt\fluent\bin\fluentd.bat
It should use findstr /I
Verified when fluentdwinsvc is running, it will abort like this:
c:\opt\fluent>fluentd.bat -c c:\opt\fluent\etc\fluent\fluentd.conf
Error: can't start duplicate Fluentd instance with same "c:\opt\fluent\etc\fluent\fluentd.conf"
c:\opt\fluent>fluentd.bat
Error: can't start duplicate Fluentd instance with same c:/opt/fluent/etc/fluent/fluentd.conf
Hmm, it seems that fluentd.bat exit expectedly, but not capture $LASTEXITCODE correctly.
2024-02-20T08:26:44.9840365Z DEBUG: 55+ >>>> Start-Process "C:\\opt\\fluent\\fluentd.bat" -ArgumentList [m [93m
2024-02-20T08:26:44.9842223Z "-c", "C:\\opt\\fluent\\etc\\fluent\\fluentd.conf" -Wait -NoNewWindow[11X[11C[m
2024-02-20T08:26:44.9843565Z [80X[80C
2024-02-20T08:26:45.0579514Z [?25h[?25lError: can't start duplicate Fluentd instance with same C:/opt/fluent/etc/fluent[?25h[?25l
2024-02-20T08:26:45.0580328Z /fluentd.conf[67X[67C
2024-02-20T08:26:45.0580632Z [?25h[?25l
2024-02-20T08:26:45.0580880Z [80X[80C
2024-02-20T08:26:45.9898406Z [?25h[93m[H1[25;1H[?25lDEBUG: 56+ >>>> $exitcode = $LASTEXITCODE[m
2024-02-20T08:26:45.9929166Z [?25h[?25l[93m[H1[25;1H[?25h[?25l[m
2024-02-20T08:26:45.9929643Z [93mDEBUG: 57+ if ( >>>> $exitcode -ne 2) {[m[39X[39C
2024-02-20T08:26:45.9952814Z [?25h[?25l[93m
2024-02-20T08:26:45.9953365Z DEBUG: 58+ >>>> Write-Host "Failed to abort when it is conflict with [m
2024-02-20T08:26:45.9955671Z [?25h[?25l
2024-02-20T08:26:45.9956365Z [93mrunning fluentdwinsvc"[58X[58C
2024-02-20T08:26:45.9986556Z [?25h[?25l[m
2024-02-20T08:26:45.9995251Z Failed to abort when it is conflict with running fluentdwinsvc[18X[18C[25;63H[?25h[?25l
2024-02-20T08:26:45.9996149Z [93mDEBUG: 59+ >>>> [Environment]::Exit(1)[m[35X[35C
2024-02-20T08:26:46.0051281Z [?25h[?25l
2024-02-20T08:26:46.0051698Z [80X[80C
2024-02-20T08:26:50.0433064Z [?25h[93m[HD[25;1H
2024-02-20T08:26:50.0555867Z ##[error]Process completed with exit code 1.
2024-02-20T08:26:50.0788284Z Post job cleanup.
With locally built msi, it work as expected.
PS C:\opt\fluent> .\fluentd.bat
Error: can't start duplicate Fluentd instance with same C:/opt/fluent/etc/fluent/fluentd.conf
PS C:\opt\fluent> $exitcode = $LASTEXITCODE
PS C:\opt\fluent> $exitcode
2
PS C:\opt\fluent>
It's a problem of test code.
It should use -PassThru
and capture with .ExitCode.
Test code was fixed, waiting CI.
All checks has passed.
I've forgot to eliminate --force
from command line arguments.
It was fixed now.
Thanks for considering. If we need a force execution option or a strict check whether the config path is the same in the future, let's revive this!
Note: strict check: https://github.com/fluent/fluent-package-builder/blob/f045a795e8f02c9731262f29a6832d95b40c85a1/fluent-package/msi/assets/fluentd.bat
msi: guard multiple Fluentd instance
Before:
After: