반응형

기본적으로 systemctl 명령을 통한 방식 (CASE 1)과 Startup.sh 및 Shutdown.sh 2가지 방식(CASE 2)이 있습니다.

 

설정하는 환경에 따른 차이로

 

공통적으로 시작 및 종료를 하기 위해서는

 

정확하게 쉘을 수행하는 것이 좋습니다.

 

systemctl 명령을 통해 시작한 tomcat은 Shutdown.sh를 수행하여도

 

잠시뒤에 다시 시작하는 현상도 볼수 있습니다.

 

1. Tomcat 시작하는 쉘

- CASE 1 방식

# Systemctl 서비스 시작 방식

MYID=`whoami`

# CHECK WAS PORT
WASPORT=`lsof -i TCP:80 | grep -i java | wc -l`

if [ ${WASPORT} -gt 0 ]; then
        echo ""
        echo "====================================="
        echo " 이미 WAS(Tomcat)가 실행 중입니다."
        echo ""

        echo " 종료한 뒤 수행해 주세요."
        echo "===================================="
        echo ""

        exit 0

fi

if [ ${MYID} = "root" ]; then
        systemctl start tomcat
else

        echo " root 계정만 실행 가능합니다."
fi

- CASE 2 방식

# WAS 서비스 시작 방식
WASHOME='/apache-tomcat-8.5.40/bin'

MYID=`whoami`

# CHECK WAS PORT
WASPORT=`lsof -i TCP:80 | wc -l`

if [ ${WASPORT} -gt 0 ]; then
        echo ""
        echo "====================================="
        echo " 이미 WAS(Tomcat)가 실행 중입니다."
        echo ""

        echo " 종료한 뒤 수행해 주세요."
        echo "===================================="
        echo ""

        exit 0

fi

if [ ${MYID} = "root" ]; then
        cd ${WASHOME}
        ./startup.sh
else

        echo " root 계정만 실행 가능합니다."
fi

 

2. Tomcat 종료하는 쉘

- CASE 1

# Systemctl 서비스 종료 방식
MYID=`whoami`

# CHECK WAS PORT
WASPORT=`lsof -i TCP:80 | wc -l`

if [ ${WASPORT} -eq 0 ]; then
        echo ""
        echo "====================================="
        echo " WAS가 기동중인 상태가 아닙니다."
        echo ""

        echo " 종료한 뒤 수행해 주세요."
        echo "===================================="
        echo ""

        exit 0

fi

if [ ${MYID} = "root" ]; then
        systemctl stop tomcat
else

        echo " root 계정만 실행 가능합니다."
fi

- CASE 2

# WAS 서비스 종료 방식
WASHOME='/apache-tomcat-8.5.40/bin'

MYID=`whoami`

# CHECK WAS PORT
WASPORT=`lsof -i TCP:80 | wc -l`

if [ ${WASPORT} -eq 0 ]; then
        echo ""
        echo "====================================="
        echo " WAS가 기동중인 상태가 아닙니다."
        echo ""

        echo " 종료한 뒤 수행해 주세요."
        echo "===================================="
        echo ""

        exit 0

fi

if [ ${MYID} = "root" ]; then
        cd ${WASHOME}
        ./shutdown.sh
else

        echo " root 계정만 실행 가능합니다."
fi

 

3. 서비스 포트에 수행되는 PID 확인

# Tomcat 기준

echo ""
echo "==================================================="
echo ""
echo " Use Port : 80, 8005, 8009, 8443, 8080 "
echo ""
echo "==================================================="

echo ""
echo "***************************************************"
echo " 1. Search : 80 Port "
lsof -i TCP:80
echo "***************************************************"
echo ""

echo ""
echo "***************************************************"
echo " 2. Search : 8005 Port "
lsof -i TCP:8005
echo "***************************************************"

echo ""
echo "***************************************************"
echo " 3. Search : 8009 Port "
lsof -i TCP:8009
echo "***************************************************"

echo ""
echo "***************************************************"
echo " 4. Search : 8443 Port "
lsof -i TCP:8443
echo "***************************************************"

echo ""
echo "***************************************************"
echo " 5. Search : 8080 Port "
lsof -i TCP:8080
echo "***************************************************"

echo ""

 

4. tomcat 에 WAR 파일 Deploy 하는 쉘

echo ""
echo "===================================================================="
echo ""
echo " Deploy Shell "
echo ""
echo "===================================================================="

############################# Define Path ################################
BACKUP_ROOT="/home/tomcat/backup"
WAR_DIR="/apache-tomcat-8.5.40/webapps"
WAR_FILE="deploy.war"

##########################################################################


if [ $# -eq 1 ]; then


        echo ""
        echo " 1. Check Deploy File Exist....."
        echo ""

        if [ -f $1 ]; then

                echo ""
                echo " 2. Check WAR File Exist..... "

                if [ -f ${WAR_DIR}/${WAR_FILE} ]; then

                        echo ""
                        echo " 3. Exist deploy.war File Backup"
                        echo "    Backup Folder => $BACKUP_ROOT "
                        echo ""

                        BK_NAME=`date +%Y%m%d_%H%M%S`

                        echo " *  cp ${WAR_DIR}/${WAR_FILE} ${BACKUP_ROOT}/${WAR_FILE}_${BK_NAME}"
                        cp ${WAR_DIR}/${WAR_FILE} ${BACKUP_ROOT}/${WAR_FILE}_${BK_NAME}
                        echo ""

                else

                        echo " *  Don't Backup Run becase, War File Not Exist "
                fi

                # delete old deploy folder
###                rm -rf ${WAR_DIR}/factory

                # Deploy File
                echo " *  cp $1 ${WAR_DIR}/${WAR_FILE}"
                cp $1 ${WAR_DIR}/${WAR_FILE}
                echo ""
                echo " >>> Please Restart Tomcat Service"
                echo ""

        else
                echo ""
                echo " $1 File not Exist .... Please check!"
                echo ""
        fi

else

        echo ""
        echo " Usage : $0 ${WAR_FILE} "
        echo ""
fi

echo ""
echo "===================================================================="
echo ""

 

반응형

+ Recent posts