注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Computer Science

I Pressed My Words Here. Will You Read ?

 
 
 

日志

 
 

deploy-do for tomcat  

2016-10-19 11:25:16|  分类: My Projects |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
deploy-do.sh 用于执行tomcat的关闭重启工作,附带拷贝链接文档到工程目录下:
#!/bin/bash
# author: wangzhi
# createTime: 201604142159
# usage:
# 1.shutdown tomcat:
#	./bin/deploy-do.sh forceshutdown
# 2.remove and backup .war
#	./bin/deploy-do.sh removeFolder ROOT
# 3.start tomcat
#	./bin/deploy-do.sh startwithlog .2017-03-01_10
# 4.cp upload link file from webapps/upload to webapps/ROOT/upload
#	./bin/deploy-do.sh cpLinkFile upload ROOT

forceshutdown(){
        local path=$(cd `dirname $PWD/$0`;pwd);
        local pathLevel=$(grep -o "[/]" <<< $(pwd) | wc -l)
        local ifs=$IFS
        IFS="/"
        local tomcatName=`echo $path| awk '{print $'${pathLevel}'}'`
        tomcatName=${1:-${tomcatName}};
        IFS=${ifs};
        local grepResult=`ps -ef | grep java | grep $tomcatName/`
        if [ "$grepResult" != "" ]
        then
                echo "${grepResult}";
                kill -9 `ps -ef | grep java | grep $tomcatName| awk '{print $2}'`;
                grepResult=`ps -ef | grep java | grep $tomcatName/`;
        else
                echo "$tomcatName is not running.";
        fi
        echo "${grepResult}";
}

removeFolder(){
        local path=$(cd `dirname $PWD/$0`;pwd);
        local webapps=${webapps:-"${path}/../webapps"};
        local ifs=$IFS;
        local folderName=${1:-"${folderName}"};
        local warFileName=${2:-"${folderName}"};
        IFS="/"
        local tomcatName=`echo $path| awk '{print $2}'`
        IFS=${ifs};
        local date=$(date --rfc-3339='date')
        case "${warFileName}" in
                "") echo ".war file will NOT be backup." ;;
                *)  echo "backup ${warFileName}.war to upper level folder with date.";
                        cp ${webapps}/${warFileName}.war ${webapps}/../${warFileName}${date}.war;
                        echo ${webapps} ;;
        esac
        echo -n "Do you really want to remove foleder ${folderName} ?" "[y|n]:";
        while read in ;do
                case "${in}" in
                        y|Y|\&)
                                echo "start to remove ${folderName}.";
                                rm -rf ${webapps}/${folderName}/;
                                cp ${webapps}/${warFileName}.war ${webapps}/../${warFileName}${date}.war;
                                echo "cp -d ${webapps}/upload ${webapps}/${folderName}/upload";
                                break ;;
                        n|N|/) echo "fine.";
                                break ;;
                        *) echo -n "[y|n]" ;;
                esac
        done;
}

startwithlog(){
        local path=$(cd `dirname $PWD/$0`;pwd);
        local catalinaSubfix="";
        catalinaSubfix=${1-"${catalinaSubfix}"};
        echo `${path}/startup.sh`;
        echo "starting log.";
        sleep 1;
        tail -200f ${path}/../logs/catalina${catalinaSubfix}.out;
}

cpLinkFile(){
        local path=$(cd `dirname $PWD/$0`;pwd);
        local webapps=${webapps:-"${path}/../webapps"};
        local fileName=${1:-"upload"};
        local folderName=${2:-"${folderName}"};
        local pathName=${webapps}/${folderName}/;
        echo -n "Do you really want to cp link file ${fileName} to ${pathName} ?" "[y|n|q]:";
        while read in ;do
                case "${in}" in
                        y|Y|\&)
                                rm -rf ${pathName}/${fileName} &
sleep 1 & cp -d ${webapps}/${fileName} ${pathName}/${fileName};
                                ls -al "${pathName}" ;;
                        n|N|/) echo "fine. Any more files ?:" ;;
                        q|Q|\|) break ;;
                        *) fileName=${in};
                                echo -n "Do you really want to cp link file ${fileName} to ${pathName} ?" "[y|n|q]:" ;;
                esac
        done;
}

t(){
        local path=$(cd `dirname $PWD/$0`;pwd);
        local webapps=${webapps:-"${path}/../webapps"};
        local fileName=${1:-"upload"};
        local folderName=${2:-"${folderName}"};
        echo "arguments:" ${@};
        echo "path: ${path}";
        echo "fileName:" ${fileName};
        echo "folderName:" ${folderName};
        echo "action: ${action}";
}

deploy_do(){
        local path=$(cd `dirname $PWD/$0`;pwd);
        local webapps="${path}/../webapps";
        local action=${1};
        local folderName="ROOT";
        #local paramOne=${2}
        #local explanation=${3};
        #local moreExplanation=${4};
        #echo "${@:2}";
        case "${action}" in
                "forceshutdown") forceshutdown ${@:2} ;;
                "removeFolder") removeFolder ${@:2} ;;
                "startwithlog") startwithlog ${@:2} ;;
                "cpLinkFile") cpLinkFile ${@:2} ;;
                "t") t ${@:2} ;;
                *) echo "forceshutdown/removeFolder/startwithlog/cpLinkFile/t"
        esac
}
deploy_do $@

./deploy-do.sh
  评论这张
 
阅读(67)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017