安裝jetty的腳本

腳本固定格式,固定版本,若有須要其它路徑,版本,請自行修改 java

#!/bin/bashweb

###############################################
#@desc :
#建立用戶
#建立默認目錄並進行受權
#Jetty下載地址:
#http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.3.9.v20160517/jetty-distribution-9.3.9.v20160517.tar.gz
#
###############################################
set -o nounset
set -o errexit
checkExist(){
    local num=`cat /etc/passwd|grep -w jetty|wc -l`
    if [[ $num == 1 ]];then
        echo "user jetty exists,overwrite user and *init all data*:[y/n]?"
        read replace
        if [[ $replace == "y" ]];then
            echo "delete existed user:jetty"
            userdel -r "jetty"
            createUser
            return 0
        fi
    else
        createUser
    fi
    return 0
}
createUser(){
    initDir
    useradd --user-group --shell /bin/false --home-dir /opt/jetty/temp jetty
    echo "OK:create user:jetty done"
}
initDir(){
    mkdir -p /opt/jetty
    mkdir -p /opt/jetty/temp
    mkdir -p /opt/web/mybase
}
installJetty(){
    which java
    if [[ $? != 0 ]];then
        echo "Java not exists,first install JDK,the JDK version must be more than 1.7,exit."
        return
    fi
    cd /opt/jetty
    #wget http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.3.9.v20160517/jetty-distribution-9.3.9.v20160517.tar.gz
    cp /opt/software/jetty-distribution-9.3.9.v20160517.tar.gz ./
    tar -zxf jetty-distribution-9.3.9.v20160517.tar.gz 
    cd /opt/web/mybase
    java -jar /opt/jetty/jetty-distribution-9.3.9.v20160517/start.jar --add-to-start=deploy,http,logging
    cp /opt/jetty/jetty-distribution-9.3.9.v20160517/bin/jetty.sh /etc/init.d/jetty
    echo "JETTY_HOME=/opt/jetty/jetty-distribution-9.3.9.v20160517" > /etc/default/jetty
        echo "JETTY_BASE=/opt/web/mybase" >> /etc/default/jetty
        echo "TMPDIR=/opt/jetty/temp" >> /etc/default/jetty
        echo "JETTY_USER=jetty" >> /etc/default/jetty
        echo "JETTY_SHELL=/bin/bash" >> /etc/default/jetty    
    chown -R jetty:jetty /opt/jetty
        chown -R jetty:jetty /opt/web/mybase
    service jetty start
    echo "OK,install jetty done"
}
checkExist
installJettyshell

相關文章
相關標籤/搜索