码迷,mamicode.com
首页 > 系统相关 > 详细

Bash Shell-通用项目升级脚本

时间:2017-06-28 13:19:06      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:shell   ase   blog   logs   nbsp   tom   查看   通用   chm   

#!/bin/bash

################################################################################
# Filename : upgrade_project.sh
# Summary  : 项目升级脚本
# License  : GPL    
# Version  : 1.0
# Author   : Jet Bi
# Email    : 1207501666@qq.com
# Date     : 2016/08/08
# Note     :
#    1.需要项目支持svn升级方式,并装有svn
#    2.需要restart_tomcat.sh存在
#    3.使用说明
#        升级:./upgrade_project.sh -p 项目路径 -t Tomcat路径
#        回滚:./upgrade_project.sh -r 版本号 -p 项目路径 -t Tomcat路径                                     
################################################################################

project_path=""                                          # 项目路径
project_version=""                                       # 项目版本
tomcat_path=""                                           # Tomcat路径
restart_script="/local/script/restart_tomcat.sh"         # 重启脚本路径
log_file="/local/script/logs/upgrade.log"                # 日志文件路径

# 获取参数,并给变量赋值
while getopts p:r:t: OPT; do
    case ${OPT} in
      p)
        project_path=${OPTARG}
        ;;
      r)
        project_version=${OPTARG}
        ;;
      t)
        tomcat_path=${OPTARG}
        ;;
    esac
done

# 检查是否设置了项目路径和Tomcat路径
echo ${project_path:?"-p Option:Missing Project Path"} > /dev/null
echo ${tomcat_path:?"-t Option:Missing Tomcat Path"} > /dev/null

# 查看是否有Tomcat重启脚本
if [ ! -e ${restart_script} ]; then
    echo "Can‘t find /local/script/restart_tomcat.sh"
    exit 1
fi

# 查看是否有执行脚本的权限
if [ ! -x ${restart_script} ]; then
    chmod u+x ${restart_script} 
fi

# 判断项目目录是否合法
if [[ ! -d ${project_path} ]]; then
    echo "${project_path} is not a directory!"
    exit 2
fi

# 查看是否存在日志目录,不存在创建
if [[ ! -e $(dirname ${log_file}) ]]; then
    echo "No directory of upgrade.log: $(dirname ${log_file})"
    mkdir $(dirname ${log_file})
    # exit 3
fi

# 开始升级
echo ---------------------------------------------------------------------------->> ${log_file}
echo "upgrade_title:$(date +%Y-%m-%d" "%H:%M:%S) svn up ${project_path}" >> ${log_file}
echo -e "upgrade_content:\c" >> ${log_file}
if [ ${project_version} ]; then
    svn up -r ${OPTARG} ${project_path} >> ${log_file} 2>&1 && ${restart_script} ${tomcat_path}    
else
    svn up ${project_path} >> ${log_file} 2>&1 && ${restart_script} ${tomcat_path}        
fi
echo ---------------------------------------------------------------------------->> ${log_file}
exit 0

 

Bash Shell-通用项目升级脚本

标签:shell   ase   blog   logs   nbsp   tom   查看   通用   chm   

原文地址:http://www.cnblogs.com/qq1207501666/p/7089068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!