Windows agent install script improvements

- Remove unneeded set-executionpolicy (in parent command)
- Wait before checking status
- Use direct binary path instead of shim
- Log to one file

Co-authored-by: vmhomelab <info@vmhomelab.de>
This commit is contained in:
henrygd
2025-04-13 19:54:06 -04:00
parent 54e3f3eba1
commit 5d840bd473

View File

@@ -28,7 +28,6 @@ if (-not $Elevated) {
Write-Host "Scoop is already installed." Write-Host "Scoop is already installed."
} else { } else {
Write-Host "Installing Scoop..." Write-Host "Installing Scoop..."
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
if (-not (Get-Command scoop -ErrorAction SilentlyContinue)) { if (-not (Get-Command scoop -ErrorAction SilentlyContinue)) {
@@ -93,7 +92,7 @@ if (-not $Elevated) {
# Admin tasks - service installation and firewall rules # Admin tasks - service installation and firewall rules
try { try {
$agentPath = (Get-Command beszel-agent -ErrorAction SilentlyContinue).Path $agentPath = Join-Path -Path $(scoop prefix beszel-agent) -ChildPath "beszel-agent.exe"
if (-not $agentPath) { if (-not $agentPath) {
throw "Could not find beszel-agent executable. Make sure it was properly installed." throw "Could not find beszel-agent executable. Make sure it was properly installed."
} }
@@ -127,8 +126,9 @@ try {
if (-not (Test-Path $logDir)) { if (-not (Test-Path $logDir)) {
New-Item -ItemType Directory -Path $logDir -Force | Out-Null New-Item -ItemType Directory -Path $logDir -Force | Out-Null
} }
nssm set beszel-agent AppStdout "$logDir\stdout.log" $logFile = "$logDir\beszel-agent.log"
nssm set beszel-agent AppStderr "$logDir\stderr.log" nssm set beszel-agent AppStdout $logFile
nssm set beszel-agent AppStderr $logFile
# Create a firewall rule if it doesn't exist # Create a firewall rule if it doesn't exist
$ruleName = "Allow beszel-agent" $ruleName = "Allow beszel-agent"
@@ -162,6 +162,7 @@ try {
} }
Write-Host "Checking beszel-agent service status..." Write-Host "Checking beszel-agent service status..."
Start-Sleep -Seconds 5 # Allow time to start before checking status
$serviceStatus = nssm status beszel-agent $serviceStatus = nssm status beszel-agent
if ($serviceStatus -eq "SERVICE_RUNNING") { if ($serviceStatus -eq "SERVICE_RUNNING") {