[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Pki-devel] [PATCH] 594 Refactored upgrade scripts.



The upgrade scripts have been modified to use the uid and gid
provided by PKIInstance object.

https://fedorahosted.org/pki/ticket/1341

--
Endi S. Dewata
From 44d79fbea55cbe53d7bb869c573cc225ad1ecebb Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata redhat com>
Date: Sat, 9 May 2015 03:21:57 -0400
Subject: [PATCH] Refactored upgrade scripts.

The upgrade scripts have been modified to use the uid and gid
provided by PKIInstance object.

https://fedorahosted.org/pki/ticket/1341
---
 .../upgrade/10.0.1/01-ReplaceRandomNumberGenerator | 25 +++++------
 base/server/upgrade/10.0.99/03-FixRegistryFile     | 13 +-----
 base/server/upgrade/10.0.99/04-FixLogFileOwnership | 22 +---------
 .../10.1.1/01-MoveWebApplicationContextFile        | 23 +---------
 .../10.1.99/01-MoveWebApplicationContextFile       | 23 +---------
 .../upgrade/10.1.99/02-ReplaceJettisonWithJackson  | 51 +++++++---------------
 base/server/upgrade/10.1.99/03-AddedRESTEasyClient | 27 ++----------
 .../01-MoveWebApplicationDeploymentLocations       | 12 +----
 .../10.2.3/01-FixInstanceWorkFolderOwnership       | 25 +----------
 9 files changed, 35 insertions(+), 186 deletions(-)

diff --git a/base/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator b/base/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator
index e6737d8697cfaad6dceb871656b37044cd411720..01614d56ae6b62c3bc64ea7cb2e3ca813c8e1bb8 100755
--- a/base/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator
+++ b/base/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator
@@ -19,9 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
 import shutil
 import signal
 import sys
@@ -45,12 +43,13 @@ class ReplaceRandomNumberGenerator(pki.server.upgrade.PKIServerUpgradeScriptlet)
         meta_inf = os.path.join(instance.base_dir, 'webapps', subsystem.name, 'META-INF')
         self.backup(meta_inf)
 
-        self.create_meta_inf(meta_inf)
+        self.create_meta_inf(instance, meta_inf)
 
         context_xml = os.path.join(meta_inf, 'context.xml')
         self.backup(context_xml)
 
         self.create_context_xml(
+            instance,
             self.context_xml % (subsystem.name, subsystem.name),
             context_xml)
 
@@ -76,12 +75,13 @@ class ReplaceRandomNumberGenerator(pki.server.upgrade.PKIServerUpgradeScriptlet)
         meta_inf = os.path.join(instance.base_dir, 'webapps', 'ROOT', 'META-INF')
         self.backup(meta_inf)
 
-        self.create_meta_inf(meta_inf)
+        self.create_meta_inf(instance, meta_inf)
 
         context_xml = os.path.join(meta_inf, 'context.xml')
         self.backup(context_xml)
 
         self.create_context_xml(
+            instance,
             self.context_xml % ('server', 'ROOT'),
             context_xml)
 
@@ -97,12 +97,13 @@ class ReplaceRandomNumberGenerator(pki.server.upgrade.PKIServerUpgradeScriptlet)
         meta_inf = os.path.join(instance.base_dir, 'webapps', 'pki', 'META-INF')
         self.backup(meta_inf)
 
-        self.create_meta_inf(meta_inf)
+        self.create_meta_inf(instance, meta_inf)
 
         context_xml = os.path.join(meta_inf, 'context.xml')
         self.backup(context_xml)
 
         self.create_context_xml(
+            instance,
             self.context_xml % ('server', 'pki'),
             context_xml)
 
@@ -113,26 +114,20 @@ class ReplaceRandomNumberGenerator(pki.server.upgrade.PKIServerUpgradeScriptlet)
         with open(context_xml, 'w') as f:
             f.write(etree.tostring(document, pretty_print=True))
 
-    def create_meta_inf(self, path):
-
-        uid = pwd.getpwnam('pkiuser').pw_uid
-        gid = grp.getgrnam('pkiuser').gr_gid
+    def create_meta_inf(self, instance, path):
 
         if not os.path.exists(path):
             os.mkdir(path)
 
-        os.chown(path, uid, gid)
+        os.chown(path, instance.uid, instance.gid)
         os.chmod(path, 0770)
 
-    def create_context_xml(self, source, target):
+    def create_context_xml(self, instance, source, target):
 
         if not os.path.exists(target):
             shutil.copyfile(source, target)
 
-        uid = pwd.getpwnam('pkiuser').pw_uid
-        gid = grp.getgrnam('pkiuser').gr_gid
-
-        os.chown(target, uid, gid)
+        os.chown(target, instance.uid, instance.gid)
         os.chmod(target, 0660)
 
     def add_manager(self, document):
diff --git a/base/server/upgrade/10.0.99/03-FixRegistryFile b/base/server/upgrade/10.0.99/03-FixRegistryFile
index 053697f49711cac0a3b5149ea638737fa38a3c74..7940e7c460523fc4fc86c5fe03759a856db8a957 100755
--- a/base/server/upgrade/10.0.99/03-FixRegistryFile
+++ b/base/server/upgrade/10.0.99/03-FixRegistryFile
@@ -19,9 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
 import re
 import pki.server
 import pki.server.upgrade
@@ -42,16 +40,7 @@ class FixRegistryFile(pki.server.upgrade.PKIServerUpgradeScriptlet):
 
         with open(registry_file, "w") as registry:
             for line in lines:
-                m = re.search('^PKI_USER=(.*)$', line)
-                if m:
-                    user = m.group(1)
-                m = re.search('^PKI_GROUP=(.*)$', line)
-                if m:
-                    group = m.group(1)
-
                 registry.write(
                     re.sub(r'PKI_INSTANCE_ID', 'PKI_INSTANCE_NAME', line))
 
-        uid = pwd.getpwnam(user).pw_uid
-        gid = grp.getgrnam(group).gr_gid
-        os.chown(registry_file, uid, gid)
+        os.chown(registry_file, instance.uid, instance.gid)
diff --git a/base/server/upgrade/10.0.99/04-FixLogFileOwnership b/base/server/upgrade/10.0.99/04-FixLogFileOwnership
index b63055f29d3da928bb0095c3eeaf76dd755c3ee3..e4cb93437f6cfea0495e0e7fffe0ed57c4aadda9 100755
--- a/base/server/upgrade/10.0.99/04-FixLogFileOwnership
+++ b/base/server/upgrade/10.0.99/04-FixLogFileOwnership
@@ -19,10 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
-import re
 import pki.server.upgrade
 
 
@@ -32,23 +29,6 @@ class FixLogFileOwnership(pki.server.upgrade.PKIServerUpgradeScriptlet):
         self.message = 'Fix log file ownership'
 
     def upgrade_instance(self, instance):
-        registry_file = os.path.join(
-            pki.server.REGISTRY_DIR, 'tomcat', instance.name, instance.name)
-
-        with open(registry_file, "r") as registry:
-            lines = registry.readlines()
-
-        for line in lines:
-            m = re.search('^PKI_USER=(.*)$', line)
-            if m:
-                user = m.group(1)
-            m = re.search('^PKI_GROUP=(.*)$', line)
-            if m:
-                group = m.group(1)
-
-        uid = pwd.getpwnam(user).pw_uid
-        gid = grp.getgrnam(group).gr_gid
 
         log_dir = os.path.join('/var/log/pki', instance.name)
-
-        pki.util.chown(log_dir, uid, gid)
+        pki.util.chown(log_dir, instance.uid, instance.gid)
diff --git a/base/server/upgrade/10.1.1/01-MoveWebApplicationContextFile b/base/server/upgrade/10.1.1/01-MoveWebApplicationContextFile
index 603fc6b8f69c3124d302294be15011ed84e178b1..d2526c5310f117b65fdb79308dcb068aee44aeef 100755
--- a/base/server/upgrade/10.1.1/01-MoveWebApplicationContextFile
+++ b/base/server/upgrade/10.1.1/01-MoveWebApplicationContextFile
@@ -19,10 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
-import re
 
 import pki.server.upgrade
 
@@ -72,26 +69,8 @@ class MoveWebApplicationContextFile(pki.server.upgrade.PKIServerUpgradeScriptlet
         # copy context file, don't overwrite existing file
         pki.util.copyfile(old_context_file, new_context_file, overwrite=False)
 
-        # find uid and gid
-        registry_file = os.path.join(
-            pki.server.REGISTRY_DIR, 'tomcat', instance.name, instance.name)
-
-        with open(registry_file, 'r') as registry:
-            lines = registry.readlines()
-
-        for line in lines:
-            m = re.search('^PKI_USER=(.*)$', line)
-            if m:
-                user = m.group(1)
-            m = re.search('^PKI_GROUP=(.*)$', line)
-            if m:
-                group = m.group(1)
-
-        uid = pwd.getpwnam(user).pw_uid
-        gid = grp.getgrnam(group).gr_gid
-
         # set file and folder ownership
-        pki.util.chown(catalina_dir, uid, gid)
+        pki.util.chown(catalina_dir, instance.uid, instance.gid)
 
         # remove old context file
         if os.path.exists(old_context_file):
diff --git a/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile b/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile
index 603fc6b8f69c3124d302294be15011ed84e178b1..d2526c5310f117b65fdb79308dcb068aee44aeef 100755
--- a/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile
+++ b/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile
@@ -19,10 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
-import re
 
 import pki.server.upgrade
 
@@ -72,26 +69,8 @@ class MoveWebApplicationContextFile(pki.server.upgrade.PKIServerUpgradeScriptlet
         # copy context file, don't overwrite existing file
         pki.util.copyfile(old_context_file, new_context_file, overwrite=False)
 
-        # find uid and gid
-        registry_file = os.path.join(
-            pki.server.REGISTRY_DIR, 'tomcat', instance.name, instance.name)
-
-        with open(registry_file, 'r') as registry:
-            lines = registry.readlines()
-
-        for line in lines:
-            m = re.search('^PKI_USER=(.*)$', line)
-            if m:
-                user = m.group(1)
-            m = re.search('^PKI_GROUP=(.*)$', line)
-            if m:
-                group = m.group(1)
-
-        uid = pwd.getpwnam(user).pw_uid
-        gid = grp.getgrnam(group).gr_gid
-
         # set file and folder ownership
-        pki.util.chown(catalina_dir, uid, gid)
+        pki.util.chown(catalina_dir, instance.uid, instance.gid)
 
         # remove old context file
         if os.path.exists(old_context_file):
diff --git a/base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson b/base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson
index 7a6216ef4e3bde4c3497b6125f6b9a31a76b3d94..e39acb0e02086bbbf56dfb6613016a88175abee9 100755
--- a/base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson
+++ b/base/server/upgrade/10.1.99/02-ReplaceJettisonWithJackson
@@ -19,10 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
-import re
 import subprocess
 
 import pki.server.upgrade
@@ -39,24 +36,6 @@ class ReplaceJettisonWithJackson(pki.server.upgrade.PKIServerUpgradeScriptlet):
         # Tomcat common library
         common_lib = os.path.join(instance.base_dir, 'common', 'lib')
 
-        # Tomcat user and group
-        registry_file = os.path.join(
-            pki.server.REGISTRY_DIR, 'tomcat', instance.name, instance.name)
-
-        with open(registry_file, "r") as registry:
-            lines = registry.readlines()
-
-        for line in lines:
-            m = re.search('^PKI_USER=(.*)$', line)
-            if m:
-                user = m.group(1)
-            m = re.search('^PKI_GROUP=(.*)$', line)
-            if m:
-                group = m.group(1)
-
-        uid = pwd.getpwnam(user).pw_uid
-        gid = grp.getgrnam(group).gr_gid
-
         # RESTEasy library
         resteasy_lib = subprocess.check_output(
             '. /etc/pki/pki.conf && echo $RESTEASY_LIB',
@@ -74,63 +53,63 @@ class ReplaceJettisonWithJackson(pki.server.upgrade.PKIServerUpgradeScriptlet):
         # create new links
         source = os.path.join('/usr/share/java', 'jackson-annotations.jar')
         link = os.path.join(common_lib, 'jackson-annotations.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java/jackson', 'jackson-core-asl.jar')
         link = os.path.join(common_lib, 'jackson-core-asl.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java', 'jackson-core.jar')
         link = os.path.join(common_lib, 'jackson-core.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java', 'jackson-databind.jar')
         link = os.path.join(common_lib, 'jackson-databind.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java/jackson-jaxrs-providers', 'jackson-jaxrs-base.jar')
         link = os.path.join(common_lib, 'jackson-jaxrs-base.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java/jackson', 'jackson-jaxrs.jar')
         link = os.path.join(common_lib, 'jackson-jaxrs.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java/jackson-jaxrs-providers', 'jackson-jaxrs-json-provider.jar')
         link = os.path.join(common_lib, 'jackson-jaxrs-json-provider.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java/jackson', 'jackson-mapper-asl.jar')
         link = os.path.join(common_lib, 'jackson-mapper-asl.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java', 'jackson-module-jaxb-annotations.jar')
         link = os.path.join(common_lib, 'jackson-module-jaxb-annotations.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java/jackson', 'jackson-mrbean.jar')
         link = os.path.join(common_lib, 'jackson-mrbean.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java/jackson', 'jackson-smile.jar')
         link = os.path.join(common_lib, 'jackson-smile.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join('/usr/share/java/jackson', 'jackson-xc.jar')
         link = os.path.join(common_lib, 'jackson-xc.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
         source = os.path.join(resteasy_lib, 'resteasy-jackson-provider.jar')
         link = os.path.join(common_lib, 'resteasy-jackson-provider.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
     def remove_link(self, link):
 
         self.backup(link)
         os.remove(link)
 
-    def create_link(self, source, link, uid, gid):
+    def create_link(self, instance, source, link):
 
         self.backup(link)
         os.symlink(source, link)
-        os.lchown(link, uid, gid)
+        os.lchown(link, instance.uid, instance.gid)
diff --git a/base/server/upgrade/10.1.99/03-AddedRESTEasyClient b/base/server/upgrade/10.1.99/03-AddedRESTEasyClient
index 55bc8c367719e7f22ebd2e81d8ef4369641456b5..63d4a93eb60d1edde0fbe953ed7d78d44a1a6b59 100755
--- a/base/server/upgrade/10.1.99/03-AddedRESTEasyClient
+++ b/base/server/upgrade/10.1.99/03-AddedRESTEasyClient
@@ -19,10 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
-import re
 import subprocess
 
 import pki.server.upgrade
@@ -39,24 +36,6 @@ class AddedRESTEasyClient(pki.server.upgrade.PKIServerUpgradeScriptlet):
         # Tomcat common library
         common_lib = os.path.join(instance.base_dir, 'common', 'lib')
 
-        # Tomcat user and group
-        registry_file = os.path.join(
-            pki.server.REGISTRY_DIR, 'tomcat', instance.name, instance.name)
-
-        with open(registry_file, "r") as registry:
-            lines = registry.readlines()
-
-        for line in lines:
-            m = re.search('^PKI_USER=(.*)$', line)
-            if m:
-                user = m.group(1)
-            m = re.search('^PKI_GROUP=(.*)$', line)
-            if m:
-                group = m.group(1)
-
-        uid = pwd.getpwnam(user).pw_uid
-        gid = grp.getgrnam(group).gr_gid
-
         # RESTEasy library
         resteasy_lib = subprocess.check_output(
             '. /etc/pki/pki.conf && echo $RESTEASY_LIB',
@@ -67,10 +46,10 @@ class AddedRESTEasyClient(pki.server.upgrade.PKIServerUpgradeScriptlet):
         # create new links
         source = os.path.join(resteasy_lib, 'resteasy-client.jar')
         link = os.path.join(common_lib, 'resteasy-client.jar')
-        self.create_link(source, link, uid, gid)
+        self.create_link(instance, source, link)
 
-    def create_link(self, source, link, uid, gid):
+    def create_link(self, instance, source, link):
 
         self.backup(link)
         os.symlink(source, link)
-        os.lchown(link, uid, gid)
+        os.lchown(link, instance.uid, instance.gid)
diff --git a/base/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations b/base/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations
index 20f35e837d2dbce7bfee01187b9763d4ff592d40..2a1ec99d716ff0124cfa58327ef003cd1e8e0eb1 100755
--- a/base/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations
+++ b/base/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations
@@ -19,9 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
 import shutil
 import signal
 import sys
@@ -52,10 +50,7 @@ class MoveWebApplicationDeploymentLocations(pki.server.upgrade.PKIServerUpgradeS
         if not os.path.exists(subsystem_webapps):
             os.mkdir(subsystem_webapps)
 
-        uid = pwd.getpwnam('pkiuser').pw_uid
-        gid = grp.getgrnam('pkiuser').gr_gid
-
-        os.chown(subsystem_webapps, uid, gid)
+        os.chown(subsystem_webapps, instance.uid, instance.gid)
         os.chmod(subsystem_webapps, 0770)
 
         # move subsystem webapp
@@ -74,10 +69,7 @@ class MoveWebApplicationDeploymentLocations(pki.server.upgrade.PKIServerUpgradeS
         if not os.path.exists(common_webapps):
             os.mkdir(common_webapps)
 
-        uid = pwd.getpwnam('pkiuser').pw_uid
-        gid = grp.getgrnam('pkiuser').gr_gid
-
-        os.chown(common_webapps, uid, gid)
+        os.chown(common_webapps, instance.uid, instance.gid)
         os.chmod(common_webapps, 0770)
 
         # move ROOT webapp
diff --git a/base/server/upgrade/10.2.3/01-FixInstanceWorkFolderOwnership b/base/server/upgrade/10.2.3/01-FixInstanceWorkFolderOwnership
index 6872a165a6f5ae0629f2709aa7522713ea2d4d0f..700aaf3ce682682148ed444337b25eaac2482b0b 100755
--- a/base/server/upgrade/10.2.3/01-FixInstanceWorkFolderOwnership
+++ b/base/server/upgrade/10.2.3/01-FixInstanceWorkFolderOwnership
@@ -19,10 +19,7 @@
 # All rights reserved.
 #
 
-import grp
 import os
-import pwd
-import re
 import pki.server.upgrade
 
 
@@ -32,26 +29,6 @@ class FixInstanceWorkFolderOwnership(pki.server.upgrade.PKIServerUpgradeScriptle
         self.message = 'Fix instance work folder ownership'
 
     def upgrade_instance(self, instance):
-        registry_file = os.path.join(
-            pki.server.REGISTRY_DIR, 'tomcat', instance.name, instance.name)
-
-        with open(registry_file, "r") as registry:
-            lines = registry.readlines()
-
-        user = None
-        group = None
-
-        for line in lines:
-            m = re.search('^PKI_USER=(.*)$', line)
-            if m:
-                user = m.group(1)
-            m = re.search('^PKI_GROUP=(.*)$', line)
-            if m:
-                group = m.group(1)
-
-        uid = pwd.getpwnam(user).pw_uid
-        gid = grp.getgrnam(group).gr_gid
 
         dir = os.path.join(instance.base_dir, 'work/Catalina/localhost/pki')
-
-        pki.util.chown(dir, uid, gid)
+        pki.util.chown(dir, instance.uid, instance.gid)
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]