首先这边是乙方,项目多,系统多。新上线的项目都是脚本去做发布,早上又赶了套脚本。
之前公司有兄弟运行了下面这套脚本未加参数,说静态资源未发成功,tomcat 和发布系统的agent反而给干没了,于是又做了点优化,加了参数判断。
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
|
$
cat
copy_h5_mall_new.sh
#!/bin/sh
#copy h5 mall
nginx_static_ip=10.10.13.37
time_stamp=`
date
+
"%Y-%m-%d-%H-%M-%S"
`
h5_mall_zip_name=$1
war_md5=`md5sum ..
/static/
${h5_mall_zip_name} |
awk
'{print $1}'
`
md5_file=`
cat
..
/static/
${h5_mall_zip_name}.md5 |
awk
'{print $1}'
`
if
[ $
# -ne "1" ];then
echo
"不看脚本就运行,干死你!"
else
if
[
"${war_md5}"
=
"${md5_file}"
];
then
ssh
${nginx_static_ip}
"cp -r /data/desheng/h5_mall /data/desheng/h5_mall-${time_stamp}"
ssh
${nginx_static_ip}
"cd /data/desheng/h5_mall && /bin/rm -rf *"
scp
..
/static/
${h5_mall_zip_name} ${nginx_static_ip}:
/data/desheng/h5_mall
ssh
${nginx_static_ip}
"cd /data/desheng/h5_mall && unzip ${h5_mall_zip_name}"
ip_list=`
cat
..
/env
.sh |
grep
"frontier-cms-web"
|
cut
-d
"="
-f1 |
cut
-d
"#"
-f2 |
uniq
`
for
ip
in
${ip_list[*]};
do
ssh
$ip
"cd /data/static/10 && cp -r h5_mall h5_mall-${time_stamp}"
ssh
$ip
"cd /data/static/10/h5_mall && /bin/rm -rf *"
scp
..
/static/
${h5_mall_zip_name} $ip:
/data/static/10/h5_mall/
ssh
$ip
"cd /data/static/10/h5_mall && unzip ${h5_mall_zip_name}"
done
fi
fi
|
#这个脚本早上临时做的,发现这个静态资源还没有脚本发布。脚本主要对参数和运行脚本的用户做了判断。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
$
cat
copy_cms_static.sh
#!/bin/bash
war=$1
nginx_static_ip=10.10.1.28
temp_time=`
date
+%Y-%m-%d-%H-%M-%S`
if
[ `
whoami
` ==
"ody"
];
then
if
[ $
# -ne "1" ];then
echo
-n
"输入的参数不对,请重新输入."
else
ssh
${nginx_static_ip}
"cd /data/stgds/ && cp -r cms_dev{,-${temp_time}}"
ssh
${nginx_static_ip}
"cd /data/stgds/cms_dev/ && /bin/rm -rf ./*"
scp
..
/static/
${war} ${nginx_static_ip}:
/data/stgds/cms_dev/
ssh
${nginx_static_ip}
"cd /data/stgds/cms_dev/ && unzip ${war}"
fi
else
echo
-n
"当前用户不是ody用户."
fi
|
下面是新项目一套发布脚本,昨天改的,运行一天还未见报错、未见发布失败的。
war包发布的脚本:
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
|
# cat deploy_new.sh
#!/bin/sh
read
-p
"请输入你需要发布的Poll Name:"
pool_name
if
[
"$pool_name"
=
""
];
then
echo
"pool_name 不支持为空!"
else
product_ip_list=`
cat
.
/deploy_env
.ini |
grep
${pool_name} |
awk
-F
'='
'{print $2}'
`
time_stamp=`
date
+
"%Y-%m-%d-%H-%M-%S"
`
function
shutdown_tomcat() {
ip=$1
tomcat_port=8080
tomcat_id=`
ssh
ody@$ip
ps
-ef |
grep
java |
grep
"tomcat"
|
grep
-
v
"grep"
|
awk
'{print $2}'
`
if
[ ! $tomcat_id ];
then
echo
"tomcat process in ${ip} is not exist."
else
echo
"shutdown tomcat in ${ip}"
ssh
ody@$ip
"/bin/kill -9 $tomcat_id"
if
[ $? == 0 ];
then
echo
"shutdown ody@$ip tomcat process is success."
else
echo
"shutdown ody@$ip tomcat process is false."
exit
2
fi
fi
}
function
start_tomcat() {
ip=$1
echo
"start tomcat in ${ip}."
ssh
ody@$ip
"JAVA_HOME=/usr/local/java/jdk1.7.0_80;export JAVA_HOME;/bin/sh /data/tomcat/bin/startup.sh"
ssh
ody@$ip
"/usr/local/java/jdk1.7.0_80/bin/jps"
}
if
[ `
whoami
` ==
"ody"
];
then
ssh
10.18.3.200
"cd /data/war && md5sum -c ${pool_name}.war.md5"
if
[ $? -
eq
0 ];
then
pool_ip_list=`
awk
'BEGIN{list="'
${product_ip_list}
'";split(list,ip_list,",");for(ip in ip_list){print ip_list[ip];}}'
`
for
deploy_ip
in
${pool_ip_list[*]};
do
shutdown_tomcat ${deploy_ip}
ssh
${deploy_ip}
"cd /data/tomcat/webapps && mv ${pool_name}.war ${pool_name}.war-${time_stamp}"
ssh
${deploy_ip}
"cd /data/tomcat/webapps && rm -rf ${pool_name}"
scp
10.18.3.200:
/data/war/
${pool_name}.war
/data/war/
scp
/data/war/
${pool_name}.war ${deploy_ip}:
/data/tomcat/webapps
start_tomcat ${deploy_ip}
done
else
echo
"md5 check false."
exit
2
fi
else
echo
"please use ody user to exec this shell."
fi
fi
|
脚本中的deploy_env.ini文件,是war和ip对应的关系:
大致是下面的样子:
1
2
3
|
# cat deploy_env.ini
ad-whale=10.18.1.1,10.18.1.64
ad-whale-web=10.18.1.2
|
本文转自青衫解衣 51CTO博客,原文链接:http://blog.51cto.com/215687833/1905065