Is it possible to overwrite Tomcat7 ports, appBase and Realm attributes (which are in server.xml) from the startup script?
-
28-05-2021 - |
문제
In a production environment, we have many different instances of Tomcats. Each Tomcat is listening on different ports, using a different database as JDBCRealm, and running apps from a different appBase directory. So here are the parameters that have instance-specific values:
port
attribute ofServer
andConnector
elementconnectionURL
,connectionName
,connectionPassword
attributes ofRealm
elementappBase
attribute ofHost
element
When someone (re)deploys a (new) Tomcat instance, one has to replace the server.xml (which comes from source control) to set instance-specific values to these parameters.
I would prefer to have the same server.xml in the different instances. So my question is, is it possible to overwrite/redefine these parameters from the startup script?
해결책
Yes, but you'll need to parameterise your server.xml.
For example, for the http connector you'd do this:
<Connector port="${port.http}" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="${port.https}" />
and then create/edit setenv.[bat|sh] and add something along the lines of (for Windows):
set CATALINA_OPTS=-Dport.http=10180 -Dport.https=10143
Don't forget that you'll also need to parameterise the shut down port. This technique will work for any attribute value in server.xml, context.xml and web.xml.