服务器上必须安装了git maven jdk 并且配置好环境变量
实际服务器中可能运行着多个Java进程,所以重新部署的时候需要先停止原来的java进程,写一个按照名称杀死进程的脚本
kill.sh
-
- function PidFind()
- {
- PIDCOUNT=`ps -ef | grep $1 | grep -v "grep" | grep -v $0 | awk '{print $2}' | wc -l`;
- if [ ${PIDCOUNT} -gt 1 ] ; then
- echo "There are too many process contains name[$1]"
- elif [ ${PIDCOUNT} -le 0 ] ; then
- echo "No such process[$1]!"
- else
- PID=`ps -ef | grep $1 | grep -v "grep" | grep -v ".sh" | awk '{print $2}'` ;
- echo "Find the PID of this progress!--- process:$1 PID=[${PID}] ";
- echo "Kill the process $1 ...";
- kill -9 ${PID};
- echo "kill -9 ${PID} $1 done!";
- fi
- }
- PidFind $1
- exit 1
接着就是写重新部署的脚本
redeploy.sh
- #杀死原来的java进程
- ./kill.sh test.jar
- #进入代码文件夹,必须有git管理
- cd code/test/
- #更新代码
- git pull
- #清理原来的jar包重新打包
- mvn clean install -Dmaven.test.skip=true
- cd ~
- #删除原来的jar包
- rm -rf test-web.jar
- cp code/test/test-web/target/test-web.jar test-web.jar
- #后台运行
- nohup java -agentlib:jdwp=transport=dt_socket,address=8100,server=y,suspend=n -jar test-web.jar > /root/logs/test.log &
- #监控日志
- tail -f /root/logs/flm-material.log
上述的代码路径 和jar包存放位置根据实际情况修改
来源:博客园
作者:那些年的代码
链接:https://www.cnblogs.com/zhuyeshen/p/11599144.html