php代码上线,实现版本切换
以下為現有php業務,代碼上線方式。實現:4套環境版本切換。
[root@hz-web-01?htdocs]#?cat?release.sh #!/usr/bin/env?bashwork_dir=/mnt/var/www/htdocs release_dir=/var/www/htdocs#?app?environment app_env=$1 #?build?release?file?path build_file_path=$2help()?{echoecho?usage:?${0##*/}?[app_env]?[build_file_path]echo?example:?${0##*/}?int?lvanclub_int_build_20150731_170557.tar.gzechoexit?0 }#?check?the?app_env?variable?value case?${app_env}?indev)echo?"ECHO:?don't?support?dev?environment?present"helpexit?1;;int)user=apachegroup=apache;;sandbox)user=apachegroup=apache;;live)user=php-fpmgroup=php-fpm;;*)echo?"ERROR:?invalid?app_env?value,?should?be?dev,?int,?sandbox?orlive!"helpexit?1;; esac#?check?the?build_file_path?variable?value if?[?-z?${build_file_path}?] thenecho?"ERROR:?please?specify?the?build?file?path"helpexit?1 elif?[?!?-f?${build_file_path}?] thenecho?"ERROR:?specified?build?file?'${build_file_path}'?is?notfound"helpexit?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 ./hosts ?web -m command -a "sh /mnt/var/www/htdocs/release.sh live /mnt/var/www/htdocs/lvanclub_live_build_20150827_153156.tar.gz"
轉載于:https://blog.51cto.com/hexudong/1690381
總結
以上是生活随笔為你收集整理的php代码上线,实现版本切换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转】CMMI环境下,该如何实施Agil
- 下一篇: php异步处理,执行系统命令