Fast deployment Projects under Linux

Source: Internet
Author: User
Tags sleep tomcat linux

Linux and Java as open source, so now on the deployment of the server is basically the Linux platform as a server, and then deploy the project! In the process of development projects, most of the program ape or use the most classic Windows operating system, although Linux also has desktop systems, for the Chinese people, or not very accustomed to, and most of the domestic software does not support Linux platform, so the frequency of the use of that is quite small!

In development, the development environment in the compilation of the use of a series of passes, can not say that the function has been OK, because once the environment changes, the problem may not be considered, so the program apes know that the real environment is the most reliable, and sometimes the problem, in the real environment needs many times to reproduce, Even if you can't reproduce it for a long time, it's quite necessary to do a lot of testing in a real environment!

In terms of how to improve the deployment environment:

A shell script is used here to briefly describe the shell script: The shell Script,shell script is similar to the batch process under Windows/dos, that is, a program file that is put into a file in advance by a variety of commands to facilitate a one-time execution. It is mainly convenient for the administrator to set up or manage. But it is more powerful than batch processing under Windows, and is more efficient than a program edited with other programming programs, after all, it uses Linux/unix commands.

Another way of saying that is, Shell script is a program that utilizes the acronym of the Shell, which uses plain text files, writes the syntax and instructions of some shells in it, and then uses regular notation, pipeline commands, and data flow redirection to achieve the desired processing purpose.

More clearly, shell script wants to get up early in the DOS era. bat, the simplest function is to write a number of instructions together, so that the user can easily be able to execute a number of commands, and shell script is to provide the array, loop, condition and logical judgment and other important functions , allowing users to write programs directly to the shell without using the syntax written in traditional programs such as the C programming language.

The shell is simply introduced here! Now put the contents of the shell script (tom.sh) directly

#!/bin/bash  
      
service Tomcat stop sleep  
3  
#kill java  
killall java  
#remove pid  
rm-rf/var/run/ Tomcat.pid  
rm-rf/nac/web/tomcat/webapps/hupunac*/nac/web/tomcat/webapps/root  
rm-rf/nac/web/tomcat/work /*  
#clear log  
>/var/log/tomcat/catalina.out  
#rz  
cd/nac/web/tomcat/webapps  
RZ  
# Start Tomcat sleep  
3  
service tomcat start  
#  
echo ' Please wait for 80s ... '  
Netstat-an|grep::: 6002 >/dev/null  
if [$!= 0];then  
        service tomcat stop  
        killall java  
        rm-rf/v Ar/run/tomcat.pid  
        Service Tomcat start  
else
        echo "Tomcat start ok!"
Fi

Here's

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

Service Tomcat Stop command It should be clear that the Tomcat service first stops, of course, at this time the Tomcat service itself is not turned on, but does not affect the execution of the entire script

Sleep 3 refers to sleeping 3s (seconds), commonly known as waiting 3 seconds.

Killall Java forced kill Java program

RM-RF Force Delete, use this command primarily to remove files that must be deleted under the server

> This command is to empty the file means, in my main is to empty the log file

CD refers to the entry directory

RZ refers to the file import, which is the browse general in Windows, and then upload

Service Tomcat start this time, when our project's war upload succeeded, we started to start services, and then wait for service to open

There is an optimization here, because we use 6002 ports in our program, so if the service is open and the port is not up, which is the listen state, Netstat-an This command is used to view all the port information in the current system. These port 6002 ports is the data we need, so we can use Netstat-an|grep::: 6002来 filter! If it doesn't, it shows that there was a problem with Tomcat's service opening and then went back to the process, just one less step to upload the war package.

Well, the script is finished, and we can do it. The/nac/script/tom.sh,ok project can be easily deployed!

At this time the personnel to ask, such a long path, so difficult to find, very trouble! Can not be more optimized, of course, must be able to optimize, here are two ways to optimize:

1, under the root of the. bashrc file to add alias webupdate= '. /nac/script/tom.sh '

2, add the alias webupdate= ' in the/etc/profile. /nac/script/tom.sh '

I've introduced both of these ways, both optimizations are fine, the latter is better and more convenient, because the latter is configured on the system's environment variable, and the former is configured on the root user's environment variable, so the former is only used by root, and the latter can be used by all users. This allows you to easily change the war package deployment using the Webupdate command

Perhaps this time someone will ask, use the command how to say does not exist! Of course, the device does not reboot, the configuration of these resources have to reload it, certainly not used, restart the device on OK, restart the device is too laborious, we can use source for a while, so you can directly use just configure the command, remember source is the source just changed the file!

Finally, we can be very easy and convenient and quick to redeploy our project!

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.