Write the automatic pulling in the idea, shell scripting, project start springboot

idea development environment to build

idea installed in the shell develop plug-ins

Server with conditions

  1. Already installed lsof (used to check port occupancy)
  2. git is installed
  3. Installation maven
  4. There are java environment

background

After the code into the repository, you need to redeploy springboot code on the server, each playing their own jar package uploaded to the server step too cumbersome, consider to use commands in the script

Pulling specified initialization code branches

blog_int.sh

#!/usr/bin/env bash

cd /data/code/
git clone -b V3.0.0 [email protected]:daleyzou/blog.git

Deploy code

deplog.sh

#!/usr/bin/env bash

cd /data/code/blog
echo '自动部署Springboot项目脚本...'
echo '1. 拉取代码...'
git pull
echo '2. 检查8000端口是否被占用...'
pid_blog=`lsof -i :8000|grep -v "PID"|awk '{print $2}'`
if [ "$pid_blog" != "" ];
then
    echo '8000端口被占用'
    echo $pid_blog
    kill -9 "$pid_blog"
    echo $pid_blog '进程已被杀死'
else
    echo "端口未被占用"
fi
echo '3. 删除已有jar包...'
if [ ! -f "/data/jarDir/blog-1.0.1-SNAPSHOT.jar" ];then
echo "文件不存在"
else
rm -f /data/jarDir/blog-1.0.1-SNAPSHOT.jar
fi
echo '4. 清理原有项目...'
/data/usr/local/apache-maven/bin/mvn clean
echo '5. 打包...'
/data/usr/local/apache-maven/bin/mvn clean package -Dmaven.test.skip=true
echo '6. 将打包后的 jar 文件移动到指定目录...'
mv /data/code/blog/target/blog-1.0.1-SNAPSHOT.jar /data/jarDir
echo '7. 后台运行jar包...'
nohup java -jar /data/jarDir/blog-1.0.1-SNAPSHOT.jar > /data/jarDir/log.out 2>&1 &
以后当代码提交到仓库后,直接执行 deploy.sh 就可以完成代码的重新拉取、编译、启动操作

Guess you like

Origin www.cnblogs.com/daleyzou/p/springbootAutoDeploy.html