From 243cbf17ef88a3ec00980670f3918db925955c6c Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Wed, 6 May 2015 00:08:30 -0400 Subject: Fixed migration tool to update Tomcat libraries. The migration tool has been fixed to update the links to Tomcat libraries in the instance folder to match the current Tomcat version installed on the system. https://fedorahosted.org/pki/ticket/1353 --- base/server/python/pki/server/__init__.py | 14 +++++------ base/server/python/pki/server/cli/migrate.py | 37 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) (limited to 'base/server/python') diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py index bbdfedc2c..7cb50fcee 100644 --- a/base/server/python/pki/server/__init__.py +++ b/base/server/python/pki/server/__init__.py @@ -50,6 +50,7 @@ class PKIServer(object): return instances + class PKISubsystem(object): def __init__(self, instance, subsystem_name): @@ -104,10 +105,11 @@ class PKIInstance(object): if self.type >= 10: self.base_dir = os.path.join(INSTANCE_BASE_DIR, name) - self.conf_dir = os.path.join(self.base_dir, 'conf') else: self.base_dir = os.path.join(pki.BASE_DIR, name) - self.conf_dir = os.path.join(self.base_dir, 'conf') + + self.conf_dir = os.path.join(self.base_dir, 'conf') + self.lib_dir = os.path.join(self.base_dir, 'lib') self.registry_dir = os.path.join(pki.server.REGISTRY_DIR, 'tomcat', self.name) self.registry_file = os.path.join(self.registry_dir, self.name) @@ -146,10 +148,12 @@ class PKIInstance(object): m = re.search('^PKI_USER=(.*)$', line) if m: self.user = m.group(1) + self.uid = pwd.getpwnam(self.user).pw_uid m = re.search('^PKI_GROUP=(.*)$', line) if m: self.group = m.group(1) + self.gid = grp.getgrnam(self.group).gr_gid for subsystem_name in os.listdir(self.registry_dir): if subsystem_name in pki.server.SUBSYSTEM_TYPES: @@ -196,12 +200,8 @@ class PKIInstance(object): with open(context_xml, 'w') as f: f.write(etree.tostring(document, pretty_print=True)) - # find uid and gid - uid = pwd.getpwnam(self.user).pw_uid - gid = grp.getgrnam(self.group).gr_gid - # set deployment descriptor ownership and permission - os.chown(context_xml, uid, gid) + os.chown(context_xml, self.uid, self.gid) os.chmod(context_xml, 00660) def undeploy(self, webapp_name): diff --git a/base/server/python/pki/server/cli/migrate.py b/base/server/python/pki/server/cli/migrate.py index 5b387cd67..bb807d8ca 100644 --- a/base/server/python/pki/server/cli/migrate.py +++ b/base/server/python/pki/server/cli/migrate.py @@ -106,6 +106,8 @@ class MigrateCLI(pki.cli.CLI): pki_context_xml = os.path.join(instance.conf_dir, 'Catalina', 'localhost', 'pki.xml') self.migrate_context_xml(pki_context_xml, tomcat_version) + self.migrate_tomcat_libraries(instance) + def migrate_server_xml(self, filename, tomcat_version): if self.verbose: @@ -379,6 +381,9 @@ class MigrateCLI(pki.cli.CLI): def migrate_context_xml(self, filename, tomcat_version): + if not os.path.exists(filename): + return + if self.verbose: print 'Migrating %s' % filename @@ -429,3 +434,35 @@ class MigrateCLI(pki.cli.CLI): context.append(resources) resources.set('allowLinking', 'true') + + def migrate_tomcat_libraries(self, instance): + + # remove old links + for filename in os.listdir(instance.lib_dir): + + if not filename.endswith('.jar'): + continue + + path = os.path.join(instance.lib_dir, filename) + + if self.verbose: + print 'Removing %s' % path + + os.remove(path) + + tomcat_dir = '/usr/share/tomcat/lib' + + # create new links + for filename in os.listdir(tomcat_dir): + + if not filename.endswith('.jar'): + continue + + source = os.path.join(tomcat_dir, filename) + dest = os.path.join(instance.lib_dir, filename) + + if self.verbose: + print 'Creating %s' % dest + + os.symlink(source, dest) + os.lchown(dest, instance.uid, instance.gid) -- cgit