How to write the shell script for to stop the tomcat.
tomcat version - tomcat9
environment - Linux
OS - centos7
How to write the shell script for to stop the tomcat.
tomcat version - tomcat9
environment - Linux
OS - centos7
The scripts located in the Tomcat directory are the most barebones ways of starting the server. To stop the Tomcat server change active directory to the tomcat root and execute
./catalina.sh stop
I recommend reading this article by O'Reilly to better understand how tomcat works:
Starting, Stopping, and Restarting Tomcat
You can create basic shell script and add one of the following commands mentioned below. If need to automate that can be done by CronScheduler
built in Linux tool.
There are two ways this can be done in Linux
and Windows
.
Linux:
./catalina.sh stop
Passing "stop" argument for catalina.sh --> stops the Tomcat in the background. Since in background no issues closing down the terminal. The logs need to be viewed as below: tail -f $CATALINA_HOME/logs/catalina.out
./shutdown.sh
The last way is firing the shutdown.sh to stop your Tomcat server. If you Vi the script you can see it calls catalina.sh script passing stop as the argument. This will be running in background as well.
Windows:
shutdown.bat // stop tomcat server
Create a file and write the following lines of code:
#!/bin/bash
systemctl stop tomcat
execute the bash script: bash fileName.sh