Skip to content

Commit

Permalink
Merge pull request #39 from intergral/no-prompt-option
Browse files Browse the repository at this point in the history
Add option to disable prompts for user input on Windows
  • Loading branch information
ibalal-intergral authored Feb 12, 2024
2 parents 056ff0b + 61fca2d commit 66b28f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ To modify a pre-existing config file, add `--config.file`, followed by the path
`sudo path/to/observability-agent-autoconf.sh --config.file path/to/configfile`
A backup of your original file will be created

To disable prompts that wait for user input, add `--prompt false` as command arguments.

You can use both `--install` and `--config.file` options in the same run command, order is irrelevant. For example: </br>
`sudo path/to/observability-agent-autoconf.sh --install false --config.file path/to/config`</br>
or </br>
Expand Down
33 changes: 31 additions & 2 deletions windows/observability-agent-autoconf.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ while ($args) {
$args = $args[2..$args.Count]
break
}
"--prompt" {
if ($args[1] -eq "false")
{
$PROMPT = $false
}
$args = $args[2..$args.Count]
break
}
default {
Write-Error "Invalid option: $($args[0])"
exit 1
Expand All @@ -43,13 +51,23 @@ if ($INSTALL -ne $false) {
$installPath = "$PSScriptRoot/grafana-agent-flow-installer.exe"

# Download the file
Write-Output "Downloading agent installer"
Invoke-WebRequest -Uri $url -OutFile $outputPath

# Extract the contents of the zip file
Write-Output "Extracting agent installer"
Expand-Archive -Path $outputPath -DestinationPath $installPath -Force

# Run the installer
Start-Process "$installPath\grafana-agent-flow-installer.exe"
Write-Output "Running agent installer"
if ($PROMPT -eq $false)
{
Start-Process "$installPath\grafana-agent-flow-installer.exe" "/S"
}
else
{
Start-Process "$installPath\grafana-agent-flow-installer.exe"
}
}

#Check if an env file exists
Expand Down Expand Up @@ -778,7 +796,7 @@ prometheus.scrape "endpoints" {
Write-Host "Scrape endpoints added"
}

while ($true)
while ($PROMPT -ne $false -and $true)
{
@"
prometheus.scrape "endpoints" {
Expand Down Expand Up @@ -823,5 +841,16 @@ Write-Output "Config file updated"

Move-Item -Path $CONFIG -Destination "C:\Program Files\Grafana Agent Flow\config.river" -Force
Write-Host "Config file can be found at C:\Program Files\Grafana Agent Flow\config.river"

# Service might not be created yet if running script with `--prompt false`
# This attempts to wait until the service can be restarted - there's probably a better way to do this
Write-Output "Attempting to restart service"
$attempts = 0
while ($attempts -le 4 -and (Get-Service -Name "Grafana Agent Flow" -ErrorAction SilentlyContinue) -eq $null)
{
$attempts += 1
Start-Sleep -Seconds 2
}

Restart-Service -Name "Grafana Agent Flow" -Force
Write-Output "Grafana Agent Flow started"

0 comments on commit 66b28f4

Please sign in to comment.