Release LanUps 0.1.2 with native installers and monitoring updates
This commit is contained in:
1 parent
90c57f020f
commit
5bdc79d8e4
30 files changed
+751
-270
No files matched your search
@@ -1,11 +1,11 @@
|
||||
#Requires -RunAsAdministrator
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Operator,
|
||||
[string]$AppRoot = (Join-Path $env:ProgramFiles 'LanUps'),
|
||||
[switch]$EnableShutdown
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$appRoot = Join-Path $env:ProgramFiles 'LanUps'
|
||||
$agent = Join-Path $appRoot 'Agent\LanUps.Agent.exe'
|
||||
$desktop = Join-Path $appRoot 'Desktop\LanUps.Desktop.exe'
|
||||
foreach ($app in @($agent, $desktop)) {
|
||||
@@ -47,8 +47,44 @@ if ($installed) {
|
||||
} else {
|
||||
New-Service -Name 'LanUps.Agent' -BinaryPathName $command -DisplayName 'LAN UPS Agent' -StartupType Automatic | Out-Null
|
||||
}
|
||||
$sc = Join-Path $env:SystemRoot 'System32\sc.exe'
|
||||
& $sc failure 'LanUps.Agent' reset= 86400 actions= 'restart/5000/restart/15000/restart/60000'
|
||||
if ($LASTEXITCODE) { throw 'Cannot configure Agent service recovery' }
|
||||
& $sc failureflag 'LanUps.Agent' 1
|
||||
if ($LASTEXITCODE) { throw 'Cannot enable Agent service recovery' }
|
||||
Start-Service -Name 'LanUps.Agent'
|
||||
|
||||
# The SCM can report Running before Kestrel is listening.
|
||||
Add-Type -AssemblyName System.Net.Http
|
||||
$handler = [Net.Http.HttpClientHandler]::new()
|
||||
$handler.UseProxy = $false
|
||||
$client = [Net.Http.HttpClient]::new($handler)
|
||||
$client.Timeout = [TimeSpan]::FromSeconds(2)
|
||||
$port = 47183
|
||||
$configuredPort = 0
|
||||
$machinePort = [Environment]::GetEnvironmentVariable('LANUPS_AGENT_PORT', 'Machine')
|
||||
if ([int]::TryParse($machinePort, [ref]$configuredPort) -and $configuredPort -in 1..65535) { $port = $configuredPort }
|
||||
$address = "http://127.0.0.1:$port/status"
|
||||
$client.DefaultRequestHeaders.Add('X-LanUps-Token', [IO.File]::ReadAllText($token).Trim())
|
||||
$deadline = [DateTime]::UtcNow.AddSeconds(25)
|
||||
$ready = $false
|
||||
try {
|
||||
do {
|
||||
try {
|
||||
$status = $client.GetStringAsync($address).GetAwaiter().GetResult() | ConvertFrom-Json
|
||||
if (!$status.endpoint -or !$status.update) { throw 'Unexpected Agent status response' }
|
||||
$ready = $true
|
||||
} catch {
|
||||
$reason = $_.Exception.GetBaseException().Message
|
||||
Start-Sleep -Milliseconds 300
|
||||
}
|
||||
} until ($ready -or [DateTime]::UtcNow -ge $deadline)
|
||||
} finally { $client.Dispose() }
|
||||
if (!$ready) {
|
||||
$state = (Get-Service 'LanUps.Agent').Status
|
||||
throw "Agent service did not respond at $address (service state: $state). $reason"
|
||||
}
|
||||
|
||||
$action = New-ScheduledTaskAction -Execute $desktop -Argument '--tray' -WorkingDirectory (Split-Path -Parent $desktop)
|
||||
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $Operator
|
||||
$principal = New-ScheduledTaskPrincipal -UserId $Operator -LogonType Interactive -RunLevel Limited
|
||||
|
||||
Reference in new issue
Block a user