努力挣扎的生活 努力挣扎的生活
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • 运维基础
  • 监控
  • 日志系统
  • gitlab安装
  • jenkins安装和管理
  • Jenkins工具集成
  • pipeline流水线
  • Docker
  • Kubernetes
  • Nexus
  • Rancher
  • Prometheus
  • ELK(EFK)
  • 虚拟化
  • Mysql
  • PostgreSQL
  • Redis
  • MongoDB
  • clickhouse
关于
  • 分类
  • 标签
  • 归档
  • 收藏
  • 更多
GitHub (opens new window)

yangfk

瑟瑟发抖的小运维
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • 运维基础
  • 监控
  • 日志系统
  • gitlab安装
  • jenkins安装和管理
  • Jenkins工具集成
  • pipeline流水线
  • Docker
  • Kubernetes
  • Nexus
  • Rancher
  • Prometheus
  • ELK(EFK)
  • 虚拟化
  • Mysql
  • PostgreSQL
  • Redis
  • MongoDB
  • clickhouse
关于
  • 分类
  • 标签
  • 归档
  • 收藏
  • 更多
GitHub (opens new window)
  • 运维基础

    • nginx 安装
    • nginx-conf常用示例
    • rsync 服务pull与push
    • linux时间同步
    • 系统参数优化
    • ruby版本升级
    • fpm定制rpm
    • php7_X安装
    • iptables规则
    • tcpdump抓包
    • 公司部署Pritunl-VPN
    • 需求shell脚本记录
      • 检查容器重启脚本
      • php代码更新
      • ping IP把日志重定向到文件带时间戳
      • 初始化磁盘
      • 数据库创建表
        • 创建256张表
        • 创建天表
      • 服务器脚本前端打包,多个工程
      • 从k8s获取包拷贝到测试环境
    • openldap安装配置
    • Ldap集成常用开源服务示例图
    • ansible基础
    • ansible进阶playbook与Roles
    • centos安装python3
    • Firewalld防火墙
    • Linux配置jdk
    • ubuntu安装ftp
    • minio分布式文件存储
    • windows安装openssh
    • centos7安装系统检测不到网卡
    • docker运行一个bind9和常用的网络命令
    • nginx禁用真实IP
  • 监控

  • 日志系统

  • 安全记录

//
  • 运维
  • 运维基础
yangfk
2020-11-15

需求shell脚本记录

//

# 检查容器重启脚本

#!/bin/bash

#服务pid第一次随便填数字,执行脚本会自动替换
prod_mes_service=23175
prod_dispatcher_algorithm_main=29759

#容器名称
Server=(
"prod_mes_service"
"prod_dispatcher_algorithm_main"

)

zoroDate=$(date +%H_%M)

for SerVer in ${Server[@]}
do
if $(docker inspect --format {{.State.Pid}} ${SerVer} >/dev/null);then
    if [ ${zoroDate} == "00_00" ];then  rm -f ${SerVer}.txt
    fi
    Pid=$(eval echo '$'"${SerVer}")
    PidNew=$(docker inspect --format {{.State.Pid}} ${SerVer})
    if [ $(docker inspect --format {{.State.Pid}} ${SerVer}) != ${Pid} ];then
        if [ $(docker inspect --format {{.State.Pid}} ${SerVer}) != 0 ];then
            curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f9c-c3da-415d-8ed5-2d66191b3c' \
            -H 'Content-Type: application/json' \
            -d '
            {
                 "msgtype": "text",
                 "text": {
                     "content": "'"生产环境: 句容 \n\n 容器服务重启了,容器名称:${SerVer}"'"
                 }
            }'
	    sed -i "s#^${SerVer}=.*#${SerVer}=${PidNew}#" $0
        else
             test -f ${SerVer}.txt || > ${SerVer}.txt
             if [ $(wc -l ${SerVer}.txt|awk '{print $1}') -le 3 ];then
                curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f9c-c3da-415d-8ed5-2d66191b3c' \
                -H 'Content-Type: application/json' \
                -d '
                {
                     "msgtype": "text",
                     "text": {
                         "content": "'"生产环境: 句容 \n\n  容器名称:${SerVer},已经停止"'"
                     }
                }'
                docker start ${SerVer}
                echo ${SerVer} >> ${SerVer}.txt
              fi
        fi
    fi
else 
        test -f ${SerVer}.txt || > ${SerVer}.txt
        if [ $(wc -l ${SerVer}.txt|awk '{print $1}') -le 2 ];then
            curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f9c-c3da-415d-8ed5-2d6366191b3c' \
            -H 'Content-Type: application/json' \
            -d '
            {
                 "msgtype": "text",
                 "text": {
                     "content": "'" 生产环境: 句容 \n\n 容器不存在,容器名称:${SerVer}"'"
                 }
            }'
            echo ${SerVer} >> ${SerVer}.txt
        fi
fi
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

# php代码更新

  • 发布脚本
#!/bin/bash

#上线到游戏中心服务端代码

script=/opt/bin
DIR=/opt/rsync-online/gamecenteronline/gamecenteronline
DIRtest=/opt/rsync-online/gamecenteronline/promaster
File=/opt/bin/commit/gamecenter-commit.txt
File2=/opt/bin/commit/gamecenter-commit-test.txt

Pro=$(cd ${DIR} && git branch |awk '/\*/{print $2}')
Protest=$(cd ${DIRtest} && git branch |awk '/\*/{print $2}')
DATE=$(date '+%Y-%m-%d_%H-%M')
DATE1=$(date +%F)

SERVER=(
        "172.16.255.4"
        "172.16.255.6"
        )
SERVER_test=(
        "172.16.255.8"
        )

function Tips() {
echo '1 正式环境'
echo '2 预上线环境'
}

Tips
function tips() {
echo '确认-输入 yes|Y|1 '
echo '退出-输入 no|N|5 '
}

function message2() {
	read -p "请输入此次更新的内容: " message
		if [ -z ${message} ];then
    		echo "请输入此次更新的内容"
    		exit
		else
    		echo "提交代码开始"
		fi
}


function answer(){
	case "$1" in
    	yes|Y|1)
        echo "开始同步代码"
		break
		;;
        no|N|5)
        exit 5
        ;;
	    *)
    	echo $"Usage: $prog {yes|Y|1|no|N|5}"
        esac
}

function confirm() {
	while true
    do
        tips
        read -p "请确认拉取的代码文件是否符合 " num
        answer $num
    done
}

read -p "请输入数字,你要操作的环境,1 正式环境,2 预上线环境 " num
	if [ $num = 1 ];then
		server=online
	elif [ $num = 2 ];then
		server=test
	else
		echo '请按提示输入,别乱来'
		exit 3
fi


#正式环境同步步骤
function online() {
	if [ "${Pro}" == 'master' ];then
		echo 'master'
	else
		echo "分支不是master主干"
		exit 1
fi

#记录更新内容
message2

#记录提交的内容,记录commit提交位置
        cd ${DIR} && /usr/bin/git log --decorate --oneline -1 |awk '{print $1}' >> ${File}

#拉取代码到master
		cd ${DIR} && /usr/bin/git pull origin master >> ${script}/gitlog/gc/gamecenter.file_$DATE1
		echo "---The status `echo $?`"
		echo "################------${DATE}-------分割线--------###############" >> ${script}/gitlog/gc/gamecenter.file_$DATE1
		commit=$(cd ${DIR} && /usr/bin/git log --decorate --oneline -1 |awk '{print $1}')
        echo "更新内容: ${message}  更新时间: ${DATE}  老版本(commit)号如上,当前同步的(commit)点: ${commit}" >> ${File}
		cat ${script}/gitlog/gc/gamecenter.file_$DATE1
		confirm

#同步代码到正式服务器
for i in ${SERVER[@]}
do
  		ssh -p 59878 $i sh ${script}/rsync-gameapi.sh
  		echo "--------------${i}-推送代码完成-----------------"  
done  
}


#测试环境同步步骤
function test() {
#记录更新内容
message2

#记录提交的内容,记录commit提交位置
        cd ${DIRtest} && /usr/bin/git log --decorate --oneline -1 |awk '{print $1}' >> ${File2}
    
#拉取代码到master
	  	cd ${DIRtest} && /usr/bin/git pull origin ${Protest} >> ${script}/gitlog/gc/gctest.file_$DATE1
		echo "---The status `echo $?`"
        echo "################-------${DATE}------分割线--------###############" >> ${script}/gitlog/gc/gctest.file_$DATE1
		commit2=$(cd ${DIRtest} && /usr/bin/git log --decorate --oneline -1 |awk '{print $1}')
        echo "分支:${Protest}更新内容: ${message}  更新时间: ${DATE}  老版本(commit)号如上,当前同步的(commit)点: ${commit2}" >> ${File2}
		cat ${script}/gitlog/gc/gctest.file_$DATE1
		confirm
  
#同步代码到web测试服务器
for i in ${SERVER_test[@]}
do
	  	ssh -p 59878 $i sh ${script}/rsync-gameapi.sh
  		echo "--------------${i}-推送代码完成-----------------"
done
}

$server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  • rsync-gameapi.sh
echo "`date +%H:%M:%d` online开始更新   ##################" >>  /opt/bin/rsynclog/gameapi`date +%Y-%m-%d`.log
rsync -vzrtopg --progress --delete --exclude ".git" update@172.16.255.17::gameapionline /opt/gamecenter --password-file=/etc/update.pass |  tee -a /opt/bin/rsynclog/gameapi`date +%Y-%m-%d`.log
echo " " >> /opt/bin/rsynclog/gameapi`date +%Y-%m-%d`.log
echo 更新结束: `date +%H:%M:%d`  >> /opt/bin/rsynclog/gameapi`date +%Y-%m-%d`.log

1
2
3
4
5
  • 回滚一个标签脚本
#!/bin/bash
#快速回滚游戏中心服务端,<正式环境>的代码

DIR=/opt/rsync-online/gamecenteronline/gamecenteronline
script=/opt/bin
DATE1=$(date +%F)
position=$(tail -2 /opt/bin/commit/gamecenter-commit.txt |head -1 )

SERVER=(
        "172.16.255.4"
        "172.16.255.6"
        )

#回滚标签到上一个版本
	cd ${DIR} && /usr/bin/git reset --hard ${position} >> /opt/bin/gitlog/rollbackgamecenter.file_$DATE1

#同步代码到web服务器
for i in ${SERVER[@]}
do
	ssh -p 59878 $i sh ${script}/rsync-gameapi.sh
	echo "--------------${i}-推送代码完成-----------------"

done

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# ping IP把日志重定向到文件带时间戳

#!/bin/bash
#ip 写入到 appIP.txt 内,一行一个IP,不能有空格

while true
Date=$(date +%F)
test -d ./appIP/$Date || mkdir -p ./appIP/$Date

do
    while read IPaddr
    do
    ping -c 1  $IPaddr |awk '{ print $0"\t" strftime("%Y-%m-%d %H:%M:%S",systime()); fflush()}' |sed -n '2p' >> ./appIP/${Date}/$IPaddr.txt &
    done < ./appIP.txt
sleep 5
find ./appIP/ -mtime +7 -exec rm -rf {} \;
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 初始化磁盘

#!/bin/bash
#by yangfukun

#只第一次初装完系统后运行,其余时间不可运行

#判断路径是否为空
if [ -z "$1" ] ; then
        echo -e "\e[31;1m#######################################################################\e[0m"
        echo -e "\e[31;1m#       请确认,此操作只第一次初装完系统后运行,其余时间不可运行!    #\e[0m"
        echo -e "\e[31;1m#   请输入挂载点(绝对路径),也就是磁盘挂载目录!缺少路径这个参数    #\e[0m"
        echo -e "\e[31;1m#                   例子:./formatdisk.sh /data                       #\e[0m"
        echo -e "\e[31;1m#######################################################################\e[0m"

exit
else
        echo "您输入的磁盘挂载路径为:$1"
fi

#磁盘创建分区
fdisk /dev/vdb << EOF
p
d

n
p
1


w
EOF

#格式化磁盘
mkfs.ext3 /dev/vdb1

#写入磁盘分区表
echo "/dev/vdb1               $1                   ext3    defaults        0 0" >>/etc/fstab

#创建挂载目录
mkdir -p $1

#挂载磁盘
mount -a

#查看磁盘挂载情况
df -h
echo "########################################配置apache和mysql的数据目录###################################################"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

记录命令:blkid /dev/sda2

# 数据库创建表

# 创建256张表

#!/bin/bash
#创建十进制,256张表,sql语句 /tmp/00ff.sql
#修改表名,字段

>/tmp/00ff.txt
>/tmp/00ff.sql

for i in {0..9};do
    for number in {0..9};do
        echo $i$number >>/tmp/00ff.txt
    done
    for char in {a..f};do
        echo $i$char >>/tmp/00ff.txt
    done
done
for i1 in {a..f};do
    for number1 in {0..9};do
        echo $i1$number1 >>/tmp/00ff.txt
    done
    for char1 in {a..f};do
        echo $i1$char1 >>/tmp/00ff.txt
    done
done

a0f=$(cat /tmp/00ff.txt)
while read line
do

cat >>/tmp/00ff.sql<<OPO
CREATE TABLE \`t_mid_active_${line}\` (
OPO

cat >>/tmp/00ff.sql<<'OPO'
  `mid` varchar(64) NOT NULL COMMENT '设备唯一标识(IOS: uudid;Android:[androidid, deviceid]',
  `channel` varchar(30) NOT NULL DEFAULT '' COMMENT '渠道(chid)',
  `subchannel` varchar(30) NOT NULL DEFAULT '' COMMENT '子渠道(subchid)',
  `os` tinyint(4) NOT NULL DEFAULT '0' COMMENT '客户端平台os(1:ios, 2:android, 3:web)',
  `ip` varchar(20) NOT NULL DEFAULT '0' COMMENT '用户IP',
  `idfa` varchar(64) NOT NULL DEFAULT '' COMMENT 'ios广告设备码',
  `mac` varchar(64) NOT NULL DEFAULT '' COMMENT 'mac地址',
  `device_name` varchar(50) NOT NULL DEFAULT '' COMMENT '设备名称',
  `device_os_ver` varchar(50) NOT NULL DEFAULT '' COMMENT '设备系统版本',
  `add_time` int(11) NOT NULL DEFAULT '0' COMMENT '激活时间',
  KEY `mid` (`mid`) USING BTREE,
  KEY `add_time` (`add_time`) USING BTREE,
  KEY `group` (`os`),
  KEY `channel` (`channel`,`subchannel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='设备激活天表';

OPO
done < /tmp/00ff.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

# 创建天表

#!/bin/bash
#创建天表,修改时间变量,修改表名,Sql 语句 /tmp/date.sql
#设置生成今天到哪天,如20201001截止,不生成20201001 这天的
DaTa=20210101

>/tmp/date.sql
Data=$(date +%F)
Day=$((($(date +%s -d "$DaTa") - $(date +%s))/86400))

i=1
while [ $i -le $Day ]
do
sum=$(date +%Y%m%d -d "$i day")

cat >>/tmp/date.sql<<OPO
CREATE TABLE \`t_mid_active_${sum}\` (
OPO
cat >>/tmp/date.sql<<'OPO'
  `mid` varchar(64) NOT NULL COMMENT '设备唯一标识(IOS: uudid;Android:[androidid, deviceid]',
  `channel` varchar(30) NOT NULL DEFAULT '' COMMENT '渠道(chid)',
  `subchannel` varchar(30) NOT NULL DEFAULT '' COMMENT '子渠道(subchid)',
  `os` tinyint(4) NOT NULL DEFAULT '0' COMMENT '客户端平台os(1:ios, 2:android, 3:web)',
  `ip` varchar(20) NOT NULL DEFAULT '0' COMMENT '用户IP',
  `add_time` int(11) NOT NULL DEFAULT '0' COMMENT '激活时间',
  KEY `mid` (`mid`) USING BTREE,
  KEY `add_time` (`add_time`) USING BTREE,
  KEY `group` (`os`),
  KEY `channel` (`channel`,`subchannel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='设备激活天表';
OPO

let i++
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

# 服务器脚本前端打包,多个工程

#!/bin/bash

by: yfk
Path=$(cd $(dirname $0); pwd)
Date=$(date +%F-%H_%M)

echo '
####################################################################
代号            |项目名称                | 说明
0 | q                                    | 退出
1 |jurong       | 巨融
2 |hailuo       | 海洛

####################################################################

'

function toWechatFailed(){

 curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=70bab7e8-2657-4b79-08c3c7bd' \
 -H 'Content-Type: application/json' \
 -d '
 {
 "msgtype": "text",
 "text": {
 "content": "'" 打包提醒 \n\n [打包失败] \n ${Projects} \n 当前打包环境--> ${build_env} \n 当前打包项目--> ${build_project} "'"
 }
 }'
exit 3
}

function toWechatSuccess(){

 curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=70bab7e8-2657-4b79-08c3c7bd' \
 -H 'Content-Type: application/json' \
 -d '
 {
 "msgtype": "text",
 "text": {
 "content": "'" 打包提醒 \n\n [打包成功] \n ${Projects} \n 当前打包环境--> ${build_env} \n 当前打包项目--> ${build_project}  \n  当前版本提交内容:${content} "'"
 }
 }'
}


dispatcher_car_app (){
build_project=dispatcher-car-app
	cd /data/front_build/${build_project}
    rm -rf node_modules
	pwd && git reset --hard `git log --decorate --oneline -1|awk '{print $1}'`
	git pull origin master
	chown -R test:test /data/front_build/${build_project}
su - test -c "
	cd /data/front_build/${build_project}
    npm cache clean --force
	npm config set registry http://mirror.yfklife.cn/repository/npm-hub/
	
	echo '---------Start Install ...'
	npm install
	rm -rf dist
	echo 'Start Build ...'
	npm run build:prod_dev_${build_env}
	find ./dist/static/js/ -name "*.map" -exec rm -f {} \;
"

if [ $(echo $?) != 0 ];then
	toWechatFailed
else
	content=$(cd ${Path}/dispatcher-car-app && git log --decorate --oneline -1|awk '{print $NF}')
	toWechatSuccess
fi
}


dispatcher_remote_app (){
build_project=dispatcher-remote-app
	cd /data/front_build/${build_project}
    rm -rf node_modules
	pwd && git reset --hard `git log --decorate --oneline -1|awk '{print $1}'`
	git pull origin master
	chown -R test:test /data/front_build/${build_project}

su - test -c "
	cd /data/front_build/${build_project}
    npm cache clean --force
	npm config set registry http://mirror.yfklife.cn/repository/npm-hub/ 
	
	echo '---------Start Install ...'
	npm install
	rm -rf dist
	echo 'Start Build ...'
	npm run build:prod_${build_env}
	find ./dist/static/js/ -name "*.map" -exec rm -f {} \;
"

if [ $(echo $?) != 0 ];then
	toWechatFailed
else
	content=$(cd ${Path}/dispatcher-remote-app && git log --decorate --oneline -1|awk '{print $NF}')
	toWechatSuccess
fi
}


dispatcher_web (){
build_project=dispatcher-web
	cd /data/front_build/${build_project}
    rm -rf node_modules
	pwd && git reset --hard `git log --decorate --oneline -1|awk '{print $1}'`
	git pull origin master
	chown -R test:test /data/front_build/${build_project}
su - test -c "
	cd /data/front_build/${build_project}
    npm cache clean --force
	npm config set registry http://mirror.yfklife.cn/repository/npm-hub/
	
	echo '---------Start Install ...'
	npm install
	rm -rf dist
	echo 'Start Build ...'
	npm run build:prod_${build_env}
	find ./dist/static/js/ -name "*.map" -exec rm -f {} \;
"

if [ $(echo $?) != 0 ];then
	toWechatFailed
else
    content=$(cd ${Path}/dispatcher-web && git log --decorate --oneline -1|awk '{print $NF}')
	toWechatSuccess
fi
}

dispatcher_assist_app (){
build_project=dispatcher-assist-app
	cd /data/front_build/${build_project}
    rm -rf node_modules
	pwd && git reset --hard `git log --decorate --oneline -1|awk '{print $1}'`
	git pull origin master
	chown -R test:test /data/front_build/${build_project}
su - test -c "
	cd /data/front_build/${build_project}
    npm cache clean --force
	npm config set registry http://mirror.yfklife.cn/repository/npm-hub/
	
	echo '---------Start Install ...'
	npm install
	rm -rf dist
	echo 'Start Build ...'
	npm run build:prod_${build_env}
	find ./dist/static/js/ -name "*.map" -exec rm -f {} \;
"

if [ $(echo $?) != 0 ];then
    toWechatFailed
else
    content=$(cd ${Path}/dispatcher-assist-app && git log --decorate --oneline -1|awk '{print $NF}')
    toWechatSuccess
fi

}

read -t 300 -p "请输入你要更新的服务代号:"  Number

case $Number in

#打巨融包
1 | jurong)
	build_env=jurong

#选择需要打包的项目
    dispatcher_remote_app &&  cd ${Path}/dispatcher-remote-app/dist && zip -r dispatcher-remote-app.zip ./
    dispatcher_car_app && cd ${Path}/dispatcher-car-app/dist && zip -r dispatcher-car-app.zip ./
    dispatcher_web && cd ${Path}/dispatcher-web/dist && zip -r dispatcher-web.zip ./
#    dispatcher_assist_app && cd ${Path}/dispatcher-assist-app/dist && zip -r dispatcher-assist-app.zip ./


	#拷贝,压缩包
	cd ${Path}/collect  && mkdir jurong-${Date}
	test -f ${Path}/dispatcher-remote-app/dist/dispatcher-remote-app.zip && mv ${Path}/dispatcher-remote-app/dist/dispatcher-remote-app.zip ./jurong-${Date}
	test -f ${Path}/dispatcher-car-app/dist/dispatcher-car-app.zip && mv ${Path}/dispatcher-car-app/dist/dispatcher-car-app.zip ./jurong-${Date}
	test -f ${Path}/dispatcher-web/dist/dispatcher-web.zip && mv ${Path}/dispatcher-web/dist/dispatcher-web.zip ./jurong-${Date}
	test -f ${Path}/dispatcher-assist-app/dist/dispatcher-assist-app.zip && mv ${Path}/dispatcher-assist-app/dist/dispatcher-assist-app.zip ./jurong-${Date}
	cd jurong-${Date} && zip -r jurong-dispatcher-static-${Date}.zip ./
        exit 0;;

#打海洛包
2 | hailuo)
	build_env=hailuo

#选择需要打包的项目
#    dispatcher_remote_app &&  cd ${Path}/dispatcher-remote-app/dist && zip -r dispatcher-remote-app.zip ./
#    dispatcher_car_app && cd ${Path}/dispatcher-car-app/dist && zip -r dispatcher-car-app.zip ./
    dispatcher_web && cd ${Path}/dispatcher-web/dist && zip -r dispatcher-web.zip ./
#    dispatcher_assist_app && cd ${Path}/dispatcher-assist-app/dist && zip -r dispatcher-assist-app.zip ./

	#拷贝,压缩包
	cd ${Path}/collect && mkdir hailuo-${Date}
	test -f ${Path}/dispatcher-remote-app/dist/dispatcher-remote-app.zip && mv ${Path}/dispatcher-remote-app/dist/dispatcher-remote-app.zip ./hailuo-${Date}
	test -f ${Path}/dispatcher-car-app/dist/dispatcher-car-app.zip && mv ${Path}/dispatcher-car-app/dist/dispatcher-car-app.zip ./hailuo-${Date}
	test -f ${Path}/dispatcher-web/dist/dispatcher-web.zip && mv ${Path}/dispatcher-web/dist/dispatcher-web.zip ./hailuo-${Date}
	test -f ${Path}/dispatcher-assist-app/dist/dispatcher-assist-app.zip && mv ${Path}/dispatcher-assist-app/dist/dispatcher-assist-app.zip ./hailuo-${Date}
	cd hailuo-${Date} && zip -r hailuo-dispatcher-static-${Date}.zip ./
        exit 0;;

0|q|Q|quit )
        echo '退出更新'
        exit 0;;
esac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

# 从k8s获取包拷贝到测试环境

#!/bin/bash

echo '
####################################################################
代号 |服务名称                |说明
0 | q                         | 退出
1,   gateway-service       | 网关服务
2,   mes-web               | mes 前端 -*
                               
####################################################################

'

NowDate=$(date +%F-%H-%M)
NowDate2=$(date +%F-%H:%M)

read -t 300 -p "请输入你要更新的服务代号:"  Number
echo "代号 $Number ,现在的系统时间是:${NowDate2}"

case $Number in
1 |gateway-service)
	echo '正在更新-网关服务-'
	dist_dir=gateway-service
	#获取pod 名
	back_service=$(kubectl get pod -n cloud-dev |grep 'gateway'|awk 'NR==1{print $1}')
	#备份jar 包,为后缀带时间的包
	mv ./digitalize_prod/${dist_dir}/java-work/gateway.jar ./digitalize_prod/${dist_dir}/java-work/gateway.jar-${NowDate}
	#拷贝jar 包到对应项目目录
	kubectl cp  -n cloud-dev ${back_service}:/java-work/app.jar ./digitalize_prod/${dist_dir}/java-work/gateway.jar >/dev/null 
	#重启容器
	docker restart prod_gateway_service
	#获取容器状态
    docker ps |grep prod_gateway_service
	#定期删除备份jar 包文件,保留15天
    find ./digitalize_prod/${dist_dir}/java-work/ -name "gateway.jar*" -mtime +30 -exec rm -f {} \;
    echo ''
	echo "服务更新结束----${dist_dir}----######"
    echo ''
	exit 0;;

2 |mes-web)
	echo '正在更新-mes 前端'
	dist_dir=mes-web
	#获取pod 名
	fronted_service=$(kubectl get pod -n cloud-dev |grep 'mes-web'|awk 'NR==1{print $1}')
	#创建备份目录
    test -d ./digitalize_prod/${dist_dir}/bak-dist || mkdir -p ./digitalize_prod/${dist_dir}/bak-dist
	#删除备份目录的文件
    rm -rf ./digitalize_prod/${dist_dir}/bak-dist/* && mv ./digitalize_prod/${dist_dir}/dist/* ./digitalize_prod/${dist_dir}/bak-dist/
	#拷贝 pod 里面的文件,到对应项目目录
	kubectl cp  -n cloud-dev ${fronted_service}:/usr/share/nginx/html/dist/ ./digitalize_prod/${dist_dir}/dist/ >/dev/null 
	#修改api 地址
	grep -rl 'cloud-dev.yfklife.cn' ./digitalize_prod/${dist_dir}/dist/* |xargs sed -i 's#cloud-dev.yfklife.cn/api#192.168.5.147/api#g'
	grep -rl 'cloud-dev.yfklife.cn' ./digitalize_prod/${dist_dir}/dist/* |xargs sed -i 's#cloud-dev.yfklife.cn/designer#192.168.5.147/designer#g'
	grep -rl 'cloud-dev.yfklife.cn' ./digitalize_prod/${dist_dir}/dist/* |xargs sed -i 's#cloud-dev.yfklife.cn/processdesigner#192.168.5.147/processdesigner#g' 
    echo ''
	echo "服务更新结束----${dist_dir}----######"
    echo ''
	exit 0;;

0|q|Q|quit )
	echo '退出更新'
	exit 0;;
esac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  • 修改文件名

sed反向引用

for i in `ls ./*.conf`;do mv $i `ls $i |sed -r 's#([a-z]*.)\..*#\1.yfklife.cn.conf#g'`;done

//
如果此文章对您有帮助,点击 -->> 请博主喝咖啡 (opens new window)
上次更新: 2025/03/28, 13:42:54
公司部署Pritunl-VPN
openldap安装配置

← 公司部署Pritunl-VPN openldap安装配置→

最近更新
01
Linux Polkit 权限提升漏洞(CVE-2021-4034)
03-28
02
postgreSQL维护
03-17
03
trivy系统漏洞扫描
02-25
更多文章>
Theme by Vdoing | Copyright © 2019-2025 yangfk | 湘ICP备2021014415号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×
//