[Switch] rapid deployment of Tomcat project Shell script, tomcatshell
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:
#!/bin/shwar=$1bin=$(cd `dirname $0`; pwd)if [ ! -n "${war}" ]; then echo "***Usage: $0 [project.war]" exit 0fiif [ ! -f "${war}" ]; then echo "***Error: ${war} does not exist." exit 0fiif [ ! "${war##*.}" = "war" ]; then echo "***Error: ${war} is not a war file." exit 0fiecho "Deploy ${war##*/}..."rm -rf ${bin}/../webapps/ROOT/ && unzip -qo ${war} -d ${bin}/../webapps/ROOT/rm -rf ${bin}/../work/Catalina/localhost/echo "Restart tomcat..."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:
#!/bin/shbin=$(cd `dirname $0`; pwd)pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}') if [ -n "${pid}" ]; then echo "Shutdown..." sh ${bin}/shutdown.sh sleep 3 pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}') if [ -n "${pid}" ]; then kill ${pid} sleep 1 fifiecho "Startup..."sh ${bin}/startup.shif [ "$1" = "-v" ]; then tail -f -n 600 ${bin}/../logs/catalina.outfi
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.
Link: https://www.linuxidc.com/Linux/2016-01/127258.htm