#!/bin/bash #Function: printLog() #Author: 刘磊 #Todoing: 打印日志 #Param: logInfo(日志信息) logPath="`pwd`" #日志存放路径 printLog(){ local errorCode=$? local logInfo="$1" echo $logInfo if [ ! -d ${logPath} ];then mkdir -p ${logPath} fi if [ ! "$logInfo" ];then return fi if [ $# -ne 1 ];then echo `date +"%Y-%m-%d %H:%M:%S"` "[ERROR]参数输入错误" | tee --append ${logPath}/yytLog-`date +"%Y-%m-%d"`.log exit 1 fi if [ ${errorCode} -ne 0 ];then echo `date +"%Y-%m-%d %H:%M:%S"` "[ERROR]$logInfo" | tee --append ${logPath}/yytLog-`date +"%Y-%m-%d"`.log exit 1 else echo "$logInfo" echo `date +"%Y-%m-%d %H:%M:%S"` "[INFO]$logInfo" >> ${logPath}/yytLog-`date +"%Y-%m-%d"`.log return fi } #Function: svnDo() #Author: 刘磊 #Todoing: 操作svn #Param: userName(用户名) # passWord(密码) # operation[co(签出)|up(更新)] # svnPath(路径1) svnDo(){ local userName=$1 local passWord=$2 local op=$3 case ${op} in "co") if [ $# -ne 4 ];then printLog "[ERROR] svnDo参数输入错误" exit 1 fi local svnPath=$4 local localPath=$5 result=`svn co "${svnPath}" 2>&1` #result=`ls 2>&1` printLog "$result" printLog "检出SVN[${svnPath}]" || local errorCode=$? return ${errorCode};; esac } #Function: editConf() #Author: 刘磊 #Todoing: 修改配置文件 #Param: filePath(导出文件路径) editConf(){ if [ $# -ne 2 ];then printLog "[ERROR] editConf参数输入错误" exit 1 fi local filePath=$1 if [ -f ${filePath} ] && [ $2 -eq 1 ];then result=`sed -ie '3c\ database_host: 127.0.0.1' ${filePath} 2>&1` printLog "$result" result=`sed -ie '5c\ database_name: yyt_2' ${filePath} 2>&1` printLog "$result" result=`sed -ie '6c\ database_user: root' ${filePath} 2>&1` printLog "$result" result=`sed -ie '7c\ database_password: liulei123' ${filePath} 2>&1` printLog "$result" printLog "修改配置文件[${filePath}]" elif [ -f ${filePath} ] && [ $2 -eq 2 ];then result=`sed -ie '2c\ listen 8084;' ${filePath} 2>&1` printLog "$result" result=`sed -ie '10c\ root /var/www/liulei161228/web;' ${filePath} 2>&1` printLog "$result" result=`sed -ie '13c\ access_log /var/log/nginx/yyt_1.com.access.log;' ${filePath} 2>&1` printLog "$result" result=`sed -ie '14c\ error_log /var/log/nginx/yyt_1.com.error.log;' ${filePath} 2>&1` printLog "$result" printLog "修改配置文件[${filePath}]" else printLog "[ERROR] 配置文件不存在" exit 1 fi } ##################### 配置变量 ##################### #svn路径 projectSvnPath="svn://127.0.0.1/yyt/yyt/branches/liulei" #nginx配置路径 nginxConfigPath=/etc/nginx/sites-enabled/yyt_bak projectName=liulei161228 #svn用户名 userName="liulei" #svn密码 passWord="liulei123" basepath=$(cd `dirname $0`; pwd) cd $basepath ##################### 获取SVN开始 ##################### printLog '----------开始checkout------------'; svnDo ${userName} ${passWord} co ${projectSvnPath} printLog '----------checkout完成------------'; ##################### 清除缓存修改权限 ##################### #清除缓存 result=`rm -rf $basepath/$projectName/app/cache/* 2>&1` printLog "$result" #修改权限 result=`chmod -R 777 $basepath/$projectName/app/cache 2>&1` printLog "$result" result=`chmod -R 777 $basepath/$projectName/app/logs 2>&1` printLog "$result" ##################### 修改配置文件 ##################### result=`cp ./yyt_1 $nginxConfigPath 2>&1` printLog "$result" editConf $basepath/$projectName/app/config/parameters.yml 1 editConf $nginxConfigPath 2 ##################### 重启服务 ##################### result=`service nginx restart 2>&1` printLog "$result" printLog "--------------部署完成-------------" ##################### 开始测试 ##################### printLog "--------------开始测试-------------" result=`source $projectName/test.sh 2>&1` printLog "$result" printLog "--------------测试完成-------------"
下面为配置文-1件代码 yyt_1
server { listen 80; # [改] 网站的域名 server_name www.yyt.com yyt.com; #301跳转可以在nginx中配置 # 程序的安装路径 root /var/www/liulei161228/web; # 日志路径 access_log /var/log/nginx/yyt_1.com.access.log; error_log /var/log/nginx/yyt_1.com.error.log; location / { index app.php; try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /app.php/$1 last; } location ~ ^/udisk { internal; root /var/www/mohatch/app/data/; } location ~ ^/(app|app_dev)\.php(/|$) { # fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect; fastcgi_param HTTP_X-Accel-Mapping /udisk=/var/www/mohatch/app/data/udisk; fastcgi_buffer_size 128k; fastcgi_buffers 8 128k; } # 配置设置图片格式文件 location ~* \.(jpg|jpeg|gif|png|ico|swf)$ { # 过期时间为3年 expires 3y; # 关闭日志记录 access_log off; # 关闭gzip压缩,减少CPU消耗,因为图片的压缩率不高。 gzip off; } # 配置css/js文件 location ~* \.(css|js)$ { access_log off; expires 3y; } # 禁止用户上传目录下所有.php文件的访问,提高安全性 location ~ ^/files/.*\.(php|php5)$ { deny all; } # 以下配置允许运行.php的程序,方便于其他第三方系统的集成。 location ~ \.php$ { # [改] 请根据实际php-fpm运行的方式修改 fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } }
下面为配置文件-2代码 parameters.yml
parameters: database_driver: pdo_mysql database_host: 127.0.0.1 database_port: 3306 database_name: yyt_2 database_user: root database_password: liulei123 mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: null mailer_password: null locale: zh_CN secret: 2mrbzstp5nwgc00wkkw40w0w8o0ko4g user_partner: none
下面为 test.sh代码#!/bin/bash basepath=$(cd `dirname $0`; pwd) if [ "$projectName" ];then basepath=$basepath/"$projectName" fi cd $basepath /usr/local/bin/phpunit --log-junit $basepath/web/testResult.xml -c $basepath/app/ $basepath/src/Bnqc/MobileBundle/ php $basepath/testResult.php