Skip to content

Commit

Permalink
Merge pull request #137 from jajik/issue-132
Browse files Browse the repository at this point in the history
Fix tomcat ports overlapping
  • Loading branch information
rhusar authored Aug 30, 2023
2 parents a5b41f4 + 91f67f7 commit 35de1cd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
26 changes: 20 additions & 6 deletions test/includes/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,30 @@ tomcat_create() {
# Start tomcat$1 container on 127.0.0.$2
# or 127.0.0.$1 if $2 is not given
# arguments:
# $1 tomcat number
# $1 tomcat number (required)
# $2 tomcat's last byte of IPv4 address (if 0 or omitted, equals to $1)
# $3 tomcat port (if omitted it's 8080)
# $3 tomcat port (if omitted it's 8080 + $1 - 1)
# $4 tomcat ajp port (if omitted it's 8900 + $1 - 1)
# $5 tomcat shutdown port (if omitted it's 8005 + $1 - 1)
tomcat_start() {
if [ -z "$1" ]; then
echo "tomcat_start called without arguments"
exit 1
fi
ADDR="127.0.0.$1"
if [ ${2:-0} -ne 0 ]; then
ADDR="127.0.0.$2"
fi

local portdef=$(expr 8080 + $1 - 1)
local ajpdef=$(expr 8900 + $1 - 1)
local shutdef=$(expr 8005 + $1 - 1)

echo "Starting tomcat$1 on $ADDR"
nohup docker run --network=host -e tomcat_ajp_port=8010 \
nohup docker run --network=host -e tomcat_ajp_port=${4:-$ajpdef} \
-e tomcat_address=$ADDR \
-e tomcat_port=${3:-8080} \
-e tomcat_shutdown_port=8005 \
-e tomcat_port=${3:-$portdef} \
-e tomcat_shutdown_port=${5:-$shutdef} \
-e jvm_route=tomcat$1 \
--name tomcat$1 ${IMG} &
ps -q $! > /dev/null
Expand Down Expand Up @@ -250,14 +260,18 @@ tomcat_start_webapp() {
}

# Send a shutdown packet to a tomcat$1 container
# arguments:
# $1 tomcat number
# $2 the last segment of IPv4 addr ($1 by default)
# $3 the shutdown port (8005 + $1 - 1 by default)
tomcat_shutdown() {
ADDR="127.0.0.$1"
if [ $2 -ne 0 ]; then
ADDR="127.0.0.$2"
fi

echo "shutting down tomcat$1 with address: $ADDR"
echo "SHUTDOWN" | nc $ADDR 8005
echo "SHUTDOWN" | nc $ADDR ${3:-$(expr 8005 + $1 - 1)}
}

# Remove the docker image tomcat$1
Expand Down
6 changes: 3 additions & 3 deletions test/tomcat/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN" address="127.0.0.1">
<Server port="shutdown_port" shutdown="SHUTDOWN" address="127.0.0.1">
<!-- <Listener className="org.jboss.modcluster.container.tomcat.ModClusterListener" advertise="true" stickySession="true" stickySessionForce="false" stickySessionRemove="true" /> -->
<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" connectorPort="changeMe" advertise="false" stickySession="true" stickySessionForce="false" stickySessionRemove="true" proxyList="proxyaddress:proxyport"/>
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
Expand Down Expand Up @@ -68,7 +68,7 @@
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
<Connector port="tomcat_port" protocol="HTTP/1.1"
address="127.0.0.1"
connectionTimeout="20000"
redirectPort="8443" />
Expand Down Expand Up @@ -119,7 +119,7 @@

<Connector protocol="AJP/1.3"
address="127.0.0.1"
port="8009"
port="ajp_port"
secretRequired="false"
redirectPort="8443" />

Expand Down
8 changes: 4 additions & 4 deletions test/tomcat/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ fi


if [ ! -z ${tomcat_port} ]; then
sed -i "s/8080/${tomcat_port}/" ./conf/server.xml
sed -i "s/tomcat_port/${tomcat_port}/" ./conf/server.xml
fi

if [ ! -z ${tomcat_shutdown_port} ]; then
sed -i "s/8005/${tomcat_shutdown_port}/" ./conf/server.xml
sed -i "s/shutdown_port/${tomcat_shutdown_port}/" ./conf/server.xml
fi

if [ ! -z ${tomcat_ajp_port} ]; then
sed -i "s/8009/${tomcat_ajp_port}/" ./conf/server.xml
sed -i "s/ajp_port/${tomcat_ajp_port}/" ./conf/server.xml
fi
if [ ! -z ${tomcat_address} ]; then
sed -i "s/127.0.0.1/${tomcat_address}/" ./conf/server.xml
Expand All @@ -47,7 +47,7 @@ fi
sed -i "s/proxyport/${cluster_port}/" ./conf/server.xml
sed -i "s/proxyaddress/127.0.0.1/" ./conf/server.xml

echo "jvm_route: ${jvm_route} and tomcat_port: ${tomcat_port} and tomcat_address: ${tomcat_address}"
echo "jvm_route: ${jvm_route:-default} tomcat_port: ${tomcat_port:-default} tomcat_address: ${tomcat_address:-default} tomcat_ajp_port: ${tomcat_ajp_port:-default} tomcat_shutdown_port: ${tomcat_shutdown_port:-default}"
if [ ! -z ${jvm_route} ]; then
sed -i "/<Engine name=\"Catalina\"/c\<Engine name=\"Catalina\" defaultHost=\"localhost\" jvmRoute=\"${jvm_route}\">" ./conf/server.xml
fi
Expand Down

0 comments on commit 35de1cd

Please sign in to comment.