diff --git a/Deploy-LoginMonitor.ps1 b/Deploy-LoginMonitor.ps1 index dc603dd..947ff0c 100644 --- a/Deploy-LoginMonitor.ps1 +++ b/Deploy-LoginMonitor.ps1 @@ -682,6 +682,49 @@ function Sync-RdpMonitorSettingsHeartbeatInterval { return $true } +function Test-RdpMonitorSettingsNeedsStartupRebootDetectMinutes { + param([string]$SettingsPath) + if (-not (Test-Path -LiteralPath $SettingsPath)) { return $true } + $c = Get-RdpMonitorSettingsRaw -Path $SettingsPath + if ([string]::IsNullOrWhiteSpace($c)) { return $true } + return ($c -notmatch '(?m)^\s*\$StartupRebootDetectMinutes\s*=\s*\d+') +} + +function Sync-RdpMonitorSettingsStartupRebootDetectMinutesIfMissing { + param( + [string]$LocalSettings, + [int]$TargetMinutes = 5 + ) + + if (-not (Test-RdpMonitorSettingsNeedsStartupRebootDetectMinutes -SettingsPath $LocalSettings)) { + return $false + } + + if (-not (Test-Path -LiteralPath $LocalSettings)) { return $false } + + $c = Get-RdpMonitorSettingsRaw -Path $LocalSettings + $block = @( + '# --- Окно (мин): LastBootUpTime + System 41/1074/6005/6008/6009 → os_reboot при старте ---' + "`$StartupRebootDetectMinutes = $TargetMinutes" + ) -join "`r`n" + + $bak = "$LocalSettings.bak.$(Get-Date -Format 'yyyyMMdd_HHmmss')" + Copy-Item -LiteralPath $LocalSettings -Destination $bak -Force + + $insertAfterHeartbeat = '(?m)^(\s*\$HeartbeatInterval\s*=\s*\d+\s*)$' + if (-not [string]::IsNullOrWhiteSpace($c) -and $c -match $insertAfterHeartbeat) { + $newContent = [regex]::Replace($c, $insertAfterHeartbeat, ('$1' + "`r`n`r`n" + $block), 1) + } elseif (-not [string]::IsNullOrWhiteSpace($c)) { + $newContent = ($c.TrimEnd() + "`r`n`r`n" + $block + "`r`n") + } else { + $newContent = ($block + "`r`n") + } + + [System.IO.File]::WriteAllText($LocalSettings, $newContent.TrimEnd() + "`r`n", $Utf8Bom) + Write-DeployLog "login_monitor.settings.ps1: добавлен `$StartupRebootDetectMinutes = $TargetMinutes (резервная копия: $bak)" + return $true +} + function Invoke-RdpMonitorSettingsPostPatches { param([string]$LocalSettings) if (-not (Test-Path -LiteralPath $LocalSettings)) { return $false } @@ -693,6 +736,7 @@ function Invoke-RdpMonitorSettingsPostPatches { if (Sync-RdpMonitorSettingsWinRmInboundBlock -LocalSettings $LocalSettings) { $changed = $true } if (Sync-RdpMonitorSettingsMaxBackupDaysIfMissing -LocalSettings $LocalSettings) { $changed = $true } if (Sync-RdpMonitorSettingsGetInventoryIfMissing -LocalSettings $LocalSettings) { $changed = $true } + if (Sync-RdpMonitorSettingsStartupRebootDetectMinutesIfMissing -LocalSettings $LocalSettings) { $changed = $true } return $changed } @@ -1346,9 +1390,10 @@ try { $needsExchangeNoisePatch = Test-RdpMonitorSettingsNeedsExchangeNoisePatch -SettingsPath $settingsLocal $needsWinRmInboundBlock = Test-RdpMonitorSettingsNeedsWinRmInboundBlock -SettingsPath $settingsLocal $needsHeartbeatInterval = Test-RdpMonitorSettingsNeedsHeartbeatInterval -SettingsPath $settingsLocal + $needsStartupRebootDetectMinutes = Test-RdpMonitorSettingsNeedsStartupRebootDetectMinutes -SettingsPath $settingsLocal $needsBundleSync = Test-RdpMonitorDeployBundleNeedsSync -ShareRoot $shareRoot $needsTaskExecutionLimitFix = Test-RdpMonitorDeployMainTaskNeedsUnlimitedExecutionTime -ShareRoot $shareRoot - $needsSacBootstrap = $needsSettingsBootstrap -or $needsBundleSync -or $needsDisplayNameHint -or $needsDailyReportHint -or $needsDailyReportRepair -or $needsExchangeNoisePatch -or $needsWinRmInboundBlock -or $needsHeartbeatInterval -or $needsTaskExecutionLimitFix + $needsSacBootstrap = $needsSettingsBootstrap -or $needsBundleSync -or $needsDisplayNameHint -or $needsDailyReportHint -or $needsDailyReportRepair -or $needsExchangeNoisePatch -or $needsWinRmInboundBlock -or $needsHeartbeatInterval -or $needsStartupRebootDetectMinutes -or $needsTaskExecutionLimitFix if (Test-RdpMonitorExchangeServerRole) { Write-DeployLog "Обнаружена роль Exchange — при необходимости допишем WinRM/4624 noise settings в login_monitor.settings.ps1." @@ -1390,6 +1435,8 @@ try { Write-DeployLog "Версия совпадает ($shareVerRaw), но RDP-Login-Monitor имеет ExecutionTimeLimit=$limitLabel — перерегистрируем задачи (InstallTasks)." } elseif ($needsHeartbeatInterval) { Write-DeployLog "Версия совпадает ($shareVerRaw), но в settings нет `$HeartbeatInterval — допишем 14400 с (4 ч) и продолжим деплой." + } elseif ($needsStartupRebootDetectMinutes) { + Write-DeployLog "Версия совпадает ($shareVerRaw), но в settings нет `$StartupRebootDetectMinutes — допишем 5 мин и продолжим деплой." } } if ($cmp -lt 0 -and -not $AllowDowngrade) { @@ -1438,6 +1485,15 @@ try { } } + $startupRebootDetectChanged = Sync-RdpMonitorSettingsStartupRebootDetectMinutesIfMissing -LocalSettings $settingsLocal + if ($startupRebootDetectChanged) { + $canonicalSr = [System.IO.Path]::GetFullPath($LocalScript) + if (Test-RdpMonitorMainProcessRunning -CanonicalScript $canonicalSr) { + Set-RdpMonitorRestartRequestFromDeploy -Mode 'settings' -Reason 'startup_reboot_detect_deploy' + Write-DeployLog "StartupRebootDetectMinutes добавлен — запрошена перезагрузка settings у работающего монитора." + } + } + if ($isScriptVersionUpgrade) { Sync-RdpMonitorUseSacFallbackMode -LocalSettings $settingsLocal | Out-Null } diff --git a/Login_Monitor.ps1 b/Login_Monitor.ps1 index 7c29092..829270d 100644 --- a/Login_Monitor.ps1 +++ b/Login_Monitor.ps1 @@ -90,7 +90,7 @@ $script:SkipLogDetailLimit = 15 # строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах). # Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только # исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1). -$ScriptVersion = "2.0.37-SAC" +$ScriptVersion = "2.0.38-SAC" # Логи (все под InstallRoot) $LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log" diff --git a/version.txt b/version.txt index 7499e98..c50554c 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.37-SAC +2.0.38-SAC