From 5952a82975063c4ec27303091a44e586d1386933 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Wed, 27 Nov 2013 11:53:57 -0500 Subject: Moved web application context file. The location of web application context file has been changed from /webapps//META-INF/context.xml into /conf/Catalina/localhost/.xml. This will eventually allow deploying the web application directly from the shared folder. A new upgrade script has been added to move the context files in the existing instances. Ticket #499 --- base/server/upgrade/10.0.99/04-FixLogFileOwnership | 12 +-- base/server/upgrade/10.1.0/.gitignore | 4 + .../10.1.99/01-MoveWebApplicationContextFile | 96 ++++++++++++++++++++++ 3 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 base/server/upgrade/10.1.0/.gitignore create mode 100755 base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile (limited to 'base/server/upgrade') diff --git a/base/server/upgrade/10.0.99/04-FixLogFileOwnership b/base/server/upgrade/10.0.99/04-FixLogFileOwnership index d7de7f96f..b63055f29 100755 --- a/base/server/upgrade/10.0.99/04-FixLogFileOwnership +++ b/base/server/upgrade/10.0.99/04-FixLogFileOwnership @@ -51,14 +51,4 @@ class FixLogFileOwnership(pki.server.upgrade.PKIServerUpgradeScriptlet): log_dir = os.path.join('/var/log/pki', instance.name) - self._chown(log_dir, uid, gid) - - - def _chown(self, path, uid, gid): - os.chown(path, uid, gid) - for item in os.listdir(path): - itempath = os.path.join(path, item) - if os.path.isfile(itempath): - os.chown(itempath, uid, gid) - elif os.path.isdir(itempath): - self._chown(itempath, uid, gid) + pki.util.chown(log_dir, uid, gid) diff --git a/base/server/upgrade/10.1.0/.gitignore b/base/server/upgrade/10.1.0/.gitignore new file mode 100644 index 000000000..5e7d2734c --- /dev/null +++ b/base/server/upgrade/10.1.0/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile b/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile new file mode 100755 index 000000000..f3bbf4477 --- /dev/null +++ b/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile @@ -0,0 +1,96 @@ +#!/usr/bin/python +# Authors: +# Endi S. Dewata +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright (C) 2013 Red Hat, Inc. +# All rights reserved. +# + +import grp +import os +import pwd +import re + +import pki.server.upgrade + + +class MoveWebApplicationContextFile(pki.server.upgrade.PKIServerUpgradeScriptlet): + + def __init__(self): + + self.message = 'Move web application context file' + + def upgrade_instance(self, instance): + + self.upgrade_webapp(instance, 'ROOT') + self.upgrade_webapp(instance, 'pki') + + def upgrade_subsystem(self, instance, subsystem): + + self.upgrade_webapp(instance, subsystem.name) + + def upgrade_webapp(self, instance, webapp): + + metainf_dir = os.path.join(instance.base_dir, 'webapps', webapp, 'META-INF') + self.backup(metainf_dir) + + old_context_file = os.path.join(metainf_dir, 'context.xml') + self.backup(old_context_file) + + catalina_dir = os.path.join(instance.base_dir, 'conf', 'Catalina') + self.backup(catalina_dir) + + localhost_dir = os.path.join(catalina_dir, 'localhost') + self.backup(localhost_dir) + + new_context_file = os.path.join(localhost_dir, webapp + '.xml') + self.backup(new_context_file) + + # prepare target folder + if not os.path.exists(localhost_dir): + os.makedirs(localhost_dir) + + # 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) + + # remove old context file + if os.path.exists(old_context_file): + os.remove(old_context_file) + + # remove empty META-INF + if not os.listdir(metainf_dir): + os.rmdir(metainf_dir) -- cgit