-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_and_reboot.ps1
35 lines (29 loc) · 1 KB
/
check_and_reboot.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$safePath = "C:\Users\usuario\Desktop\NEWS_CRAWLER\safe_to_reboot.flag"
$maxRetries = 5 # Maximum number of retries
$retryInterval = 60 # Interval between retries in seconds (1 minute)
function AttemptReboot {
if (Test-Path $safePath) {
Write-Host "Initiating system reboot..."
Remove-Item $safePath -Force
shutdown /r /f /t 5
return $true
} else {
Write-Host "Not safe to reboot at this moment."
return $false
}
}
$retryCount = 0
$rebootSuccessful = $false
while (-not $rebootSuccessful -and $retryCount -lt $maxRetries) {
$rebootSuccessful = AttemptReboot
if (-not $rebootSuccessful) {
$retryCount++
if ($retryCount -lt $maxRetries) {
Write-Host "Retry $retryCount of $maxRetries. Waiting $retryInterval seconds before next attempt..."
Start-Sleep -Seconds $retryInterval
}
}
}
if (-not $rebootSuccessful) {
Write-Host "Failed to reboot after $maxRetries attempts. Skipping reboot for now."
}