Hey guys!
Having a little bit of trouble with this segment of code.
I’ve got a script that I’m using to do the following:
- remove an azure webapp from the traffic manager
-
check for the number of requests for that webapp every 60 seconds until requests drop below 300
-
reboot the web app
-
get the URL response of the web app every 60 seconds while it returns a status code not equal to 200
-
re-add the web app to the TM after the URL Response status code is 200 3 time in a row.
I’m having trouble with the 3rd step, where the GetResponse times out and hangs even after the URL is back up and responding.
I’ve marked in the code 2 spots where I’ve tried a couple things I found in searching for a solution but so far nothing has worked.
$url = "http://webapp.azurewebsites.net"
Function GetURL {
$webRequest = [net.WebRequest]::Create($url)
$webRequest.Timeout = [System.Threading.Timeout]::Infinite #Read this on a blog but it didn't work
$Response = $webRequest.GetResponse()
$statusCode = [int]$Response.StatusCode
$Response.close #Read this on a blog but it didn't work either
Return $statusCode
} #Function to get URL Status
###Check the site every 60 seconds until it returns a status code of 200###
While ($statusCode -ne 200) {
Write-verbose "The webpage $url has not come back up.
The current Status Code is $statusCode. Waiting 60 seconds and trying again"
#sleep -Seconds 60
. GetURL
}
Function VerifyUp {
Param ($statusCode)
###Check the site every 60 seconds until it returns a status code of 200###
While ($statusCode -ne 200) {
Write-Host "The webpage $url has not come back up.
The current Status Code is $statusCode. Waiting 60 seconds and trying again"
#sleep -Seconds 60
. GetURL
}
While ($statusCode -eq 200) {
$i = 1
sleep -Seconds 60
. GetURL
$i++
}
for ($statusCode -ne 200) {
VerifyUp
}
for ($i -eq 3) {
Write-host "The Webpage $url has been up for 3 minutes. Readding $app to TM."
break
}
}
###### Start Script ##################
ARMLogin
TMRemove
. Requests
Reboot -RequestCount $RequestCount
. GetURL
VerifyUP -statusCode $statusCode
TMAdd