在自动部署springboot项目中,一直无法后台运行
在执行脚本上加入
export BUILD_ID=dontKillMe
大体了解原因:Jenkins在构建结束后会把额外启动的进程杀死。
完整shell脚本
#!/bin/bash
export BUILD_ID=dontKillMe
echo "复制文件"
cp ${WORKSPACE}/engineer-fix-employee/target/engineer-fix-employee-0.0.1-SNAPSHOT.jar /opt/engineer-cloud-fix/fix-employee/engineer-fix-employee-0.0.1-SNAPSHOT.jar
cd /opt/engineer-cloud-fix/fix-employee/
ls_date=`date "+%Y-%m-%d"`
path="/opt/engineer-cloud-fix/fix-employee/"
jar="engineer-fix-employee-0.0.1-SNAPSHOT.jar"
pidlist=`ps -ef |grep ${jar} |grep -v "grep"|awk '{print $2}'`
echo $pidlist
if [ $pidlist ]
then
kill -9 $pidlist
echo ${ls_date}":kill "${pidlist}
fi
echo "start "${jar}
nohup /home/soft/jdk-11.0.8/bin/java -jar -Duser.timezone=GMT+08 engineer-fix-employee-0.0.1-SNAPSHOT.jar --server.port=9709 >log.log 2>&1 &