7e1b55
From 5abf1bc79f8b32c6638ff98fbe2e4a8dec9a5010 Mon Sep 17 00:00:00 2001
7e1b55
From: "Endi S. Dewata" <edewata@redhat.com>
7e1b55
Date: Thu, 12 Aug 2021 13:26:42 -0500
7e1b55
Subject: [PATCH] Specify PKI installation log paths
7e1b55
7e1b55
The DogtagInstance.spawn_instance() and uninstall() have
7e1b55
been modified to specify the paths of PKI installation
7e1b55
logs using --log-file option on PKI 11.0.0 or later.
7e1b55
7e1b55
This allows IPA to have a full control over the log files
7e1b55
instead of relying on PKI's default log files.
7e1b55
7e1b55
Fixes: https://pagure.io/freeipa/issue/8966
7e1b55
Signed-off-by: Endi Sukma Dewata <edewata@redhat.com>
7e1b55
---
7e1b55
 ipaserver/install/dogtaginstance.py | 35 ++++++++++++++++++++++++++---
7e1b55
 1 file changed, 32 insertions(+), 3 deletions(-)
7e1b55
7e1b55
diff --git a/ipaserver/install/dogtaginstance.py b/ipaserver/install/dogtaginstance.py
7e1b55
index 644acd4eacea22f41a7cd36b54553d6d7cd22690..0d9aebb542f242b81315edd016699697f2fc4091 100644
7e1b55
--- a/ipaserver/install/dogtaginstance.py
7e1b55
+++ b/ipaserver/install/dogtaginstance.py
7e1b55
@@ -36,8 +36,10 @@ from configparser import DEFAULTSECT, ConfigParser, RawConfigParser
7e1b55
 
7e1b55
 import six
7e1b55
 
7e1b55
+import pki
7e1b55
 from pki.client import PKIConnection
7e1b55
 import pki.system
7e1b55
+import pki.util
7e1b55
 
7e1b55
 from ipalib import api, errors, x509
7e1b55
 from ipalib.install import certmonger
7e1b55
@@ -202,6 +204,18 @@ class DogtagInstance(service.Service):
7e1b55
                 "-f", cfg_file,
7e1b55
                 "--debug"]
7e1b55
 
7e1b55
+        # specify --log-file <path> on PKI 11.0.0 or later
7e1b55
+
7e1b55
+        pki_version = pki.util.Version(pki.specification_version())
7e1b55
+        if pki_version >= pki.util.Version("11.0.0"):
7e1b55
+            timestamp = time.strftime(
7e1b55
+                "%Y%m%d%H%M%S",
7e1b55
+                time.localtime(time.time()))
7e1b55
+            log_file = os.path.join(
7e1b55
+                paths.VAR_LOG_PKI_DIR,
7e1b55
+                "pki-%s-spawn.%s.log" % (self.subsystem.lower(), timestamp))
7e1b55
+            args.extend(["--log-file", log_file])
7e1b55
+
7e1b55
         with open(cfg_file) as f:
7e1b55
             logger.debug(
7e1b55
                 'Contents of pkispawn configuration file (%s):\n%s',
7e1b55
@@ -290,10 +304,25 @@ class DogtagInstance(service.Service):
7e1b55
         if self.is_installed():
7e1b55
             self.print_msg("Unconfiguring %s" % self.subsystem)
7e1b55
 
7e1b55
+        args = [paths.PKIDESTROY,
7e1b55
+                "-i", "pki-tomcat",
7e1b55
+                "-s", self.subsystem]
7e1b55
+
7e1b55
+        # specify --log-file <path> on PKI 11.0.0 or later
7e1b55
+
7e1b55
+        pki_version = pki.util.Version(pki.specification_version())
7e1b55
+        if pki_version >= pki.util.Version("11.0.0"):
7e1b55
+            timestamp = time.strftime(
7e1b55
+                "%Y%m%d%H%M%S",
7e1b55
+                time.localtime(time.time()))
7e1b55
+            log_file = os.path.join(
7e1b55
+                paths.VAR_LOG_PKI_DIR,
7e1b55
+                "pki-%s-destroy.%s.log" % (self.subsystem.lower(), timestamp))
7e1b55
+            args.extend(["--log-file", log_file])
7e1b55
+
7e1b55
         try:
7e1b55
-            ipautil.run([paths.PKIDESTROY,
7e1b55
-                         "-i", 'pki-tomcat',
7e1b55
-                         "-s", self.subsystem])
7e1b55
+            ipautil.run(args)
7e1b55
+
7e1b55
         except ipautil.CalledProcessError as e:
7e1b55
             logger.critical("failed to uninstall %s instance %s",
7e1b55
                             self.subsystem, e)
7e1b55
-- 
7e1b55
2.31.1
7e1b55