SpringBoot项⽬从Git拉取代码并完成编译打包启动的sh⾃动脚
操作步骤:
1.进⼊/home/servers/codes/xxxx-dev/⽬录,从git上将项⽬clone下来;
2.确保/usr/local/xxx/xxxx-dev⽬录存在;
3.确保sh脚本有可执⾏权限;
4.执⾏"sh xxx.sh"命令启动脚本;
#!/bin/bash
#jdk环境变量
export JAVA_HOME=/usr/java/jdk1.8.0_211-amd64
export JAVA_BIN=$JAVA_HOME/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
date=`date +%Y%m%d%H%M%S`
CODE_PATH=/home/servers/codes/xxxx-dev/
APP_NAME=xxxx-dev.jar
echo"开始拉取最新代码"
#⾸先进⾏编译
cd ${CODE_PATH}
git pull origin dev
echo"开始编译"
mvn clean install -st.skip=true -P test
cd target/
#执⾏复制
mv xxxx-0.0.1-SNAPSHOT.jar ${APP_NAME}
cp -r ${APP_NAME} /usr/local/xxx/xxxx-dev
echo"开始进⾏复制"
logline=`cat /usr/local/xxx/xxxx-dev/console.log | wc -l`
#检查程序是否在运⾏
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk'{print $2}' `
#如果不存在返回1,存在返回0
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
else
echo"${APP_NAME} is not running"
fi
cd /usr/local/xxx/xxxx-dev
is_exist
springboot原理视频if [ $? -eq "0" ]; then
echo"${APP_NAME} is already running. pid=${pid} ."
else
nohup java -jar ${APP_NAME} >/usr/local/xxx/xxxx-dev/console.log 2>&1 &
echo"程序已启动..."
sleep1;
tail -10f /usr/local/xxx/xxxx-dev/console.log | sed'/Starting Quartz Scheduler now/Q'
cat /usr/local/xxx/xxxx-dev/console.log | sed -n ''"$logline"',${/Starting Quartz Scheduler now/, +3p}'
fi
is_exist
if [ $? -eq "0" ]; then
echo"${APP_NAME} is running. pid is ${pid} "
else
echo"${APP_NAME} is not running."
fi
exit

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。