Idea automatically deploys projects to cloud servers

When we carry outserver deploymentdebugging, we need to upload, stop and start again every time, which is cumbersome operation.

In fact, we can quickly deploy and start the project in the idea.

Install plugin

Search for the Alibaba Cloud Tookit plug-in in the idea software store and install it.

Configure in the project

Find Edit Configurations and open it

Select + and select Deploy to Host,

After adding, you can see the following interface

First we give the configuration a name, Name: test
and then select Upload File, select target The following jar package

Deployment device ip, point + , selection Add Host .

Add the host address, configure the SSH port number, and select the verification method to support password mode and private key mode
After configuration, you can test the connection. If the connection is successful, just click Add. .

After configuring the IP, configure the upload server path. Mine is under /home/jar/dev, as shown in the figure.

Then configure the command to be executed after uploading. Here we create a new shell script, as shown below, and place it in the upload directory. File name start.sh

# jar包的文件名,根据自己的进行修改
RESOURCE_NAME=laboratory-0.0.1-SNAPSHOT.jar
 
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
else
echo 'Stop Success!'
fi
 
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'App is running.'
else
    echo 'App is NOT running.'
fi
 
rm -f tpid
nohup java -jar ./$RESOURCE_NAME  & tail -f nohup.out
echo $! > tpid
echo Start Success!

Create new files in the upload directory

Then fill in the command to execute after uploading, select Select Command , select Add Command

Enter ./start.sh Select OK, select the command you just edited, select OK< /span>That’s it

Then we configure and perform operations before uploading. Find Before launch and click +Run Maven Goal
Select 

In the input box that appears, enter clean package and click OK.

At this point, the configuration is basically completed.
Next, you can automatically deploy the project.

Select what we just configured and click Run.

We can see the output bar at the bottom, the output log. If it ends normally, the configuration is successful.

Guess you like

Origin blog.csdn.net/Libra_Oct_13th/article/details/132577852