Rapid deployment of Shell scripts for Tomcat Projects
In order to perform cluster testing, three tomcat servers are installed on each machine. During each project release, multiple commands are required. Before restarting tomcat, check whether the tomcat process has been stopped, there is no need to manually kill the process.
As the number of releases increases, the operation is complicated. Simply write a script for one-click release, saving time and effort ^_^.
Copy deploy. sh and restart. sh to the three tomcat bin directories respectively, and then grant the executable permissions to the two scripts using chmod + x.
One-click release command:./deploy. sh project war Package example:./deploy. sh/home/test. war
Note: deploy. sh first clears the ROOT directory under tomcat, then pressurizes the specified war package to the ROOT directory, and finally executes restart. sh to restart tomcat.
The Code is as follows:
1 #!/bin/sh 2 3 war=$1 4 bin=$(cd `dirname $0`; pwd) 5 6 if [ ! -n "${war}" ]; then 7 echo "***Usage: $0 [project.war]" 8 exit 0 9 fi10 if [ ! -f "${war}" ]; then11 echo "***Error: ${war} does not exist."12 exit 013 fi14 if [ ! "${war##*.}" = "war" ]; then15 echo "***Error: ${war} is not a war file."16 exit 017 fi18 19 echo "Deploy ${war##*/}..."20 rm -rf ${bin}/../webapps/ROOT/ && unzip -qo ${war} -d ${bin}/../webapps/ROOT/21 rm -rf ${bin}/../work/Catalina/localhost/22 echo "Restart tomcat..."23 exec ${bin}/restart.sh
To restart tomcat, run the following command:./restart. sh or./restart. sh-v (parameter-v indicates printing tomcat startup logs at startup)
Note: restart. sh is used to restart tomcat. If tomcat is not started, it is started directly. If it is started, shutdown and start again. If the tomcat process is not stopped 3 s after shutdown, kill the original process and start again.
The Code is as follows:
1 #!/bin/sh 2 3 bin=$(cd `dirname $0`; pwd) 4 pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}')
5 6 if [ -n "${pid}" ]; then 7 echo "Shutdown..." 8 sh ${bin}/shutdown.sh 9 sleep 310 11 pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}')
12 if [ -n "${pid}" ]; then13 kill -9 ${pid}14 sleep 115 fi16 fi17 18 echo "Startup..."19 sh ${bin}/startup.sh20 if [ "$1" = "-v" ]; then21 tail -f ${bin}/../logs/catalina.out22 fi
I am using CentOS. The three tomcat servers are listening to port 7.0.65/8080/8081 IN THE 8082/8080/8081 subdirectory under/opt/apache-tomcat-8082. Run the following command:
Enter http: // localhost: 8080 in the browser.
For more Tomcat tutorials, see the following:
Install and configure the Tomcat environment in CentOS 6.6
Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects
Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)
Tomcat Security Configuration and Performance Optimization
How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux
Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure
Install Tomcat in CentOS 6.5
Tomcat details: click here
Tomcat: click here
This article permanently updates the link address: