Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rocky 9 branch: Add support for Tomcat 9, 10, and 11, comply with new Tomcat RPMs, add RPM builder script, cleanup #2

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Changelog
*~
.project
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1
2.5.1
48 changes: 48 additions & 0 deletions buildRpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/sh

pkgName=tomcat-instance-framework
pkgVersion=$(cat VERSION)

runtimeDir=$(pwd)
sourceDir=$(dirname $(realpath $0))
cd $sourceDir

workspace=/tmp/rpmbuild-$(openssl rand -hex 12)
buildDirName=build
buildDirPath=${workspace}/${buildDirName}

git log --date=short --pretty=format:"%h%x09%an%x09%ad%x09%s" > Changelog


# purge any previous work directories and recreate
rm -rf ${buildDirPath}
mkdir -p ${buildDirPath}/rpm-build
cd ${buildDirPath}
$(cd rpm-build; mkdir -p BUILD RPMS SOURCES SPECS SRPMS)

ln -s ${sourceDir} ${pkgName}-${pkgVersion}
tar -czf ${buildDirPath}/rpm-build/${pkgName}-${pkgVersion}.tar.gz \
-C ${buildDirPath} \
--exclude .git \
--exclude .gitignore \
--exclude ${buildDirName} \
-h ${pkgName}-${pkgVersion}

cd -

rpmbuild \
-ba \
--define "_topdir ${buildDirPath}/rpm-build" \
--define "_builddir %{_topdir}" \
--define "_rpmdir %{_topdir}/RPM" \
--define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
--define "_srcrpmdir %{_topdir}/RPM" \
--define "_specdir %{_topdir}" \
--define "_sourcedir %{_topdir}" \
--define "vendor EuPathDB" \
--define "pkg_version ${pkgVersion}" \
--define "debug_package %{nil}" \
${sourceDir}/tomcat-instance-framework.spec

# copy generated RPMs to the runtime directory
cp ${buildDirPath}/rpm-build/RPM/*.rpm $runtimeDir
29 changes: 9 additions & 20 deletions instance_manager
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TOMCAT_INSTANCES_DIR="$(readlink -e "$TOMCAT_INSTANCES_DIR")"
#///////////////////////////////////////////////////////////////#

# clear invoker's env. Only use what is specified inline or by
# source-ing instance.env
# sourcing instance.env
unset $(/usr/bin/env | \
egrep -v 'TOMCAT_INSTANCES_DIR|USER' | \
egrep '^(\w+)=(.*)$' | \
Expand Down Expand Up @@ -45,7 +45,6 @@ usage() {
exit 1
}


expanded_usage() {
local known_instances=`get_known_instances`
(
Expand Down Expand Up @@ -144,25 +143,21 @@ set_manager_credentials() {

TC_USER=${cred[0]}
TC_PASS=${cred[1]}

}


require_sudo() {
if [[ "$TOMCAT_USER" != "$USER" && `id -u` != 0 ]]; then
echo 'sudo/root permissions required for this action.'; exit 4;
fi
}


# determine the version of Tomcat.
# The version.sh script is included with Tomcat >= 5.0, don't know about earlier.
# Basically it runs "java -classpath $CATALINA_HOME/lib/catalina.jar org.apache.catalina.util.ServerInfo"
tomcat_version() {
$CATALINA_HOME/bin/version.sh | grep '^Server version:' | cut -d'/' -f2
}


# The url path to the Tomcat Manager varies with Tomcat version
# /manager/<verb> for TC 6, /manager/text/<verb> for TC 7 .
manager_path_for_version() {
Expand All @@ -180,13 +175,18 @@ manager_path_for_version() {
9.*)
echo 'manager/text'
;;
*)
10.*)
echo 'manager/text'
;;
11.*)
echo 'manager/text'
;;
*)
echo 1>&2 "unable to determine the manager's URL path for Tomcat version '${tomcat_version}'"
;;
esac
}


# initialize for management tasks (start, stop, enable, disable, list)
init_for_managment() {

Expand Down Expand Up @@ -272,7 +272,6 @@ init_for_managment() {
-Dtcif.root=$TOMCAT_INSTANCES_DIR \
"}


# 'eval echo' expands any embedded variables
for val in "${CATALINA_OPTS[*]}"; do
CATALINA_OPTS_E="${CATALINA_OPTS_E} $(eval echo $val)"
Expand Down Expand Up @@ -302,7 +301,6 @@ init_for_managment() {

} # init_for_managment()


# output parent and child processes
get_pids() {
# processes owned by $TOMCAT_USER
Expand All @@ -321,7 +319,6 @@ get_pids() {
echo $pids
}


start() {
require_sudo

Expand Down Expand Up @@ -390,7 +387,6 @@ start() {
return $exit_status
}


stop() {
require_sudo

Expand Down Expand Up @@ -425,7 +421,6 @@ stop() {

# add newline after last dot
echo ""

}

disable() {
Expand All @@ -443,7 +438,6 @@ disable() {
echo "Renaming ${INSTANCE} directory to _${INSTANCE}"
cd "${TOMCAT_INSTANCES_DIR}"
mv "${INSTANCE}" "_${INSTANCE}"

}

enable() {
Expand Down Expand Up @@ -486,7 +480,6 @@ deployFile() {
cd - > /dev/null
}


# pass in context xml to create and deploy from temporary context.xml file
deployVirtual() {
local HTTP_PORT=$1
Expand All @@ -503,7 +496,6 @@ deployVirtual() {
rm -f $tmp_ctx_file || { echo "could not delete temp file '$tmp_ctx_file'. Please manually remove it."; }
}


undeploy() {
local webapp=$1
local tomcat_ctx=$([ "$webapp" == "ROOT" ] && echo "/" || echo "/$webapp")
Expand Down Expand Up @@ -598,15 +590,13 @@ tstatus() {
fi
}


wstatus() {
local webapp=$1
local tomcat_ctx=$([ "$webapp" == "ROOT" ] && echo "/" || echo "/$webapp")
set_manager_credentials $INSTANCE
curl -s "http://$TC_USER:[email protected]:$HTTP_PORT/${MANAGER_PATH}/list" | egrep "^$tomcat_ctx:" | awk -F: "{print \$2}"
}


start_app() {
local webapp=$1
if [ -z $webapp ]; then
Expand All @@ -632,7 +622,6 @@ start_app() {
fi
}


manage() {
[ "$1" == "" ] && usage;
[ ! -d "$1" ] && echo "Instance '$1' not found." && exit 1;
Expand Down Expand Up @@ -733,7 +722,7 @@ EOF
}

INSTANCE=$2
# Special case when starting/stoping instance 'all'. Iteratively
# Special case when starting/stopping instance 'all'. Iteratively
# invoke this script for each active instance found.
if [[
"$INSTANCE" == "all" &&
Expand Down
12 changes: 5 additions & 7 deletions tomcat-instance-framework.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%define pkg_name tomcat-instance-framework
%define instance_dir tomcat_instances
%define required_tomcat_version 6.0.35
%define required_java_version 1.7.0_25
%define required_tomcat_version 9
%define required_java_version 21
%define required_oracle_version 11.2.0.3
%define tomcat_uid 300
%define packager Mark Heiges <[email protected]>
Expand All @@ -13,16 +13,15 @@ Version: %{pkg_version}
Release: 1.el%{?rhel}
License: GPL
Group: Networking/Daemons
URL: https://www.cbil.upenn.edu/apiwiki/index.php/UGATomcatConfiguration
URL: https://wiki.apidb.org/index.php/UGATomcatConfiguration
Packager: %{packager}

Requires: jdk >= %{required_java_version}
Requires: java-21-openjdk >= %{required_java_version}
Requires: tomcat-%{required_tomcat_version}
Requires: perl-XML-Simple
Requires(pre): %{_sbindir}/useradd
Requires(pre): %{_sbindir}/groupadd


Source0: tomcat-instance-framework-%{version}.tar.gz

BuildRoot: %{_tmppath}/%{pkg_name}-%{version}
Expand All @@ -37,8 +36,7 @@ Tomcat instances for the EuPathDB BRC project.

%build
%define tc_shared_conf tomcat_instances/shared/conf/global.env
sed -i 's;^CATALINA_HOME=.*;CATALINA_HOME=/usr/local/apache-tomcat-%{required_tomcat_version};' %{tc_shared_conf}
sed -i 's;^JAVA_HOME=.*;JAVA_HOME=/usr/java/jdk%{required_java_version};' %{tc_shared_conf}
sed -i 's;^CATALINA_HOME=.*;CATALINA_HOME=/usr/local/tomcat-%{required_tomcat_version};' %{tc_shared_conf}
sed -i 's;^ORACLE_HOME=.*;ORACLE_HOME=/u01/app/oracle/product/%{required_oracle_version}/db_1;' %{tc_shared_conf}

%install
Expand Down
32 changes: 20 additions & 12 deletions tomcat_instances/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
# Make a Tomcat project instance for EuPathDB
# usage
#
# Example Usage:
#
# make install \
# INSTANCE=FooDB \
# HTTP_PORT=19280 \
# AJP13_PORT=19209 \
# JMX_PORT=19205 \
# TOMCAT_USER=tomcat_Z \
# TEMPLATE=7.0.x \
# CATALINA_HOME=/usr/local/apache-tomcat-7.0.103 \
# ORCL_JDBC_PATH=$ORACLE_HOME/jdbc/lib/ojdbc6.jar \
# PG_JDBC_PATH=$PG_HOME/lib/java/postgresql92-jdbc.jar
#
# Note: You cannot update the template
#
# make update \
# INSTANCE=FooDB \
# HTTP_PORT=19280 \
# AJP13_PORT=19209 \
# JMX_PORT=19205 \
# TOMCAT_USER=tomcat_Z \
# CATALINA_HOME=/usr/local/apache-tomcat-7.0.103 \
# ORCL_JDBC_PATH=$ORACLE_HOME/jdbc/lib/ojdbc6.jar \
# PG_JDBC_PATH=$PG_HOME/lib/java/postgresql92-jdbc.jar
#
# Optionally,
# ORCL_JDBC_PATH and PG_JDBC_PATH are optional
# Optional values:
# ORCL_JDBC_PATH, PG_JDBC_PATH

# Other special purppose variables
# Other special purpose variables
# DEFER_USER=1 - do not do check and chown for user. Useful for RPM builds on naive servers,
# assuming the RPM install process does the chown (e.g. using %attr() ).

Expand All @@ -36,12 +42,13 @@ all:
@echo 'make update'
@echo
@echo 'Required variables:'
@echo ' INSTANCE=FooDB \
HTTP_PORT=19280 \
AJP13_PORT=19209 \
JMX_PORT=19205 \
TOMCAT_USER=tomcat_Z \
TEMPLATE=7.0.23'
@echo ' INSTANCE=FooDB \
HTTP_PORT=19280 \
AJP13_PORT=19209 \
JMX_PORT=19205 \
TOMCAT_USER=tomcat_Z \
CATALINA_HOME=/usr/local/apache-tomcat-7.0.103 \
TEMPLATE=7.0.x'
@echo
@echo 'Optional variables:'
@echo ' ORCL_JDBC_PATH=$$ORACLE_HOME/jdbc/lib/ojdbc6.jar'
Expand All @@ -62,7 +69,7 @@ endif

can_update :
ifeq "$(wildcard $(INSTANCE) )" ""
@echo $(INSTANCE) does not exit
@echo $(INSTANCE) does not exist
@exit 1
endif

Expand All @@ -89,7 +96,7 @@ install_pg_driver:
copy_temp_template:
cp -a templates/$(TEMPLATE) $(INSTANCE)
chmod 0644 $(INSTANCE)/conf/tomcat-users.xml

configure:
@echo configure instance.env ...
cd $(INSTANCE)/conf \
Expand All @@ -98,6 +105,7 @@ configure:
-e 's;AJP13_PORT=.*;AJP13_PORT=$(AJP13_PORT);' \
-e 's;JMX_PORT=.*;JMX_PORT=$(JMX_PORT);' \
-e 's;TOMCAT_USER=.*;TOMCAT_USER=$(TOMCAT_USER);' \
-e 's;CATALINA_HOME=.*;CATALINA_HOME=$(CATALINA_HOME);' \
instance.env.in > instance.env

@echo set tomcat-users.xml credentials \(not echoed to screen\) ...
Expand Down
18 changes: 11 additions & 7 deletions tomcat_instances/shared/conf/global.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # #

#
# Directory of the Tomcat binary distribution.
# Directory of the default Tomcat binary distribution.
# This can, and should, be a stock installation.
# Instances are instantiated from this.
#
# Instances are, well, instantiated from this.
# When used with RPMs generated from tool-tomcat-rpm-builder (see Github repo),
# apache-tomcat is a soft link to one of the installed Tomcat major versions.
# If an instance is desired for a non-default major version, specify a custom
# CATALINA_HOME when creating the instance (using the Makefile)
#
CATALINA_HOME=/usr/local/apache-tomcat-6.0.35
CATALINA_HOME=/usr/local/apache-tomcat

#
# Base directory for all instances
Expand All @@ -30,13 +34,13 @@ INSTANCE_DIR=/usr/local/tomcat_instances
#
# Java installation directory
#
JAVA_HOME=/usr/java/jdk1.7.0
JAVA_HOME=/usr/lib/jvm/java

#
# The Tomcat Instance Framework requires jsvc.
# This is the path to that executable.
# The value inludes the variable $CATALINA_HOME
# and that varibable is escaped so it will not
# The value includes the variable $CATALINA_HOME
# and that variable is escaped so it will not
# be evaluated until after instance.env is
# read. This way CATALINA_HOME can be redefined
# in instance.env and JSVC_EXE evaluates to the
Expand Down Expand Up @@ -64,7 +68,7 @@ AUTO_DEPLOY=false
# TMP_DIR=/tmp

#
#
# Location of Oracle installation (driver jar pulled from here by default)
#
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/db_1

Expand Down
Loading