tomcat快速部署腳本1.3

#!/bin/bash
#-*- coding: utf-8 -*-
#Date:   2020/03/30
#Author:  Mr.yang
#Version: 1.3

tomcat6=""
tomcat61=""
tomcat62=""
tomcat63=""
tomcat7=""
tomcat8=""
tomcat81=""
tomcat82=""
tomcat83=""
i="0"

function choose(){
cat << KOF
*************************************************
*        1.測試環境項目部署        *
*        2.正式環境項目部署        *
*************************************************
KOF
}

function test(){
read -p "請輸入項目名:" pjname
    name=`echo ${pjname} | sed 's/-//g'`
read -p "請輸入平臺名稱:" platform && read -p "請輸入用戶密碼:" passwd
    mkdir -p /webapp/${platform}${pjname}
    mkdir -p /logs/${pjname}
    useradd ${platform}${name}
    echo "${passwd}" | passwd --stdin ${platform}${name}
read -p "請輸入端口號(關閉端口自動+1000):" prot
    while [ $i -le 3 ]
    do
                fin=`find /webapp -mindepth 2 -maxdepth 2 |egrep tomcat_${prot} | wc -l`
                find /webapp -mindepth 2 -maxdepth 2 |egrep tomcat_${prot} | wc -l
                if [ $fin != 0 ];then
                        echo "端口目錄存在……" && read -p "請從新輸入端口號:" prot
                        i=$((i+1))
                        if [ $i < 3 ];then
                                continue
                        elif [ $i == 3 ];then
                                echo "請仔細覈對端口後,再次執行……"
                                exit
                        fi
                        ps -ef |grep $prot | grep -v grep
                        if [ $? -eq 0 ];then
                                echo "啓用端口重複……" && read -p "請從新輸入:" prot
                        elif [ $? -ne 0 ];then
                                echo "無故口重複,繼續進行……"
                                break
                        fi
                elif [ $fin == 0 ];then
                        echo "無故口重複……"
                        break
                fi
        done
read -p "請輸入tomcat版本(輸入6/8):" tomcat
    cd /webapp/${platform}${pjname}
    if [ $tomcat == 6 ];then
        wget $tomcat6
    elif [ $tomcat == 7 ];then
        wget $tomcat7
    elif [ $tomcat == 8 ];then
        wget $tomcat8
    fi
}

function product(){
read -p "請輸入項目名:" pjname
read -p "請輸入平臺名稱:" platform && read -p "請輸入用戶密碼:" passwd && read -p "請輸入UID:" uid
    name=`echo ${pjname} | sed 's/-//g'`
    mkdir -p /webapp/${platform}${pjname}
    mkdir -p /logs/${pjname}
    useradd -u ${uid} ${platform}${name}
    echo "$passwd" | passwd --stdin ${platform}${name}
read -p "請輸入端口號(關閉端口自動+1000):" prot
    while [ $i -le 3 ]
    do
                fin=`find /webapp -mindepth 2 -maxdepth 2 |egrep tomcat_${prot} | wc -l`
                find /webapp -mindepth 2 -maxdepth 2 |egrep tomcat_${prot} | wc -l
                if [ $fin != 0 ];then
                        echo "端口目錄存在……" && read -p "請從新輸入端口號:" prot
                        i=$((i+1))
                        if [ $i <= 3 ];then
                                continue
                        elif [ $i == 3 ];then
                                echo "請仔細覈對端口後,再次執行……"
                                exit
                        fi
                        ps -ef |grep $prot | grep -v grep
                        if [ $? -eq 0 ];then
                                echo "啓用端口重複……" && read -p "請從新輸入:" prot
                        elif [ $? -ne 0 ];then
                                echo "無故口重複,繼續進行……"
                                break
                        fi
                elif [ $fin == 0 ];then
                        echo "無故口重複……"
                        break
                fi
    done
read -p "請輸入tomcat版本(6/8+1/2/3爲低/中/高配置)\n(例61) :" tomcat
    cd /webapp/${platform}${pjname}
    if [ $tomcat == 61 ];then
        wget $tomcat61
    elif [ $tomcat == 62 ];then
        wget $tomcat62
    elif [ $tomcat == 63 ];then
        wget $tomcat63
    elif [ $tomcat == 81 ];then
        wget $tomcat81
    elif [ $tomcat == 82 ];then
        wget $tomcat82
    elif [ $tomcat == 83 ];then
        wget $tomcat83
    fi
}


function tomcat(){
    echo "建立中……請稍後……"
        tar=`ls | awk '/jdk/{print}'`
        tar xf /webapp/${platform}${pjname}/$tar && rm -rf /webapp/${platform}${pjname}/$tar
        gz=`ls | awk 'NR==1{print $1}'`
        mv /webapp/${platform}${pjname}/$gz /webapp/${platform}${pjname}/tomcat_$prot
        sed -i "s/8080/$prot/g" /webapp/${platform}${pjname}/tomcat_$prot/conf/server.xml
        Prot=$(($prot+1000))
        sed -i "s/9080/$Prot/g" /webapp/${platform}${pjname}/tomcat_$prot/conf/server.xml
        chown -R $platform$name.$platform$name /webapp/${platform}${pjname} /logs/${pjname}
        su - $platform$name -c "sh /webapp/${platform}${pjname}/tomcat_$prot/bin/startup.sh"
}

while :
do
    clear
    choose
    read -p "選擇列表內容:" a
    case $a in
        1)
            test
            tomcat
            exit
            ;;
        2)
            product
            tomcat
            exit
            ;;
        *)
            echo "輸入錯誤,請從新輸入"
            sleep 2
            ;;
    esac
done
相關文章
相關標籤/搜索