From c3100442972a78521eae4e2e2e50d35bbdaa5d33 Mon Sep 17 00:00:00 2001 From: lizw Date: Mon, 14 Mar 2022 15:04:32 +0800 Subject: [PATCH] add yxt-cq/deploy-lims-report.sh --- yxt-cq/deploy-lims-report.sh | 128 +++++++++++++++++++++++++++++++++++++++++++ yxt-cq/deploy-lims.sh | 2 +- 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 yxt-cq/deploy-lims-report.sh diff --git a/yxt-cq/deploy-lims-report.sh b/yxt-cq/deploy-lims-report.sh new file mode 100644 index 0000000..0ec6aef --- /dev/null +++ b/yxt-cq/deploy-lims-report.sh @@ -0,0 +1,128 @@ +#!/bin/bash +#time=`date +%Y-%m-%d.%H-%M` +#set -x +set -e + +gitUrl=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_report_cq.git +dirPath=~/deploy/yxt_lmis_report_cq +serverName=yxt_cq_report +logPath=~/logs/yxt_lmis_report_cq_nohup.log + +cmd=$1 +profiles=${2:-"yxt-cq-prod"} +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +#------------------------------------------------------------------- +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g" +DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false" +JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai" +#------------------------------------------------------------------- + +isChange="1" # 仓库是否发生变化,0未:变化;非0:变化 +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"master"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix mkdir -p $path $echoSuffix" + mkdir -p $path + fi + + # git clone + echo -e "$echoPrefix cd $path $echoSuffix" + cd $path + if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then + echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix" + git clone $gitUrl $position + isChange="2" + fi + + # 进入文件夹,切换分支,git pull + if [ "$position" != "" ]; then + echo -e "$echoPrefix cd $position $echoSuffix" + cd $position + fi + echo -e "$echoPrefix git checkout $branch $echoSuffix" + git checkout $branch + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == 1 ]; then + isChange="0" + fi + echo "" +} + +startServer() { + pid=$1 + if [ -z $pid ];then + echo -e "$echoPrefix cd $dirPath $echoSuffix" + cd $dirPath + echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./app-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8186 >$logPath 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./app-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8186 >$logPath 2>&1 & + echo "$serverName 启动成功!" + else + echo "$serverName 正在运行..." + fi + echo "查看日志: tail -F $logPath -n 100" +} + +stopServer() { + pid=$1 + if [ -z $pid ];then + echo "$serverName 未运行" + else + echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix" + ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill + echo "$serverName 已停止!" + fi +} + +deployPull() { + pid=$1 + if [ -z $pid ];then + pullCode $dirPath $gitUrl "master" "." + else + echo "$serverName 正在运行,必须先stop,再pull" + fi +} + +deployServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + deployPull + startServer +} + +logs() { + tail -F $logPath -n 100 +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: pull deploy start stop kill log logs +if [ "$cmd" == "pull" ];then + deployPull $pid +elif [ "$cmd" == "deploy" ];then + deployServer $pid +elif [ "$cmd" == "start" ];then + startServer $pid +elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then + stopServer $pid +elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then + logs +else + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: pull deploy start stop kill log logs" + else + echo "输入操作参数: pull deploy start stop kill log logs" + echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100" + fi +fi + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt-cq/deploy-lims-report.sh) [cmd profiles] diff --git a/yxt-cq/deploy-lims.sh b/yxt-cq/deploy-lims.sh index 0562d85..82c329e 100644 --- a/yxt-cq/deploy-lims.sh +++ b/yxt-cq/deploy-lims.sh @@ -5,7 +5,7 @@ set -e gitUrl=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_cq.git dirPath=~/deploy/yxt_lmis_cq -serverName=yxt_lmis_cq +serverName=yxt_cq_lmis logPath=~/logs/yxt_lmis_cq_nohup.log cmd=$1