|
| 1 | +#!/bin/bash |
| 2 | +# 项目自动更新脚本 |
| 3 | +# 先clone相应的分支下来: |
| 4 | +# git clone ssh://[email protected]:7999/xxx.git |
| 5 | +# 远程调试启动: |
| 6 | +# nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Xms512m -Xmx1024m -jar -Dspring.profiles.active=${profile} ${jarfile} >/dev/null 2>&1 & |
| 7 | + |
| 8 | +function start { |
| 9 | + profile="$1" |
| 10 | + echo "启动环境profile=${profile}" |
| 11 | + jarfile=$(ls target/*.jar) |
| 12 | + if [[ "$?" == "0" ]]; then |
| 13 | + stop $profile $jarfile |
| 14 | + fi |
| 15 | + branch=$(git branch |awk '{print $2}') |
| 16 | + git pull origin ${branch} |
| 17 | + echo "更新完代码开始重新打包" |
| 18 | + mvn clean && mvn clean && mvn package -DskipTests=true |
| 19 | + if [[ "$?" != "0" ]]; then |
| 20 | + echo "编译出错,退出!" |
| 21 | + exit 1 |
| 22 | + fi |
| 23 | + echo "nohup java -Xms512m -Xmx1024m -jar -Dspring.profiles.active=${profile} ${jarfile} >/dev/null 2>&1 &" |
| 24 | + nohup java -Xms512m -Xmx1024m -jar -Dspring.profiles.active=${profile} ${jarfile} >/dev/null 2>&1 & |
| 25 | + echo "启动应用中,请查看日志文件..." |
| 26 | +} |
| 27 | + |
| 28 | +function stop { |
| 29 | + profile="$1" |
| 30 | + jarfile="$2" |
| 31 | + ps aux | grep "${jarfile}" | grep "spring.profiles.active=${profile}" | grep -v grep > /dev/null |
| 32 | + if [[ "$?" == "0" ]]; then |
| 33 | + echo "该应用还在跑,我先停了它" |
| 34 | + pid=$(ps aux | grep "${jarfile}" | grep "spring.profiles.active=${profile}" | grep -v grep |awk '{print $2}') |
| 35 | + if [[ "$pid" != "" ]]; then |
| 36 | + kill -9 $pid |
| 37 | + fi |
| 38 | + echo "停止应用成功..." |
| 39 | + fi |
| 40 | +} |
| 41 | + |
| 42 | +if [[ "$1" == "start" ]]; then |
| 43 | + if [[ "$#" < 2 ]]; then |
| 44 | + echo "请输入正确参数:./epay.sh start {profile}" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + profile="$2" |
| 48 | + if [[ "$profile" != "dev" && "$profile" != "test" && "$profile" != "show" && "$profile" != "production" ]]; then |
| 49 | + echo "参数错误,请输入正确的profile参数,使用方法:" |
| 50 | + echo "./epay.sh start {profile} ==> 启动应用,{profile}取值:dev|test|show|production" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + start "${profile}" |
| 54 | +elif [[ "$1" == "stop" ]]; then |
| 55 | + if [[ "$#" < 2 ]]; then |
| 56 | + echo "请输入正确参数:./epay.sh stop {profile}" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + profile="$2" |
| 60 | + if [[ "$profile" != "dev" && "$profile" != "test" && "$profile" != "show" && "$profile" != "production" ]]; then |
| 61 | + echo "参数错误,请输入正确的profile参数,使用方法:" |
| 62 | + echo "./epay.sh stop {profile} ==> 停止应用,{profile}取值:dev|test|show|production" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + jarfile=$(ls target/*.jar) |
| 66 | + stop $profile $jarfile |
| 67 | +else |
| 68 | + echo "参数错误,使用方法:{}参数是必填的,[]参数可选" |
| 69 | + echo "./epay.sh start {profile} ==> 启动应用,{profile}取值:dev|test|show|production" |
| 70 | + echo "./epay.sh stop {profile} ==> 停止应用,{profile}取值:dev|test|show|production" |
| 71 | + exit 1 |
| 72 | +fi |
0 commit comments