zoukankan      html  css  js  c++  java
  • 在linux写一个shell脚本用maven git自动更新代码并且打包部署

    服务器上必须安装了git maven jdk 并且配置好环境变量

    实际服务器中可能运行着多个Java进程,所以重新部署的时候需要先停止原来的java进程,写一个按照名称杀死进程的脚本

    kill.sh

    1. #!/bin/sh
    2. function PidFind()
    3.  
    4. {
    5.  
    6. PIDCOUNT=`ps -ef | grep $1 | grep -v "grep" | grep -v $0 | awk '{print $2}' | wc -l`;
    7.  
    8. if [ ${PIDCOUNT} -gt 1 ] ; then
    9.  
    10. echo "There are too many process contains name[$1]"
    11.  
    12. elif [ ${PIDCOUNT} -le 0 ] ; then
    13.  
    14. echo "No such process[$1]!"
    15.  
    16. else
    17.  
    18. PID=`ps -ef | grep $1 | grep -v "grep" | grep -v ".sh" | awk '{print $2}'` ;
    19.  
    20. echo "Find the PID of this progress!--- process:$1 PID=[${PID}] ";
    21.  
    22. echo "Kill the process $1 ...";
    23.  
    24. kill -9 ${PID};
    25.  
    26. echo "kill -9 ${PID} $1 done!";
    27.  
    28. fi
    29.  
    30. }
    31.  
    32.  
    33. PidFind $1
    34.  
    35. exit 1

    接着就是写重新部署的脚本

    redeploy.sh

    1. #杀死原来的java进程
    2. ./kill.sh test.jar
    3. #进入代码文件夹,必须有git管理
    4. cd code/test/
    5. #更新代码
    6. git pull
    7. #清理原来的jar包重新打包
    8. mvn clean install -Dmaven.test.skip=true
    9. cd ~
    10. #删除原来的jar包
    11. rm -rf test-web.jar
    12. cp code/test/test-web/target/test-web.jar test-web.jar
    13. #后台运行
    14. nohup java -agentlib:jdwp=transport=dt_socket,address=8100,server=y,suspend=n -jar test-web.jar > /root/logs/test.log &
    15. #监控日志
    16. tail -f /root/logs/flm-material.log

    上述的代码路径 和jar包存放位置根据实际情况修改

  • 相关阅读:
    mysql5大引擎之间的区别和优劣之分
    关于集合
    泛型
    集合2
    easyui 入门讲解
    <input>和<textarea>
    php中echo(),print(),print_r(),var_dump()间的区别
    PHP图形操作之生成图像验证码
    JZ046圆圈中最后剩下的数
    Python3连接MySQL
  • 原文地址:https://www.cnblogs.com/zhuyeshen/p/11599144.html
Copyright © 2011-2022 走看看