summaryrefslogtreecommitdiffstats
path: root/ipaserver/install/installutils.py
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-03-14 17:56:17 +0100
committerRob Crittenden <rcritten@redhat.com>2011-03-21 14:31:08 -0400
commit18542cd165d047cba69ed2b3ac12e59993bf2fb0 (patch)
treeaf1e88fc5380dcc40d124b358a4466654d3b04bb /ipaserver/install/installutils.py
parentca5332951c68904b0763f79f3612209271206b2a (diff)
downloadfreeipa-18542cd165d047cba69ed2b3ac12e59993bf2fb0.tar.gz
freeipa-18542cd165d047cba69ed2b3ac12e59993bf2fb0.tar.xz
freeipa-18542cd165d047cba69ed2b3ac12e59993bf2fb0.zip
Wait for Directory Server ports to open
When Directory Server operation is run right after the server restart the listening ports may not be opened yet. This makes the installation fail. This patch fixes this issue by waiting for both secure and insecure Directory Server ports to open after every restart. https://fedorahosted.org/freeipa/ticket/1076
Diffstat (limited to 'ipaserver/install/installutils.py')
-rw-r--r--ipaserver/install/installutils.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index b3402440a..61d53a26f 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -28,6 +28,7 @@ import sys
import struct
import fcntl
import netaddr
+import time
from ipapython import ipautil
from ipapython import dnsclient
@@ -389,3 +390,34 @@ def create_keytab(path, principal):
kadmin("ktadd -k " + path + " " + principal)
+def wait_for_open_ports(host, ports, timeout=0):
+ """
+ Wait until the specified port(s) on the remote host are open. Timeout
+ in seconds may be specified to limit the wait.
+ """
+ if not isinstance(ports, (tuple, list)):
+ ports = [ports]
+
+ op_timeout = time.time() + timeout
+ ipv6_failover = False
+
+ for port in ports:
+ while True:
+ try:
+ if ipv6_failover:
+ s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+ else:
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.connect((host, port))
+ s.close()
+ break;
+ except socket.error, e:
+ if e.errno == 111: # 111: Connection refused
+ if timeout and time.time() > op_timeout: # timeout exceeded
+ raise e
+ time.sleep(1)
+ elif not ipv6_failover: # fallback to IPv6 connection
+ ipv6_failover = True
+ else:
+ raise e
+