From 35354988b0e49f8a7d060bdafec1f49578c0ed1a Mon Sep 17 00:00:00 2001 From: Ade Lee Date: Fri, 19 Sep 2014 11:54:29 -0400 Subject: Added idempotent 01-MoveWebApplicationContextFile migration script Added to 10.1.1 to be consistent with 10.1 branch. --- base/server/upgrade/10.1.1/.gitignore | 4 - .../10.1.1/01-MoveWebApplicationContextFile | 102 +++++++++++++++++++++ base/server/upgrade/10.1.2/.gitignore | 4 + .../10.1.99/01-MoveWebApplicationContextFile | 6 ++ 4 files changed, 112 insertions(+), 4 deletions(-) delete mode 100644 base/server/upgrade/10.1.1/.gitignore create mode 100755 base/server/upgrade/10.1.1/01-MoveWebApplicationContextFile create mode 100644 base/server/upgrade/10.1.2/.gitignore (limited to 'base/server/upgrade') diff --git a/base/server/upgrade/10.1.1/.gitignore b/base/server/upgrade/10.1.1/.gitignore deleted file mode 100644 index 5e7d2734c..000000000 --- a/base/server/upgrade/10.1.1/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore diff --git a/base/server/upgrade/10.1.1/01-MoveWebApplicationContextFile b/base/server/upgrade/10.1.1/01-MoveWebApplicationContextFile new file mode 100755 index 000000000..603fc6b8f --- /dev/null +++ b/base/server/upgrade/10.1.1/01-MoveWebApplicationContextFile @@ -0,0 +1,102 @@ +#!/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') + if not os.path.exists(metainf_dir): + # upgrade already done + return + self.backup(metainf_dir) + + old_context_file = os.path.join(metainf_dir, 'context.xml') + if not os.path.exists(old_context_file): + # upgrade already done + return + 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) diff --git a/base/server/upgrade/10.1.2/.gitignore b/base/server/upgrade/10.1.2/.gitignore new file mode 100644 index 000000000..5e7d2734c --- /dev/null +++ b/base/server/upgrade/10.1.2/.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 index f3bbf4477..603fc6b8f 100755 --- a/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile +++ b/base/server/upgrade/10.1.99/01-MoveWebApplicationContextFile @@ -45,9 +45,15 @@ class MoveWebApplicationContextFile(pki.server.upgrade.PKIServerUpgradeScriptlet def upgrade_webapp(self, instance, webapp): metainf_dir = os.path.join(instance.base_dir, 'webapps', webapp, 'META-INF') + if not os.path.exists(metainf_dir): + # upgrade already done + return self.backup(metainf_dir) old_context_file = os.path.join(metainf_dir, 'context.xml') + if not os.path.exists(old_context_file): + # upgrade already done + return self.backup(old_context_file) catalina_dir = os.path.join(instance.base_dir, 'conf', 'Catalina') -- cgit