Shell——脚本安装Tomcat

#!/bin/bash
#creator qituo
#date 2017-11-09
#email 776336152@qq.com

base_dir="/data/shell"
tomcat_dir="$base_dir/tomcat"

function usage()
{
        echo "usage: chsa_addtomcat.sh -p [project] -m [module]  -S [Server port] -H [HTTP-Connector] -A [AJP-Connector]";
        echo "eg: mysqlha_login.sh -p staging -m exchange-web -S 8106 -H 8156 -A 8206";
}

echo $#
if [ $# -ne 10 ] ;
    then
         usage
         exit 1
else
  while getopts p:m:S:H:A: OPTION
  do
     case "$OPTION"  in
         p)project=$OPTARG;;
         m)module=$OPTARG;;
         S)server_port=$OPTARG;;
         H)http_port=$OPTARG;;
         A)ajp_port=$OPTARG;;
         *) echo "input error! please check your input."; usage ; exit 2; ;;
    esac
  done
fi

function check_all()
{
         ##check tomcat
         if [ ! -d $tomcat_dir ]; then
             echo "This server is not installed tomcat ,Now try installing" 
             mkdir -p $base_dir
             if [ -f $base_dir/*tomcat*.tar.gz ]; then
                 echo "This server already exists plase check version"
                 ls $base_dir/*tomcat*.tar.gz
                 exit
             fi
             cd $base_dir
             http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz
             if [[ $? != 0 ]]; then
                   echo "Tomcat download failed"
                   exit
             fi
             sleep 5
             tar -xvzf apache-tomcat-8.0.53.tar.gz
             if [[ $? != 0 ]]; then
                   echo "Tomcat decompression failed"
                   exit
             fi
             mv apache-tomcat-8.0.53 tomcat
             sed -i '163i        <Valve className="org.apache.catalina.valves.RemoteIpValve"' $tomcat_dir/conf/server.xml
             if [[ $? != 0 ]]; then
                   echo "insert server.html failed"
                   exit
             fi
             sed -i '164i      remoteIpHeader="X-Forwarded-For"' $tomcat_dir/conf/server.xml
             if [[ $? != 0 ]]; then
                   echo "insert server.html failed"
                   exit
             fi
             sed -i '165i      protocolHeader="X-Forwarded-Proto"' $tomcat_dir/conf/server.xml
             if [[ $? != 0 ]]; then
                   echo "insert server.html failed"
                   exit
             fi
             sed -i '166i      protocolHeaderHttpsValue="https"/>' $tomcat_dir/conf/server.xml
             if [[ $? != 0 ]]; then
                   echo "insert server.html failed"
                   exit
             fi
             sed -i '150i       <Context path="" docBase="'${module}'" reloadable="true" />' $tomcat_dir/conf/server.xml
             if [[ $? != 0 ]]; then
                   echo "insert server.html failed"
                   exit
             fi
         fi
         ##check port
         for oneport in $server_port $http_port $ajp_port
         do
             reson=`netstat -lnp|grep $oneport`
             if [ X"$reson" = X ]; then
                 echo "$oneport is OK"
             else
                 echo "the $oneport is exists"
             fi
         done
      
}

function copy_tomcat()
{
         if [ -d $base_dir/tomcat-$project-$module ]; then
             echo "then $project $module is exists"
             exit
         fi    
         cd $base_dir
         cp -r tomcat tomcat-$project-$module
         cd tomcat-$project-$module/conf
         sed -i s/8005/$server_port/g server.xml
         if [[ $? != 0 ]]; then
             echo "replace port failedd"
             exit
         fi
         sed -i s/8080/$http_port/g server.xml
         if [[ $? != 0 ]]; then
             echo "replace port failedd"
             exit
         fi
         sed -i s/8009/$ajp_port/g server.xml       
         if [[ $? != 0 ]]; then
             echo "replace port failedd"
             exit
         fi
         sed -i '150d' server.xml
         if [[ $? != 0 ]]; then
             echo "replace port failedd"
             exit
         fi
         if [ $module != 'stats-job' ] && [ $module != 'kline-job' ] && [ $module != 'schedule-web' ]; then
             sed -i '150i       <Context path="" docBase="'${module}'" reloadable="true" />' $base_dir/tomcat-$project-$module/conf/server.xml
         fi
         if [[ $? != 0 ]]; then
             echo "insert server.html failed"
             exit
         fi        
         chown -R work:work $base_dir/tomcat-$project-$module
}


function main()
{
         check_all
         copy_tomcat
}


main

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值