diff options
author | Rob Crittenden <rcritten@redhat.com> | 2012-05-24 11:23:36 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2012-07-02 17:08:58 -0400 |
commit | e5b6260008a3a7132fdaef99d800406eb8872316 (patch) | |
tree | 9981186bd06f5574570f5743cba05cd0aa9ee963 /ipapython/platform/systemd.py | |
parent | 6fb802152add24aa1842f4adccf59b23850ab336 (diff) | |
download | freeipa.git-e5b6260008a3a7132fdaef99d800406eb8872316.tar.gz freeipa.git-e5b6260008a3a7132fdaef99d800406eb8872316.tar.xz freeipa.git-e5b6260008a3a7132fdaef99d800406eb8872316.zip |
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
Diffstat (limited to 'ipapython/platform/systemd.py')
-rw-r--r-- | ipapython/platform/systemd.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/ipapython/platform/systemd.py b/ipapython/platform/systemd.py index ae06c022..a233e104 100644 --- a/ipapython/platform/systemd.py +++ b/ipapython/platform/systemd.py @@ -20,6 +20,7 @@ from ipapython import ipautil from ipapython.platform import base import sys, os, shutil +from ipalib import api class SystemdService(base.PlatformService): SYSTEMD_ETC_PATH = "/etc/systemd/system/" @@ -73,16 +74,34 @@ class SystemdService(base.PlatformService): return (None,None) return dict(map(lambda x: splitter(x, separator=separator), text.split("\n"))) + 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: + elements = self.service_name.split("@") + if elements[0] in base.wellknownports: + ports = base.wellknownports[elements[0]] + if ports: + ipautil.wait_for_open_ports('localhost', ports, api.env.startup_timeout) + def stop(self, instance_name="", capture_output=True): ipautil.run(["/bin/systemctl", "stop", self.service_instance(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(["/bin/systemctl", "start", self.service_instance(instance_name)], capture_output=capture_output) + if wait and self.is_running(instance_name): + self.__wait_for_open_ports(self.service_instance(instance_name)) - def restart(self, instance_name="", capture_output=True): + def restart(self, instance_name="", capture_output=True, wait=True): # Restart command is broken before systemd-36-3.fc16 # If you have older systemd version, restart of dependent services will hang systemd indefinetly ipautil.run(["/bin/systemctl", "restart", self.service_instance(instance_name)], capture_output=capture_output) + if wait and self.is_running(instance_name): + self.__wait_for_open_ports(self.service_instance(instance_name)) def is_running(self, instance_name=""): ret = True |