From 1527f668df4fec5446cfe67ad911469ec6fcff0b Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Fri, 14 Sep 2012 15:42:01 -0500
Subject: [PATCH] Fixed conflicting log4j.properties.

The <instance>/lib link has been replaced with a real folder
which contains links to the files in /usr/share/tomcat/lib. This
way the log4j.properties can be placed in this folder without
causing conflicts with other instances.

Ticket: #284
---
 base/deploy/scripts/operations                |  1 -
 base/deploy/src/scriptlets/instance_layout.py | 34 ++++++++++++++-------------
 base/deploy/src/scriptlets/pkiparser.py       |  8 +++----
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/base/deploy/scripts/operations b/base/deploy/scripts/operations
index 60b66efdc560c4617db4f80497514d6880999a52..d4c03d0841e7db0d3cbb04da99cb512352d861db 100644
--- a/base/deploy/scripts/operations
+++ b/base/deploy/scripts/operations
@@ -961,7 +961,6 @@ verify_symlinks()
         [alias]=/etc/pki/${PKI_INSTANCE_ID}/alias
         [bin]=/usr/share/tomcat/bin
         [conf]=/etc/pki/${PKI_INSTANCE_ID}
-        [lib]=/usr/share/tomcat/lib
         [logs]=/var/log/pki/${PKI_INSTANCE_ID})
 
     # '${PKI_INSTANCE_PATH}' symlinks (root:root ownership)
diff --git a/base/deploy/src/scriptlets/instance_layout.py b/base/deploy/src/scriptlets/instance_layout.py
index c5f884ec3e2187c584266ddea81914ab458336f3..5b48b87b52d28df49f137a099ad9e3fef0944d14 100644
--- a/base/deploy/src/scriptlets/instance_layout.py
+++ b/base/deploy/src/scriptlets/instance_layout.py
@@ -45,9 +45,25 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
         util.directory.create(master['pki_instance_configuration_path'])
         # establish Apache/Tomcat specific instance
         if master['pki_subsystem'] in config.PKI_TOMCAT_SUBSYSTEMS:
+            # establish Tomcat instance configuration
+            util.directory.copy(master['pki_source_shared_path'],
+                                master['pki_instance_configuration_path'],
+                                overwrite_flag=True)
             # establish Tomcat instance base
             util.directory.create(master['pki_tomcat_common_path'])
             util.directory.create(master['pki_tomcat_common_lib_path'])
+            # establish Tomcat instance library
+            util.directory.create(master['pki_instance_lib'])
+            for name in os.listdir(master['pki_tomcat_lib_path']):
+                util.symlink.create(
+                    os.path.join(
+                        master['pki_tomcat_lib_path'],
+                        name),
+                    os.path.join(
+                        master['pki_instance_lib'],
+                        name))
+            util.symlink.create(master['pki_instance_conf_log4j_properties'],
+                                master['pki_instance_lib_log4j_properties'])
             util.directory.create(master['pki_tomcat_tmpdir_path'])
             util.directory.create(master['pki_tomcat_webapps_path'])
             util.directory.create(master['pki_tomcat_webapps_common_path'])
@@ -74,19 +90,10 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
             util.directory.create(
                 master['pki_tomcat_work_catalina_host_subsystem_path'])
             # establish Tomcat instance logs
-            # establish Tomcat instance configuration
-            util.directory.copy(master['pki_source_shared_path'],
-                                master['pki_instance_configuration_path'],
-                                overwrite_flag=True)
             # establish Tomcat instance registry
             # establish Tomcat instance convenience symbolic links
             util.symlink.create(master['pki_tomcat_bin_path'],
                                 master['pki_tomcat_bin_link'])
-            util.symlink.create(master['pki_tomcat_lib_path'],
-                                master['pki_tomcat_lib_link'])
-            util.symlink.create(master['pki_instance_log4j_properties'],
-                                master['pki_tomcat_lib_log4j_properties_link'],
-                                uid=0, gid=0)
             util.symlink.create(master['pki_tomcat_systemd'],
                                 master['pki_instance_systemd_link'],
                                 uid=0, gid=0)
@@ -166,6 +173,8 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
             # update Tomcat instance base
             util.directory.modify(master['pki_tomcat_common_path'])
             util.directory.modify(master['pki_tomcat_common_lib_path'])
+            util.directory.modify(master['pki_instance_lib'])
+            util.directory.modify(master['pki_instance_lib_log4j_properties'])
             util.directory.modify(master['pki_tomcat_webapps_path'])
             util.directory.copy(
                 os.path.join(
@@ -195,9 +204,6 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
             # update Tomcat instance registry
             # update Tomcat instance convenience symbolic links
             util.symlink.modify(master['pki_tomcat_bin_link'])
-            util.symlink.modify(master['pki_tomcat_lib_link'])
-            util.symlink.modify(master['pki_tomcat_lib_log4j_properties_link'],
-                                uid=0, gid=0)
             util.symlink.modify(master['pki_instance_systemd_link'],
                                 uid=0, gid=0)
             # update Tomcat instance common lib jar symbolic links
@@ -274,8 +280,6 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
                 # remove shared NSS security database path for this instance
                 util.directory.delete(master['pki_database_path'])
                 # remove Tomcat instance configuration
-                util.symlink.delete(
-                    master['pki_tomcat_lib_log4j_properties_link'])
                 util.directory.delete(master['pki_instance_configuration_path'])
                 # remove PKI 'tomcat.conf' instance file
                 util.file.delete(master['pki_target_tomcat_conf_instance_id'])
@@ -311,8 +315,6 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
                 # remove shared NSS security database path for this instance
                 util.directory.delete(master['pki_database_path'])
                 # remove Tomcat instance configuration
-                util.symlink.delete(
-                    master['pki_tomcat_lib_log4j_properties_link'])
                 util.directory.delete(master['pki_instance_configuration_path'])
                 # remove PKI 'tomcat.conf' instance file
                 util.file.delete(master['pki_target_tomcat_conf_instance_id'])
diff --git a/base/deploy/src/scriptlets/pkiparser.py b/base/deploy/src/scriptlets/pkiparser.py
index dd70874feee1f1f9c0e048347223a524ccce56dd..a235c5917f21dfe6626bb0d7bbd266f009a7041c 100644
--- a/base/deploy/src/scriptlets/pkiparser.py
+++ b/base/deploy/src/scriptlets/pkiparser.py
@@ -587,7 +587,7 @@ def compose_pki_master_dictionary():
                     config.pki_master_dict['pki_subsystem'].lower())
             # Tomcat instance log name/value pairs
             # Tomcat instance configuration name/value pairs
-            config.pki_master_dict['pki_instance_log4j_properties'] =\
+            config.pki_master_dict['pki_instance_conf_log4j_properties'] =\
                 os.path.join(
                     config.pki_master_dict['pki_instance_configuration_path'],
                     "log4j.properties")
@@ -604,11 +604,11 @@ def compose_pki_master_dictionary():
             config.pki_master_dict['pki_tomcat_bin_link'] =\
                 os.path.join(config.pki_master_dict['pki_instance_path'],
                              "bin")
-            config.pki_master_dict['pki_tomcat_lib_link'] =\
+            config.pki_master_dict['pki_instance_lib'] =\
                 os.path.join(config.pki_master_dict['pki_instance_path'],
                              "lib")
-            config.pki_master_dict['pki_tomcat_lib_log4j_properties_link'] =\
-                os.path.join(config.pki_master_dict['pki_tomcat_lib_path'],
+            config.pki_master_dict['pki_instance_lib_log4j_properties'] =\
+                os.path.join(config.pki_master_dict['pki_instance_lib'],
                              "log4j.properties")
             config.pki_master_dict['pki_instance_systemd_link'] =\
                 os.path.join(config.pki_master_dict['pki_instance_path'],
-- 
1.7.11.2

