From e5b6260008a3a7132fdaef99d800406eb8872316 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 24 May 2012 11:23:36 -0400 Subject: Centralize timeout for waiting for servers to start. All service start/restart currently go through ipapython/platform so move the "wait for service to start" code there as well. A dictionary of known services and ports to wait on is defined in base.py This is referenced by the platforms by instance name to determine what to wait for. For the case of dirsrv if we get that as a plain name (no specific instance) it is assumed to be the main IPA service. https://fedorahosted.org/freeipa/ticket/2375 https://fedorahosted.org/freeipa/ticket/2610 --- ipapython/platform/redhat.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'ipapython/platform/redhat.py') diff --git a/ipapython/platform/redhat.py b/ipapython/platform/redhat.py index 28a43e588..d3c23ab0d 100644 --- a/ipapython/platform/redhat.py +++ b/ipapython/platform/redhat.py @@ -26,6 +26,7 @@ import sys import socket from ipapython import ipautil from ipapython.platform import base +from ipalib import api # All what we allow exporting directly from this module # Everything else is made available through these symbols when they are @@ -46,14 +47,31 @@ from ipapython.platform import base __all__ = ['authconfig', 'service', 'knownservices', 'backup_and_replace_hostname', 'restore_context', 'check_selinux_status'] class RedHatService(base.PlatformService): + def __wait_for_open_ports(self, instance_name=""): + """ + If this is a service we need to wait for do so. + """ + ports = None + if instance_name in base.wellknownports: + ports = base.wellknownports[instance_name] + else: + if self.service_name in base.wellknownports: + ports = base.wellknownports[self.service_name] + if ports: + ipautil.wait_for_open_ports('localhost', ports, api.env.startup_timeout) + def stop(self, instance_name="", capture_output=True): ipautil.run(["/sbin/service", self.service_name, "stop", instance_name], capture_output=capture_output) - def start(self, instance_name="", capture_output=True): + def start(self, instance_name="", capture_output=True, wait=True): ipautil.run(["/sbin/service", self.service_name, "start", instance_name], capture_output=capture_output) + if wait and self.is_running(instance_name): + self.__wait_for_open_ports(instance_name) - def restart(self, instance_name="", capture_output=True): + def restart(self, instance_name="", capture_output=True, wait=True): ipautil.run(["/sbin/service", self.service_name, "restart", instance_name], capture_output=capture_output) + if wait and self.is_running(instance_name): + self.__wait_for_open_ports(instance_name) def is_running(self, instance_name=""): ret = True -- cgit