Skip to content

Instantly share code, notes, and snippets.

@JuanRamino
Created December 1, 2021 14:55
Show Gist options
  • Save JuanRamino/56832a9207adf0ed24a3a5bfac8f3fbe to your computer and use it in GitHub Desktop.
Save JuanRamino/56832a9207adf0ed24a3a5bfac8f3fbe to your computer and use it in GitHub Desktop.
Start-Job -ScriptBlock {
$ipaddress = '127.0.0.1'
$port = 3000
$try = 0
$sleepTime = 10
while(1) {
Start-Sleep -s $sleepTime
try {
$connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
Write-Output "$(Get-Date -Format u) - app is running"
$sleepTime = 5
}
catch {
if ($try -eq 3) {
Write-Output "$(Get-Date -Format u) - app down quit"
exit
} else {
$try = $try + 1
Write-Output "$(Get-Date -Format u) - app down try $try"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment