您好,登錄后才能下訂單哦!
小編給大家分享一下php如何實(shí)現(xiàn)版本切換,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
以下為現(xiàn)有php業(yè)務(wù),代碼上線方式。實(shí)現(xiàn):4套環(huán)境版本切換。
[root@hz-web-01 htdocs]# 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##*/} [app_env] [build_file_path] 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
以上腳本內(nèi)容較少,沒有注釋。下面進(jìn)行解讀
采用這種方式的原因:阿里云平臺,掛載磁盤被分配在/mnt目錄下
實(shí)際目錄:/mnt/var/www/htdocs
軟連接目錄:/var/www/htdocs
正如help所說 dev 環(huán)境 int環(huán)境 sandbox環(huán)境 live環(huán)境 四套環(huán)境的版本切換。live環(huán)境為線上正式環(huán)境。
我已將思路共享,希望大家能給出改良方案!
#2015-08-26 以下為每次代碼上線的實(shí)施文檔
#此文檔為暫時文檔,后期部署jenkins 更換
#1 檢查tar.gz文件里面一級菜單內(nèi)容
#2 回滾操作:
# 根據(jù)第三步,選擇近期升級版本。
第一步:
把要升級的軟件包,傳送至服務(wù)器:hz-bf-01
代碼存放位置:/mnt/word
第二布:
分發(fā)軟件包到相應(yīng)的服務(wù)器
sh /mnt/shell/fenfa.sh /mnt/word/lvanclub_live_build_20150826_111450.tar.gz /mnt/var/www/htdocs
第三步:
執(zhí)行ansiable:
ansible -i ./hosts web -m command -a "sh /mnt/var/www/htdocs/release.sh live /mnt/var/www/htdocs/lvanclub_live_build_20150827_153156.tar.gz"
以上是“php如何實(shí)現(xiàn)版本切換”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。