Let Tomcat is download and installed under /opt/tomcat.
Also, let tomcat be a non-provileged user under which the server will be running.
We assume that we keep server's binaries under /opt/tomcat and we will create a server instance named foo under /var/tomcat/ (carrying its own conf, logs, webapps, work, lib directories).
See also https://dzone.com/articles/running-multiple-tomcat.
Create a template service unit file at /etc/systemd/system/[email protected]:
[Unit]
Description=Tomcat - instance %i
After=syslog.target network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
WorkingDirectory=/var/tomcat/%i
Environment="JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_PID=/var/tomcat/%i/run/tomcat.pid"
Environment="CATALINA_BASE=/var/tomcat/%i/"
Environment="CATALINA_HOME=/opt/tomcat/"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
#RestartSec=10
#Restart=always
[Install]
WantedBy=multi-user.targetNow, we can instantiate a service instance for our foo tomcat instance:
systemctl daemon-reload
systemctl enable [email protected]
systemctl start [email protected]
This is an excellent link and at the bottom gives a great way of avoiding
Type=forking. Use a service file like:Obviously adjust to suit your own environment. I need the
WorkingDirectoryfor some apps to add their log files (so not the standard tomcat log files) to the logs folder. Many won't need it.There is no need to set a
CATALINA_HOMEas thecatalina.shworks it out from the path in the ExecStart statement.I do not set
JAVA_HOMEhere, preferring setenv.sh. This allows the instantiated version of the start up to run different versions of Java for differentCATALINA_BASEs. Even if you do set it here, it can be overridden in setenv.sh.PermissionsStartOnlyis probably totally unnecessary.It can be simply instantiated by changing the two references
tomcat-your_sitetotomcat-%IIf you want a pid file, add:
Again, it can be instantiated.