Browse Source

Merge remote-tracking branch 'origin/master'

master
lizw 3 years ago
parent
commit
d5ebb500cb
  1. 1
      .gitignore
  2. 30
      00base/01yvan-ext.groovy
  3. 30
      00base/02yvan-ext-mobile.groovy
  4. 154
      00base/07env-install-centos.sh
  5. 232
      01dongying_guokang/06wms8-test2.sh
  6. 81
      05shengke/03xxljob-prod.sh
  7. 35
      05shengke/03xxljob.groovy
  8. 33
      05shengke/04wms83-prod.groovy
  9. 229
      05shengke/04wms83-prod.sh
  10. 33
      05shengke/05api-prod.groovy
  11. 174
      05shengke/05api-prod.sh

1
.gitignore

@ -70,3 +70,4 @@ target
pom.xml.versionsBackup pom.xml.versionsBackup
build/ build/
node_modules node_modules
lib

30
00base/01yvan-ext.groovy

@ -0,0 +1,30 @@
//file:noinspection ALL
pipeline {
agent any
environment {
projectName = 'yvan-ext'
}
stages {
stage('#检查环境') {
steps {
sh """
node -v
npm -v
yarn -v
"""
}
}
stage('#编译项目') {
steps {
sh """
wget -N http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/01yvan-ext.sh
chmod +x 01yvan-ext.sh
./01yvan-ext.sh deploy
"""
}
}
}
}

30
00base/02yvan-ext-mobile.groovy

@ -0,0 +1,30 @@
//file:noinspection ALL
pipeline {
agent any
environment {
projectName = 'yvan-ext-mobile'
}
stages {
stage('#检查环境') {
steps {
sh """
node -v
npm -v
yarn -v
"""
}
}
stage('#编译项目') {
steps {
sh """
wget -N http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh
chmod +x 02yvan-ext-mobile.sh
./02yvan-ext-mobile.sh deploy
"""
}
}
}
}

154
00base/07env-install-centos.sh

@ -41,6 +41,10 @@ JENKINS_FILE_NAME="jenkins.war"
JENKINS_JAVA_URL="https://d6.injdk.cn/oraclejdk/11/jdk-11.0.16.1_linux-x64_bin.tar.gz" JENKINS_JAVA_URL="https://d6.injdk.cn/oraclejdk/11/jdk-11.0.16.1_linux-x64_bin.tar.gz"
JENKINS_JAVA_FILE_NAME="jdk-11.0.16.1_linux-x64_bin.tar.gz" JENKINS_JAVA_FILE_NAME="jdk-11.0.16.1_linux-x64_bin.tar.gz"
JENKINS_JAVA_DIR_NAME="jdk-11.0.16.1" JENKINS_JAVA_DIR_NAME="jdk-11.0.16.1"
#--- redis Latest Stable
REDIS_URL="https://download.redis.io/redis-stable.tar.gz"
REDIS_FILE_NAME="redis-stable.tar.gz"
REDIS_DIR_NAME="redis-stable"
# 安装标识 # 安装标识
#--- SSH用户 #--- SSH用户
@ -68,6 +72,7 @@ JAVA_TAG="1"
GRADLE_TAG="1" GRADLE_TAG="1"
MAVEN_TAG="1" MAVEN_TAG="1"
JENKINS_TAG="1" JENKINS_TAG="1"
REDIS_TAG="1"
# 脚本设置 # 脚本设置
TMP_DIR="$(rm -rf /tmp/env-install* && mktemp -d -t env-install.XXXXXXXXXX)" TMP_DIR="$(rm -rf /tmp/env-install* && mktemp -d -t env-install.XXXXXXXXXX)"
@ -550,6 +555,147 @@ EOF
log::info "[jenkins]" "停止jenkins: ${BASE_DIR}/jenkins/kill.sh" log::info "[jenkins]" "停止jenkins: ${BASE_DIR}/jenkins/kill.sh"
} }
# 安装redis环境
function init:redis() {
log::info "[redis]" "安装redis环境..."
local host="127.0.0.1"
local redis_path="${BASE_DIR}/redis/${REDIS_DIR_NAME}"
local redis_install_path="${BASE_DIR}/redis/${REDIS_DIR_NAME}-install"
command::exec "${host}" "
if [ ! -d "$redis_path" ]; then
mkdir -p ${BASE_DIR}/redis
wget --timeout=10 --waitretry=3 --tries=5 --retry-connrefused --no-check-certificate ${REDIS_URL} -O ${BASE_DIR}/redis/${REDIS_FILE_NAME}
cd ${BASE_DIR}/redis
tar -zxvf ${REDIS_FILE_NAME}
cd $redis_path
yum -y install gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
echo 'source /opt/rh/devtoolset-9/enable' >> /etc/profile
source /etc/profile
gcc -v
mkdir -p $redis_install_path
cd $redis_path
make install PREFIX=$redis_install_path
# 写文件start.sh文件
cat << EOF > $redis_install_path/redis.conf
# bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 300
tcp-keepalive 300
daemonize yes
supervised auto
pidfile $redis_install_path/redis.pid
loglevel notice
logfile $redis_install_path/redis.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir $redis_install_path/
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
requirepass admin123456
# 限制内存4GB = 4294967296 bytes
maxmemory 4294967296
maxmemory-policy allkeys-lfu
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
oom-score-adj no
oom-score-adj-values 0 200 800
appendonly no
appendfilename \"appendonly.aof\"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events \"\"
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
EOF
cat << EOF > $redis_install_path/start.sh
#!/bin/bash
#set -x
set -e
pid=\\\`ps -ef | grep '$redis_install_path/bin/redis-server' | grep -v 'grep' | awk '{print \\\$2}'\\\`
cd $redis_install_path
if [ -z \\\$pid ];then
$redis_install_path/bin/redis-server $redis_install_path/redis.conf
echo 'redis启动成功!'
else
echo 'redis正在运行...'
fi
echo '查看日志: tail -F $redis_install_path/redis.log -n 100'
EOF
# 写文件kill.sh文件
cat << EOF > $redis_install_path/kill.sh
#!/bin/bash
#set -x
set -e
pid=\\\`ps -ef | grep '$redis_install_path/bin/redis-server' | grep -v 'grep' | awk '{print \\\$2}'\\\`
if [ -z \\\$pid ];then
echo 'redis未运行'
else
ps -ef | grep '$redis_install_path/bin/redis-server' | grep -v 'grep' | awk '{print \\\$2}' | xargs kill
echo 'redis已停止!'
fi
EOF
chmod +x $redis_install_path/start.sh
chmod +x $redis_install_path/kill.sh
fi
"
check::exit_code "$?" "redis" "$host 安装redis环境" "exit"
if [[ "${ADD_USER_TAG:-}" == "1" ]]; then
command::exec "${host}" "
sudo chown -R \$(id -u ${ADD_USER_NAME}):\$(id -g ${ADD_USER_NAME}) ${BASE_DIR}/redis
"
fi
log::info "[redis]" "redis环境安装成功!"
log::info "[redis]" "启动redis: $redis_install_path/start.sh"
log::info "[redis]" "停止redis: $redis_install_path/kill.sh"
}
###################################################################################################### ######################################################################################################
# 主调用逻辑 # 主调用逻辑
###################################################################################################### ######################################################################################################
@ -578,6 +724,7 @@ Flag:
-gradle 是否安装gradle环境, 默认: '1' -gradle 是否安装gradle环境, 默认: '1'
-maven 是否安装maven环境, 默认: '1' -maven 是否安装maven环境, 默认: '1'
-jenkins 是否安装jenkins环境, 默认: '1' -jenkins 是否安装jenkins环境, 默认: '1'
-redis 是否安装redis环境, 默认: '1'
Example: Example:
env-install-centos.sh init \\ env-install-centos.sh init \\
@ -593,7 +740,8 @@ Example:
-java 1 \\ -java 1 \\
-gradle 0 \\ -gradle 0 \\
-maven 0 \\ -maven 0 \\
-jenkins 0 -jenkins 0 \\
-redis 0
EOF EOF
exit 1 exit 1
@ -649,6 +797,9 @@ while [ "${1:-}" != "" ]; do
-jenkins ) shift -jenkins ) shift
JENKINS_TAG=${1:-JENKINS_TAG} JENKINS_TAG=${1:-JENKINS_TAG}
;; ;;
-redis ) shift
REDIS_TAG=${1:-REDIS_TAG}
;;
* ) help::usage * ) help::usage
exit 1 exit 1
esac esac
@ -672,6 +823,7 @@ if [[ "${INIT_TAG:-}" == "1" ]]; then
[[ "${GRADLE_TAG:-}" == "1" ]] && { init:gradle; } [[ "${GRADLE_TAG:-}" == "1" ]] && { init:gradle; }
[[ "${MAVEN_TAG:-}" == "1" ]] && { init:maven; } [[ "${MAVEN_TAG:-}" == "1" ]] && { init:maven; }
[[ "${JENKINS_TAG:-}" == "1" ]] && { init:jenkins; } [[ "${JENKINS_TAG:-}" == "1" ]] && { init:jenkins; }
[[ "${REDIS_TAG:-}" == "1" ]] && { init:redis; }
else else
help::usage help::usage
fi fi

232
01dongying_guokang/06wms8-test2.sh

@ -0,0 +1,232 @@
#!/bin/bash
#set -x
set -e
codePath=/home/www/deploy/wms8_dygk
gitUrlArr=(
"http://git.galaxis.yvanui.com/wms8/wms8-bench.git"
"http://git.galaxis.yvanui.com/wms8/wms-core.git"
"http://git.yvanui.com/lizhiwei/yvan-framework.git"
)
branchArr=(
"dongying_guokang"
"dongying_guokang"
"master"
)
positionArr=(
"."
"wms-core"
"yvan-framework"
)
# 是否需要构建,-1:自动;0:不需要;1:需要
needBuild=(
"1"
"1"
"1"
)
echoPrefix="\033[36m+"
echoSuffix="\033[0m"
# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master
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"
exit
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 checkout . $echoSuffix"
git checkout .
echo -e "$echoPrefix git pull $echoSuffix"
if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
isChange="0"
fi
echo ""
}
buildCode() {
# 构建 wms-biz/bundle
if [ "${needBuild[0]}" != "0" ]; then
echo -e "$echoPrefix cd $codePath/wms-biz/bundle $echoSuffix"
cd "$codePath/wms-biz/bundle"
echo -e "$echoPrefix yarn $echoSuffix"
yarn
echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
yarn link yvan-ext
echo -e "$echoPrefix yarn build $echoSuffix"
yarn build
echo ""
else
echo "wms-biz/bundle 文件未变化"
fi
# 构建 wms-biz/pda-client
if [ "${needBuild[0]}" != "0" ]; then
echo -e "$echoPrefix cd $codePath/wms-biz/pda-client $echoSuffix"
cd "$codePath/wms-biz/pda-client"
echo -e "$echoPrefix yarn $echoSuffix"
yarn
echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix"
yarn link yvan-ext-mobile
echo -e "$echoPrefix yarn build $echoSuffix"
yarn build
echo ""
else
echo "wms-biz/pda-client 文件未变化"
fi
# 构建 java
echo -e "$echoPrefix cd $codePath $echoSuffix"
cd $codePath
echo -e "$echoPrefix gradle build -x test $echoSuffix"
gradle build -x test
echo ""
}
logPath=/data/logs/wms8_dygk/wms8_dygk.log
dirPath=/home/www/deploy/wms8_dygk/wms-biz/servo/build/libs/
serverName=wms8_dygk
cmd=$1
profiles=${2:-"test2"}
#-------------------------------------------------------------------
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"
#-------------------------------------------------------------------
startServer() {
pid=$1
if [ -z $pid ];then
echo -e "$echoPrefix cd $dirPath../runtime/ $echoSuffix"
cd $dirPath../runtime/
echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8096 >>/dev/null 2>&1 & $echoSuffix"
java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8096 >>/dev/null 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() {
for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
if [ "${needBuild[idx]}" == "-1" ]; then
needBuild[idx]=$isChange
fi
done
# 设置 require_config.js 前端版本
version=$(date +_%Y_%m_%d_%H_%M_%S)
echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $codePath/public/require_config.js $echoSuffix"
sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $codePath/public/require_config.js
echo "###--代码更新完成--------------------------------------------------------------------------###"
echo ""
}
deployServer() {
pid=$1
deployPull
buildCode
echo "###--代码构建完成--------------------------------------------------------------------------###"
# 重启服务
if [ ! -z $pid ];then
stopServer $pid
sleep 3s
fi
# 移动编译后的文件
echo -e "$echoPrefix cd $dirPath $echoSuffix"
cd $dirPath
echo -e "$echoPrefix rm -rf ../runtime $echoSuffix"
rm -rf ../runtime
echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix"
cp -r ./ ../runtime
echo ""
startServer
}
restartServer() {
pid=$1
if [ ! -z $pid ];then
stopServer $pid
sleep 3s
fi
startServer
}
logs() {
tail -F $logPath -n 100
}
deployYvanUI() {
bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull
bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull
}
pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
# 操作参数: pull deploy restart start stop kill log logs
if [ "$cmd" == "pull" ];then
deployYvanUI
deployPull
if [ -z $pid ];then
echo "$serverName 未运行 | 输入操作参数: pull deploy restart start stop kill log logs"
fi
elif [ "$cmd" == "deploy" ];then
deployYvanUI
deployServer $pid
elif [ "$cmd" == "restart" ];then
restartServer $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 restart start stop kill log logs"
else
echo "输入操作参数: pull deploy restart 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/01dongying_guokang/06wms8-test2.sh) [cmd profiles]

81
05shengke/03xxljob-prod.sh

@ -0,0 +1,81 @@
#!/bin/bash
#set -x
set -e
echoPrefix="\033[36m+"
echoSuffix="\033[0m"
logPath=/data/logs/xxl-job/xxl-job.log
dirPath=/home/www/deploy/xxl-job/
serverName=xxl_job_prod
cmd=$1
profiles=${2:-"shengke-prod"}
#-------------------------------------------------------------------
JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx1g -Xms1g"
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"
#-------------------------------------------------------------------
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 bin/xxl-job-admin-postgres-2.3.0.jar --spring.config.location=conf/ --spring.profiles.active=global,$profiles --server.port=8000 >>/dev/null 2>&1 & $echoSuffix"
java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar bin/xxl-job-admin-postgres-2.3.0.jar --spring.config.location=conf/ --spring.profiles.active=global,$profiles --server.port=8000 >>/dev/null 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
}
restartServer() {
pid=$1
if [ ! -z $pid ];then
stopServer $pid
sleep 3s
fi
startServer
}
logs() {
tail -F $logPath -n 100
}
pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
# 操作参数: deploy restart start stop kill log logs
if [ "$cmd" == "deploy" ];then
bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/03xxljob.sh) pull
restartServer $pid
elif [ "$cmd" == "restart" ];then
restartServer $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 未运行 | 输入操作参数: deploy restart start stop kill log logs"
else
echo "输入操作参数: deploy restart 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/05shengke/03xxljob-prod.sh) [cmd profiles]

35
05shengke/03xxljob.groovy

@ -0,0 +1,35 @@
//file:noinspection ALL
pipeline {
agent any
environment {
projectName = 'xxl-job'
}
stages {
stage('#检查环境') {
steps {
sh """
java -version
"""
}
}
stage('#编译项目') {
steps {
sh """
wget -N http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/03xxljob.sh
chmod +x 03xxljob.sh
wget -N http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/05shengke/03xxljob-prod.sh
chmod +x 03xxljob-prod.sh
./03xxljob-prod.sh stop
./03xxljob.sh pull
"""
sh """
sleep 3s
JENKINS_NODE_COOKIE=dontKillMe nohup ./03xxljob-prod.sh start > /dev/null 2>&1 &
"""
}
}
}
}

33
05shengke/04wms83-prod.groovy

@ -0,0 +1,33 @@
//file:noinspection ALL
pipeline {
agent any
environment {
projectName = 'wms8'
}
stages {
stage('#检查环境') {
steps {
sh """
java -version
gradle -v
"""
}
}
stage('#编译项目') {
steps {
sh """
wget -N http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/05shengke/04wms83-prod.sh
chmod +x ./04wms83-prod.sh
./04wms83-prod.sh deploy
"""
sh """
sleep 3s
JENKINS_NODE_COOKIE=dontKillMe nohup ./04wms83-prod.sh restart > /dev/null 2>&1 &
"""
}
}
}
}

229
05shengke/04wms83-prod.sh

@ -0,0 +1,229 @@
#!/bin/bash
#set -x
set -e
codePath=/home/www/deploy/wms8_shengke
gitUrlArr=(
"http://git.galaxis.yvanui.com/wms8/wms83.git"
"http://git.yvanui.com/lizhiwei/yvan-framework.git"
)
branchArr=(
"master"
"8.3"
)
positionArr=(
"."
"yvan-framework"
)
# 是否需要构建,-1:自动;0:不需要;1:需要
needBuild=(
"1"
"1"
)
echoPrefix="\033[36m+"
echoSuffix="\033[0m"
# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master
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"
exit
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 checkout . $echoSuffix"
git checkout .
echo -e "$echoPrefix git pull $echoSuffix"
if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
isChange="0"
fi
echo ""
}
buildCode() {
# 构建 wms-biz/bundle
if [ "${needBuild[0]}" != "0" ]; then
echo -e "$echoPrefix cd $codePath/wms-biz/bundle $echoSuffix"
cd "$codePath/wms-biz/bundle"
echo -e "$echoPrefix yarn $echoSuffix"
yarn
echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
yarn link yvan-ext
echo -e "$echoPrefix yarn build $echoSuffix"
yarn build
echo ""
else
echo "wms-biz/bundle 文件未变化"
fi
# 构建 wms-biz/pda-client
if [ "${needBuild[0]}" != "0" ]; then
echo -e "$echoPrefix cd $codePath/wms-biz/pda-client $echoSuffix"
cd "$codePath/wms-biz/pda-client"
echo -e "$echoPrefix yarn $echoSuffix"
yarn
echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix"
yarn link yvan-ext-mobile
echo -e "$echoPrefix yarn build $echoSuffix"
yarn build
echo ""
else
echo "wms-biz/pda-client 文件未变化"
fi
# 构建 java
echo -e "$echoPrefix cd $codePath $echoSuffix"
cd $codePath
echo -e "$echoPrefix gradle build -x test $echoSuffix"
gradle build -x test
echo ""
}
logPath=/data/logs/wms8_shengke/wms8_shengke.log
dirPath=/home/www/deploy/wms8_shengke/wms-biz/servo/build/libs/
serverName=wms8_shengke
cmd=$1
profiles=${2:-"prod"}
#-------------------------------------------------------------------
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"
#-------------------------------------------------------------------
startServer() {
pid=$1
if [ -z $pid ];then
echo -e "$echoPrefix cd $dirPath../runtime/ $echoSuffix"
cd $dirPath../runtime/
echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8101 >>/dev/null 2>&1 & $echoSuffix"
java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8101 >>/dev/null 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() {
for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
if [ "${needBuild[idx]}" == "-1" ]; then
needBuild[idx]=$isChange
fi
done
# 设置 require_config.js 前端版本
version=$(date +_%Y_%m_%d_%H_%M_%S)
echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $codePath/public/require_config.js $echoSuffix"
sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $codePath/public/require_config.js
echo "###--代码更新完成--------------------------------------------------------------------------###"
echo ""
}
deployServer() {
pid=$1
deployPull
buildCode
echo "###--代码构建完成--------------------------------------------------------------------------###"
# 重启服务
if [ ! -z $pid ];then
stopServer $pid
sleep 3s
fi
# 移动编译后的文件
echo -e "$echoPrefix cd $dirPath $echoSuffix"
cd $dirPath
echo -e "$echoPrefix rm -rf ../runtime $echoSuffix"
rm -rf ../runtime
echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix"
cp -r ./ ../runtime
echo ""
startServer
}
restartServer() {
pid=$1
if [ ! -z $pid ];then
stopServer $pid
sleep 3s
fi
startServer
}
logs() {
tail -F $logPath -n 100
}
deployYvanUI() {
bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull
bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull
}
pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
# 操作参数: pull deploy restart start stop kill log logs
if [ "$cmd" == "pull" ];then
deployYvanUI
deployPull
if [ -z $pid ];then
echo "$serverName 未运行 | 输入操作参数: pull deploy restart start stop kill log logs"
fi
elif [ "$cmd" == "deploy" ];then
deployYvanUI
deployServer $pid
elif [ "$cmd" == "restart" ];then
restartServer $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 restart start stop kill log logs"
else
echo "输入操作参数: pull deploy restart 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/05shengke/04wms83-prod.sh) [cmd profiles]

33
05shengke/05api-prod.groovy

@ -0,0 +1,33 @@
//file:noinspection ALL
pipeline {
agent any
environment {
projectName = 'wms8-api'
}
stages {
stage('#检查环境') {
steps {
sh """
java -version
gradle -v
"""
}
}
stage('#编译项目') {
steps {
sh """
wget -N http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/05shengke/05api-prod.sh
chmod +x ./05api-prod.sh
./05api-prod.sh deploy
"""
sh """
sleep 3s
JENKINS_NODE_COOKIE=dontKillMe nohup ./05api-prod.sh restart > /dev/null 2>&1 &
"""
}
}
}
}

174
05shengke/05api-prod.sh

@ -0,0 +1,174 @@
#!/bin/bash
#set -x
set -e
codePath=/home/www/deploy/wms8_api_shengke
gitUrlArr=(
"http://git.galaxis.yvanui.com/wms8/wms83.git"
"http://git.yvanui.com/lizhiwei/yvan-framework.git"
)
branchArr=(
"master"
"8.3"
)
positionArr=(
"."
"yvan-framework"
)
# 是否需要构建,-1:自动;0:不需要;1:需要
needBuild=(
"1"
"1"
)
echoPrefix="\033[36m+"
echoSuffix="\033[0m"
# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master
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"
exit
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 checkout . $echoSuffix"
git checkout .
echo -e "$echoPrefix git pull $echoSuffix"
if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
isChange="0"
fi
echo ""
}
buildCode() {
# 构建 java
echo -e "$echoPrefix cd $codePath $echoSuffix"
cd $codePath
echo -e "$echoPrefix gradle build -x test $echoSuffix"
gradle build -x test
echo ""
}
logPath=/data/logs/wms8_api_shengke/wms8_api_shengke.log
dirPath=/home/www/deploy/wms8_api_shengke/wms-biz/wms8-api/build/libs/
serverName=wms8_api_shengke
cmd=$1
profiles=${2:-"prod"}
#-------------------------------------------------------------------
JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx1g -Xms1g"
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 -Duser.name=user"
#-------------------------------------------------------------------
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 ./wms8-api-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8094 >>/dev/null 2>&1 & $echoSuffix"
java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./wms8-api-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8094 >>/dev/null 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() {
for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
if [ "${needBuild[idx]}" == "-1" ]; then
needBuild[idx]=$isChange
fi
done
echo "###--代码更新完成--------------------------------------------------------------------------###"
echo ""
}
deployServer() {
pid=$1
if [ ! -z $pid ];then
stopServer $pid
sleep 3s
fi
deployPull
buildCode
echo "###--代码构建完成--------------------------------------------------------------------------###"
echo ""
startServer
}
restartServer() {
pid=$1
if [ ! -z $pid ];then
stopServer $pid
sleep 3s
fi
startServer
}
logs() {
tail -F $logPath -n 100
}
pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
# 操作参数: deploy restart start stop kill log logs
if [ "$cmd" == "deploy" ];then
deployServer $pid
elif [ "$cmd" == "restart" ];then
restartServer $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 未运行 | 输入操作参数: deploy restart start stop kill log logs"
else
echo "输入操作参数: deploy restart start stop kill log logs"
echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100"
fi
fi
# 云南圣科 api
# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/05shengke/05api-prod.sh) [cmd profiles]
Loading…
Cancel
Save