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/SH2 3war=$14bin=$ (CD 'dirname$0`;pwd)5 6 if[!-N"${war}"]; Then7     Echo "***usage: $ [Project.war]"8Exit09 fiTen if[!-F"${war}"]; Then One     Echo "***error: ${war} does not exist." AExit0 - fi - if[ !"${war##*.}"="War"]; Then the     Echo "***error: ${war} is a war file." -Exit0 - fi -  + Echo "Deploy ${war##*/} ..." - RM-RF ${bin}/. /webapps/root/&&Unzip-qo ${war}-D ${bin}/. /webapps/root/&&RM-RF ${bin}/. /webapps/root/${war##*/} + RM-RF ${bin}/. /work/catalina/localhost/ A Echo "Restart Tomcat ..." atEXEC ${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/SH2 3bin=$ (CD 'dirname$0`;pwd)4Pid= 'PSAux |grepTomcat |grep-Vgrep|grep-V Restart |grep${bin} |awk '{print $}'`5 6 if[-N"${pid}"]; Then7     Echo "Shutdown ..."8     SH${bin}/shutdown.SH9     Sleep 3Ten  OnePid= 'PSAux |grepTomcat |grep-Vgrep|grep-V Restart |grep${bin} |awk '{print $}'` A     if[-N"${pid}"]; Then -         Kill-9${pid} -         Sleep 1 the     fi - fi -  - Echo "Startup ..." + SH${bin}/startup.SH - if[" $"="- v"]; Then +     Tail-F ${bin}/. /logs/Catalina.out A 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.