Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Created December 14, 2016 23:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaFinkelshteyn/dda699c562c485099f28ee5b2f33435a to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/dda699c562c485099f28ee5b2f33435a to your computer and use it in GitHub Desktop.
$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