fix: deploy graceful recycle writes restart.request directly (no 90s wait)
This commit is contained in:
+24
-11
@@ -165,8 +165,27 @@ function Test-RdpMonitorMainProcessRunning {
|
||||
return $false
|
||||
}
|
||||
|
||||
function Set-RdpMonitorRestartRequestFromDeploy {
|
||||
param(
|
||||
[ValidateSet('settings', 'recycle')]
|
||||
[string]$Mode = 'recycle',
|
||||
[string]$Reason = 'deploy'
|
||||
)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $InstallRoot)) {
|
||||
New-Item -ItemType Directory -Path $InstallRoot -Force | Out-Null
|
||||
}
|
||||
$restartFile = Join-Path $InstallRoot 'restart.request'
|
||||
$content = @(
|
||||
"mode=$Mode"
|
||||
"reason=$Reason"
|
||||
"requested_at=$((Get-Date).ToString('o'))"
|
||||
) -join "`r`n"
|
||||
[System.IO.File]::WriteAllText($restartFile, $content + "`r`n", $Utf8Bom)
|
||||
}
|
||||
|
||||
function Stop-RdpLoginMonitorMainProcesses {
|
||||
param([int]$GracefulWaitSec = 90)
|
||||
param([int]$GracefulWaitSec = 35)
|
||||
|
||||
$canonical = [System.IO.Path]::GetFullPath($LocalScript)
|
||||
if (-not (Test-RdpMonitorMainProcessRunning -CanonicalScript $canonical)) {
|
||||
@@ -174,22 +193,16 @@ function Stop-RdpLoginMonitorMainProcesses {
|
||||
return
|
||||
}
|
||||
|
||||
if (Test-Path -LiteralPath $LocalScript) {
|
||||
Write-DeployLog "Graceful recycle: Login_Monitor.ps1 -RequestRestart -Recycle (без Stop-Process)."
|
||||
$recycleArgs = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $LocalScript, '-RequestRestart', '-Recycle')
|
||||
$p = Start-Process -FilePath $PsExe -ArgumentList $recycleArgs -Wait -PassThru -WindowStyle Hidden
|
||||
if ($p.ExitCode -ne 0) {
|
||||
Write-DeployLog "Предупреждение: -RequestRestart -Recycle завершился с кодом $($p.ExitCode)."
|
||||
}
|
||||
}
|
||||
Write-DeployLog "Graceful recycle: запись restart.request (mode=recycle), без дочернего PowerShell."
|
||||
Set-RdpMonitorRestartRequestFromDeploy -Mode 'recycle' -Reason 'deploy'
|
||||
|
||||
$deadline = (Get-Date).AddSeconds($GracefulWaitSec)
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
if (-not (Test-RdpMonitorMainProcessRunning -CanonicalScript $canonical)) {
|
||||
Write-DeployLog "Монитор завершился gracefully (ожидание $($GracefulWaitSec) с)."
|
||||
Write-DeployLog "Монитор завершился gracefully (до $($GracefulWaitSec) с)."
|
||||
return
|
||||
}
|
||||
Start-Sleep -Seconds 2
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
|
||||
Write-DeployLog "Таймаут graceful recycle — принудительная остановка оставшихся процессов монитора."
|
||||
|
||||
@@ -173,7 +173,7 @@ powershell.exe -NoProfile -ExecutionPolicy Bypass `
|
||||
-File "C:\ProgramData\RDP-login-monitor\Login_Monitor.ps1" -RequestRestart -Recycle
|
||||
```
|
||||
|
||||
**`Deploy-LoginMonitor.ps1`** при обновлении вызывает `-RequestRestart -Recycle` и ждёт до 90 с; **`Stop-Process -Force`** только если таймаут.
|
||||
**`Deploy-LoginMonitor.ps1`** записывает **`restart.request`** напрямую (без дочернего PowerShell) и ждёт до **35 с**; **`Stop-Process -Force`** только если таймаут.
|
||||
|
||||
Сигнал: файл **`C:\ProgramData\RDP-login-monitor\restart.request`** (создаётся автоматически, не редактировать вручную).
|
||||
|
||||
|
||||
+9
-8
@@ -80,7 +80,7 @@ $script:MonitorLoopInitialized = $false
|
||||
# строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах).
|
||||
# Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только
|
||||
# исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1).
|
||||
$ScriptVersion = "1.2.2-SAC"
|
||||
$ScriptVersion = "1.2.3-SAC"
|
||||
|
||||
# Логи (все под InstallRoot)
|
||||
$LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log"
|
||||
@@ -622,6 +622,14 @@ if ($InstallTasks) {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Только запись restart.request — без проверки администратора (Deploy/GPO может вызывать из SYSTEM).
|
||||
if ($RequestRestart) {
|
||||
$restartMode = if ($Recycle) { 'recycle' } else { 'settings' }
|
||||
Set-RdpMonitorRestartRequest -Mode $restartMode -Reason 'RequestRestart'
|
||||
Write-Log "Запрошен graceful restart (mode=$restartMode, файл restart.request). Активный монитор обработает запрос без Stop-Process."
|
||||
exit 0
|
||||
}
|
||||
|
||||
# --- Учётные данные Telegram (открытый текст или DPAPI Base64) ---
|
||||
if (-not [string]::IsNullOrWhiteSpace($TelegramBotTokenProtectedB64)) {
|
||||
try {
|
||||
@@ -923,13 +931,6 @@ if ($CheckSac) {
|
||||
exit $code
|
||||
}
|
||||
|
||||
if ($RequestRestart) {
|
||||
$restartMode = if ($Recycle) { 'recycle' } else { 'settings' }
|
||||
Set-RdpMonitorRestartRequest -Mode $restartMode -Reason 'RequestRestart'
|
||||
Write-Log "Запрошен graceful restart (mode=$restartMode, файл restart.request). Активный монитор обработает запрос без Stop-Process."
|
||||
exit 0
|
||||
}
|
||||
|
||||
Invoke-RdpMonitorProcessMigrationAndRelaunch
|
||||
Lock-RdpMonitorSingleInstance
|
||||
Ensure-RdpMonitorScheduledTasks
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.2.2-SAC
|
||||
1.2.3-SAC
|
||||
|
||||
Reference in New Issue
Block a user