Created
December 14, 2016 23:11
-
-
Save IlyaFinkelshteyn/dda699c562c485099f28ee5b2f33435a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$port = 15672; | |
[int]$attempt=0 | |
$maxAttempts = 5 | |
while(!$client.Connected -and $attempt -lt $maxAttempts) { | |
try { | |
$client = New-Object System.Net.Sockets.TcpClient([System.Net.Sockets.AddressFamily]::InterNetwork) | |
$attempt++; $client.Connect("127.0.0.1", $port); write-host "service is listening on port $port" | |
} | |
catch { | |
try { | |
[int]$sleepTime = 10*$attempt | |
write-host "Service is not listening on port $port. Retry after $sleepTime seconds..." | |
sleep $sleepTime; | |
$client.Close() | |
$client = New-Object System.Net.Sockets.TcpClient([System.Net.Sockets.AddressFamily]::InterNetwork) | |
$client.Connect("127.0.0.1", $port); write-host "service is listening on port $port" | |
} | |
catch { | |
write-host "restarting service..." | |
cmd /c "C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.5\sbin\rabbitmq-service.bat" stop | |
cmd /c "C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.5\sbin\rabbitmq-service.bat" start | |
$client.Close() | |
} | |
} | |
} | |
if (!$client.Connected) { | |
throw "unable to make service listen in $maxAttempts attempst" | |
} | |
$client.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment