eunja511005 / AutoCoding

0 stars 0 forks source link

[중요] 사전 알림 체계 구축 #159

Open eunja511005 opened 1 year ago

eunja511005 commented 1 year ago

크론탭 설치를 위해 OS 확인

cat /proc/version

크론탭 설치

sudo yum install cronie
sudo systemctl enable crond
sudo systemctl start crond

image

크론탭 잘 설치 되었는지 확인

cd /usr/local/lib/tomcat/webapps/
mkdir batchshell
cd batchshell
vi test_script.sh
i

#!/bin/bash
echo "Cron job is running"

esc 
:wq
chmod 755 test_script.sh
mkdir logs
crontab -e
i
* * * * * /usr/local/lib/tomcat/webapps/batchshell/test_script.sh > /usr/local/lib/tomcat/webapps/batchshell/logs/test.log 2>&1
eunja511005 commented 1 year ago

자바 설치 위치 확인

echo $JAVA_HOME

shellEnv.sh 파일 만들기

#!/bin/bash

export JAVA_HOME=/home/opc/java/openjdk-8u342-b07/bin
export WORK_HOME=/usr/local/lib/tomcat/webapps/ROOT
export BUILD_PATH=${WORK_HOME}/WEB-INF/classes

export CLASS_PATH=${BUILD_PATH}
export CLASS_PATH=${CLASS_PATH}:${WORK_HOME}/WEB-INF/lib/*

오류가 나서 종료 되어도 무조건 락 파일 삭제 하도록 trap 설정

#!/bin/bash

lockfile="/usr/local/lib/tomcat/webapps/my_batch_job.lock"

if [ -e "$lockfile" ]; then
    echo "Batch job is already running."
    exit 1
fi

touch "$lockfile"

trap 'rm -f "$lockfile"' EXIT

source /usr/local/lib/tomcat/webapps/batchshell/script_env.sh
export executeBatch="batchshell.Batch_Test"
${JAVA_HOME}/java -cp ${CLASS_PATH} $executeBatch $1 $2