Skip to content

Commit 8b71296

Browse files
fix windows ingest script (#1699)
* fix windows ingest script * use PSScriptRoot join path
1 parent f307c49 commit 8b71296

1 file changed

Lines changed: 27 additions & 19 deletions

File tree

scripts/ingest.ps1

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ $CONFIG_FILE = "$PSScriptRoot\fluent-bit.conf"
2323
$PID_FILE = "$PSScriptRoot\fluent-bit.pid"
2424
$LOG_FILE = "$PSScriptRoot\fluent-bit.log"
2525
$ERROR_LOG_FILE = "$PSScriptRoot\fluent-bit.err.log"
26+
$SCRIPT_PATH = $PSCommandPath
27+
if ([string]::IsNullOrWhiteSpace($SCRIPT_PATH)) {
28+
$SCRIPT_PATH = $MyInvocation.MyCommand.Path
29+
}
30+
if ([string]::IsNullOrWhiteSpace($SCRIPT_PATH)) {
31+
$SCRIPT_PATH = Join-Path $PSScriptRoot "ingest.ps1"
32+
}
33+
$SCRIPT_CMD = "powershell -NoProfile -ExecutionPolicy Bypass -File '$SCRIPT_PATH'"
2634

2735
$SUPPORTED_ARCH = @("AMD64", "ARM64")
2836

@@ -90,8 +98,8 @@ function Show-Status {
9098
Write-Info "Log file: $LOG_FILE"
9199
Write-Info "Error log file: $ERROR_LOG_FILE"
92100
Write-Host ""
93-
Write-Info "To see logs: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 logs"
94-
Write-Info "To stop: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 stop"
101+
Write-Info "To see logs: $SCRIPT_CMD logs"
102+
Write-Info "To stop: $SCRIPT_CMD stop"
95103
}
96104
else {
97105
Write-Warning "Fluent Bit is not running"
@@ -202,7 +210,7 @@ function Start-FluentBit {
202210
if (Test-FluentBitRunning) {
203211
$processId = Get-Content $PID_FILE
204212
Write-Warning "Fluent Bit is already running (PID: $processId)"
205-
Write-Info "Use 'ingest.ps1 stop' to stop it first"
213+
Write-Info "Use '$SCRIPT_CMD stop' to stop it first"
206214
return
207215
}
208216

@@ -241,17 +249,17 @@ function Start-FluentBit {
241249

242250
if (-not $stillRunning) {
243251
Write-ErrorMsg "Fluent Bit exited immediately"
244-
Write-ErrorMsg "Run '.\ingest.ps1 debug' to see error details"
252+
Write-ErrorMsg "Run '$SCRIPT_CMD debug' to see error details"
245253
Remove-Item $PID_FILE -ErrorAction SilentlyContinue
246254
exit 1
247255
}
248256
else {
249257
Write-Info "Fluent Bit started successfully (PID: $($process.Id))"
250258
Write-Host ""
251-
Write-Info "To debug: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 debug"
252-
Write-Info "To check status: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 status"
253-
Write-Info "To see logs: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 logs"
254-
Write-Info "To stop: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 stop"
259+
Write-Info "To debug: $SCRIPT_CMD debug"
260+
Write-Info "To check status: $SCRIPT_CMD status"
261+
Write-Info "To see logs: $SCRIPT_CMD logs"
262+
Write-Info "To stop: $SCRIPT_CMD stop"
255263
}
256264
}
257265

@@ -359,17 +367,17 @@ function Show-Help {
359367
Fluent Bit Setup and Management Script for Windows
360368
361369
Usage:
362-
Setup: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 [host[:port]] [stream] [api_key] [tenant_id]
363-
Stop: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 stop
364-
Start: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 start
365-
Restart: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 restart
366-
Status: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 status
367-
Logs: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 logs
368-
Debug: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 debug
370+
Setup: $SCRIPT_CMD [host[:port]] [stream] [api_key] [tenant_id]
371+
Stop: $SCRIPT_CMD stop
372+
Start: $SCRIPT_CMD start
373+
Restart: $SCRIPT_CMD restart
374+
Status: $SCRIPT_CMD status
375+
Logs: $SCRIPT_CMD logs
376+
Debug: $SCRIPT_CMD debug
369377
370378
Example:
371-
powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 https://your-host.com:443 node-metrics px_api_key
372-
powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 http://localhost:8000 node-metrics px_api_key tenant-id
379+
$SCRIPT_CMD https://your-host.com:443 node-metrics px_api_key
380+
$SCRIPT_CMD http://localhost:8000 node-metrics px_api_key tenant-id
373381
374382
"@
375383
}
@@ -425,8 +433,8 @@ switch ($Param1.ToLower()) {
425433
}
426434
default {
427435
if ([string]::IsNullOrWhiteSpace($Param2) -or [string]::IsNullOrWhiteSpace($Param3)) {
428-
Write-ErrorMsg "Usage: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 [host[:port]] [stream] [api_key] [tenant_id]"
429-
Write-ErrorMsg " Or: powershell -NoProfile -ExecutionPolicy Bypass -File .\ingest.ps1 [start|stop|restart|status|logs|debug|help]"
436+
Write-ErrorMsg "Usage: $SCRIPT_CMD [host[:port]] [stream] [api_key] [tenant_id]"
437+
Write-ErrorMsg " Or: $SCRIPT_CMD [start|stop|restart|status|logs|debug|help]"
430438
exit 1
431439
}
432440
Setup-FluentBit -IngestorHost $Param1 -StreamName $Param2 -ApiKey $Param3 -TenantId $Param4

0 commit comments

Comments
 (0)