Shell scripts for quick deployment of Tomcat projects

Source: Internet
Author: User

In order to do cluster testing, 3 tomcat is installed on each machine, each time the project is released, it is necessary to repeatedly knock some commands, check that the Tomcat process has not stopped before restarting Tomcat, and kill the process manually.

Publish more times, the operation is more cumbersome, simply write a script one-click Release, save time and effort ^_^.

Copy the deploy.sh and restart.sh to 3 Tomcat bin directories, and then use chmod +x to assign executable permissions to both scripts.

One-click Publish command:./DEPLOY.SH Project War Package for example:./deploy.sh/home/test.war

Note: deploy.sh will first empty the root directory under Tomcat, then pressurize the specified war packet to the root directory, and finally execute restart.sh to restart Tomcat.

The code is as follows:

1 #!/bin/sh 2  3 war=$1 4 bin=$ (CD ' DirName $ '; pwd) 5  6 if [!-n ' ${war} ']; then 7     echo "***usage: $ [proj Ect.war] "8     exit 0 9 fi10 if [!-F" ${war} "]; Then11     echo" ***error: ${war} does not exist. "     Exit 013 fi14 if [! "${war##*.}" = "war"]; Then15     echo "***error: ${war} is a war file."     exit 017 fi18 "Deploy ${war##*/} ..." Rm-rf ${bin}/. /webapps/root/&& Unzip-qo ${war}-D ${bin}/. /webapps/root/
RM-RF ${bin}/. /WORK/CATALINA/LOCALHOST/22 echo "Restart tomcat ..." at $ exec ${bin}/restart.sh

To restart Tomcat use the command:./restart.sh or./restart.sh-v (parameter-V indicates that the Tomcat boot log is printed at startup)

Description: restart.sh is used to restart Tomcat, if Tomcat does not start the direct start, if it has been started shutdown restart, if the shutdown after the 3s did not stop the Tomcat process, kill the original process and then start.

The code is as follows:

1 #!/bin/sh 2  
5 6 If [-N "${pid}"] and then 7 echo "Shutdown ..." 8 sh ${bin}/shutdown.sh 9 sleep 310 One -pid=$ (ps aux | grep tomcat | grep-v grep | grep-v Restart | grep ${bi n} | awk ' {print $} ')
if [-N "${pid}"]; then13 kill-9 ${pid}14 sleep + fi16 fi17 echo "Startup ..." sh ${bin}/startu P.SH20 if ["$" = "-V"]; Then21 tail-f ${bin}/. /logs/catalina.out22 fi

I use centos,3 tomcat in the/opt/apache-tomcat-7.0.65/under the 8080/8081/8082 sub-directory, listening to the 8080/8081/8082 port. Run as follows:

Finally, you can access it by typing http://localhost:8080 in the browser.

Shell scripts for quick deployment of Tomcat projects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.