kghjtyhyt 发表于 2015-9-2 09:25:53

php代码上线,实现版本切换

以下为现有php业务,代码上线方式。实现:4套环境版本切换。

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
# cat release.sh
#!/usr/bin/env bash

work_dir=/mnt/var/www/htdocs
release_dir=/var/www/htdocs

# app environment
app_env=$1
# build release file path
build_file_path=$2

help() {
   echo
   echo usage: ${0##*/}
   echo example: ${0##*/} int lvanclub_int_build_20150731_170557.tar.gz
   echo
   exit 0
}

# check the app_env variable value
case ${app_env} in
   dev)
       echo "ECHO: don't support dev environment present"
       help
       exit 1
       ;;
   int)
       user=apache
       group=apache
       ;;
   sandbox)
       user=apache
       group=apache
       ;;
   live)
       user=php-fpm
       group=php-fpm
       ;;
   *)
       echo "ERROR: invalid app_env value, should be dev, int, sandbox orlive!"
       help
       exit 1
       ;;
esac

# check the build_file_path variable value
if [ -z ${build_file_path} ]
then
   echo "ERROR: please specify the build file path"
   help
   exit 1
elif [ ! -f ${build_file_path} ]
then
   echo "ERROR: specified build file '${build_file_path}' is notfound"
   help
   exit 1
fi

# reference: linux shell 字符串操作(长度,查找,替换)详解 - http://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html
# only keep the build folder name
build_file_name=${build_file_path##*/}
build_name=${build_file_name%.tar.gz}
# if current build folder exists, justremove it
rm ${work_dir}/${build_name} -rvf
tar xzvf ${build_file_path}--directory=${work_dir}/

# make soft link for cpserver project
cd ${work_dir}/${build_name}/sdkserver/web
ln -s ../../cpserver cpserver

# copy log files
cd ${work_dir}
# appstore
cp${release_dir}/${app_env}/appstore/apps/api/var/logs ${work_dir}/${build_name}/appstore/apps/api/var/-rvf
# appstore dashboard
cp${release_dir}/${app_env}/appstore/apps/dashboard/var/logs${work_dir}/${build_name}/appstore/apps/dashboard/var/ -rvf
# sdkserver
cp${release_dir}/${app_env}/sdkserver/protected/logs${work_dir}/${build_name}/sdkserver/protected/ -rvf
cp${release_dir}/${app_env}/sdkserver/protected/runtime${work_dir}/${build_name}/sdkserver/protected/ -rvf
# cpserver
cp ${release_dir}/${app_env}/cpserver/logs${work_dir}/${build_name}/cpserver/ -rvf

# change file owners and permissions
chown ${user}:${group}${work_dir}/${build_name} -R
chmod 775 ${work_dir}/${build_name} -R

# make build as current release
rm ${release_dir}/${app_env} -vf
ln -s ${work_dir}/${build_name}${release_dir}/${app_env}

# restart php-fpm service
service php-fpm restart





以上脚本内容较少,没有注释。下面进行解读   
采用这种方式的原因:阿里云平台,挂载磁盘被分配在/mnt目录下

实际目录:/mnt/var/www/htdocs
软连接目录:/var/www/htdocs
正如help所说dev 环境   int环境   sandbox环境live环境   四套环境的版本切换。live环境为线上正式环境。

我已将思路共享,希望大家能给出改良方案!

#2015-08-26      以下为每次代码上线的实施文档
#此文档为暂时文档,后期部署jenkins 更换
#1 检查tar.gz文件里面一级菜单内容
#2 回滚操作:
# 根据第三步,选择近期升级版本。

第一步:
把要升级的软件包,传送至服务器:hz-bf-01
代码存放位置:/mnt/word
第二布:
分发软件包到相应的服务器
sh /mnt/shell/fenfa.sh /mnt/word/lvanclub_live_build_20150826_111450.tar.gz /mnt/var/www/htdocs
第三步:
执行ansiable:
ansible -i ./hostsweb -m command -a "sh /mnt/var/www/htdocs/release.sh live /mnt/var/www/htdocs/lvanclub_live_build_20150827_153156.tar.gz"


页: [1]
查看完整版本: php代码上线,实现版本切换