summaryrefslogtreecommitdiffstats
path: root/ipaserver/install/installutils.py
diff options
context:
space:
mode:
authorTomas Babej <tbabej@redhat.com>2013-08-01 14:47:52 +0200
committerPetr Viktorin <pviktori@redhat.com>2013-08-26 16:21:36 +0200
commitab6a6e27d88b44b8c3f07290ae753558705363ee (patch)
treecc600b67c7b293bfbadb27aa9f42da688f74b6f1 /ipaserver/install/installutils.py
parent6961cf2e77cca8f3784a6d82cebeb0bb8df1f535 (diff)
downloadfreeipa.git-ab6a6e27d88b44b8c3f07290ae753558705363ee.tar.gz
freeipa.git-ab6a6e27d88b44b8c3f07290ae753558705363ee.tar.xz
freeipa.git-ab6a6e27d88b44b8c3f07290ae753558705363ee.zip
Make CS.cfg edits with CA instance stopped
This patch makes sure that all edits to CS.cfg configuration file are performed while pki-tomcatd service is stopped. Introduces a new contextmanager stopped_service for handling a general problem of performing a task that needs certain service being stopped. https://fedorahosted.org/freeipa/ticket/3804
Diffstat (limited to 'ipaserver/install/installutils.py')
-rw-r--r--ipaserver/install/installutils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index d17d53d1..268279dc 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -42,6 +42,7 @@ from ipapython import config
from ipalib import errors
from ipapython.dn import DN
from ipaserver.install import certs
+from ipapython import services as ipaservices
# Used to determine install status
IPA_MODULES = [
@@ -792,3 +793,38 @@ def private_ccache(path=None):
if os.path.exists(path):
os.remove(path)
+
+
+@contextmanager
+def stopped_service(service, instance_name=""):
+ """
+ Ensure that the specified service is stopped while the commands within
+ this context are executed.
+
+ Service is started at the end of the execution.
+ """
+
+ if instance_name:
+ log_instance_name = "@{instance}".format(instance=instance_name)
+ else:
+ log_instance_name = ""
+
+ root_logger.debug('Ensuring that service %s%s is not running while '
+ 'the next set of commands is being executed.', service,
+ log_instance_name)
+
+ # Figure out if the service is running, if not, yield
+ if not ipaservices.knownservices[service].is_running(instance_name):
+ root_logger.debug('Service %s%s is not running, continue.', service,
+ log_instance_name)
+ yield
+ root_logger.debug('Starting %s%s.', service, log_instance_name)
+ ipaservices.knownservices[service].start(instance_name)
+ return
+ else:
+ # Stop the service, do the required stuff and start it again
+ root_logger.debug('Stopping %s%s.', service, log_instance_name)
+ ipaservices.knownservices[service].stop(instance_name)
+ yield
+ root_logger.debug('Starting %s%s.', service, log_instance_name)
+ ipaservices.knownservices[service].start(instance_name)