Apache Tomcat comes with a startup and shutdown script;
$CATALINA_HOME/bin/startup.sh and $CATALINA_HOME/bin/shutdown.sh
Both of these scripts have some small issues, which we can improved upon...
Tomcat Start (startup.sh)
While the startup script does work without too many issues, it runs often without clearing out any of the log files or temporary directories. This leads to a full filesystem, which is bad.
To improve the startup script a bit, add the following line in red into $TOMCAT_HOME/bin/startup.sh at the beginning of the file:
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.272.b10-1.el7_9.x86_64 ; export JAVA_HOME CATALINA_HOME=/u01/apache/tomcat; export CATALINA_HOME CATALINA_OPTS='-server -Xms4g -Xmx14g -XX:MaxPermSize=512m' ; export CATALINA_OPTS CATALINA_PID=/tmp/tomcat.pid ; export CATALINA_PID
This will write the Tomcat ProcessID into a file /tmp/tomcat/pid. Once we have the PID in a file, if will be much easier to kill this process later on.
We can now define the NEW startup script as the following:
#!/bin/bash # save this to another file e.g. /usr/local/bin/tomcat_start.sh export CATALINA_HOME=[set this to your Tomcat directory] /bin/echo "Clearing out scratch files" /bin/rm -rf "$CATALINA_HOME/logs/* /bin/rm -rf "$CATALINA_HOME/temp/* /bin/rm -rf "$CATALIA_HOME/work/* /bin/echo "Restarting Tomcat" $CATALINA_HOME/bin/startup.sh /bin/echo "All Done."
Tomcat Stop (shutdown.sh)
There are also some issues with the shutdown script; namely, that thing takes a LOOONG time to complete.
When you shutdown.sh command is issued, you are returned back to the command line prompt. However it often takes upwards of a couple minutes before the tomcat processes are actually terminated. This leaves most of us in "OS Limbo", especially if we are waiting to do something else which REQUIRES that tomcat be actually down (like restarting Tomcat)
A better way to shutdown tomcat is to simply do a kill -9 on the tomcat process. Which we can define below. Doing so seems to be fine for apps running Banner, and there are no issues with starting things backup.
#!/bin/bash # save this to a new file, e.g. /usr/local/bin/tomcat_shutdown.sh /bin/echo "Killing Tomcat" /bin/kill -9 `/bin/cat /tmp/tomcat.pid`