-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
134 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
#!/bin/bash | ||
|
||
BUILD_JAR=$(ls /home/ubuntu/app/build/libs/*.jar) | ||
JAR_NAME=$(basename $BUILD_JAR) | ||
echo ">>> build 파일명: $JAR_NAME" >> /home/ubuntu/deploy.log | ||
|
||
echo ">>> build 파일 복사" >> /home/ubuntu/deploy.log | ||
DEPLOY_PATH=/home/ubuntu/app/ | ||
cp $BUILD_JAR $DEPLOY_PATH | ||
|
||
echo ">>> 현재 실행중인 애플리케이션 pid 확인 후 일괄 종료" >> /home/ubuntu/deploy.log | ||
sudo ps -ef | grep java | awk '{print $2}' | xargs kill -15 | ||
|
||
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME | ||
echo ">>> DEPLOY_JAR 배포" >> /home/ubuntu/deploy.log | ||
echo ">>> $DEPLOY_JAR의 $JAR_NAME를 실행합니다" >> /home/ubunru/deploy.log | ||
nohup java -jar $DEPLOY_JAR >> /home/ubuntu/deploy.log 2> /home/ubuntu/deploy_err.log & | ||
|
||
# backup | ||
##!/bin/bash | ||
# | ||
#BUILD_JAR=$(ls /home/ubuntu/app/build/libs/*.jar) | ||
#JAR_NAME=$(basename $BUILD_JAR) | ||
#echo ">>> build 파일명: $JAR_NAME" >> /home/ubuntu/deploy.log | ||
# | ||
#echo ">>> build 파일 복사" >> /home/ubuntu/deploy.log | ||
#DEPLOY_PATH=/home/ubuntu/ | ||
#DEPLOY_PATH=/home/ubuntu/app/ | ||
#cp $BUILD_JAR $DEPLOY_PATH | ||
# | ||
#echo ">>> 현재 실행중인 애플리케이션 pid 확인" >> /home/ubuntu/deploy.log | ||
#CURRENT_PID=$(pgrep -f $JAR_NAME) | ||
# | ||
#if [ -z $CURRENT_PID ] | ||
#then | ||
# echo ">>> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ubuntu/deploy.log | ||
#else | ||
# echo ">>> kill -15 $CURRENT_PID" | ||
# kill -15 $CURRENT_PID | ||
# sleep 5 | ||
#fi | ||
#echo ">>> 현재 실행중인 애플리케이션 pid 확인 후 일괄 종료" >> /home/ubuntu/deploy.log | ||
#sudo ps -ef | grep java | awk '{print $2}' | xargs kill -15 | ||
# | ||
#DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME | ||
#echo ">>> DEPLOY_JAR 배포" >> /home/ubuntu/deploy.log | ||
#nohup java -jar $DEPLOY_JAR >> /home/ubuntu/deploy.log 2> /home/ubuntu/deploy_err.log & | ||
#echo ">>> $DEPLOY_JAR의 $JAR_NAME를 실행합니다" >> /home/ubunru/deploy.log | ||
#nohup java -jar $DEPLOY_JAR >> /home/ubuntu/deploy.log 2> /home/ubuntu/deploy_err.log & | ||
# | ||
## backup | ||
##BUILD_JAR=$(ls /home/ubuntu/app/build/libs/*.jar) | ||
##JAR_NAME=$(basename $BUILD_JAR) | ||
##echo ">>> build 파일명: $JAR_NAME" >> /home/ubuntu/deploy.log | ||
## | ||
##echo ">>> build 파일 복사" >> /home/ubuntu/deploy.log | ||
##DEPLOY_PATH=/home/ubuntu/ | ||
##cp $BUILD_JAR $DEPLOY_PATH | ||
## | ||
##echo ">>> 현재 실행중인 애플리케이션 pid 확인" >> /home/ubuntu/deploy.log | ||
##CURRENT_PID=$(pgrep -f $JAR_NAME) | ||
## | ||
##if [ -z $CURRENT_PID ] | ||
##then | ||
## echo ">>> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ubuntu/deploy.log | ||
##else | ||
## echo ">>> kill -15 $CURRENT_PID" | ||
## kill -15 $CURRENT_PID | ||
## sleep 5 | ||
##fi | ||
## | ||
##DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME | ||
##echo ">>> DEPLOY_JAR 배포" >> /home/ubuntu/deploy.log | ||
##nohup java -jar $DEPLOY_JAR >> /home/ubuntu/deploy.log 2> /home/ubuntu/deploy_err.log & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# health.sh | ||
|
||
#!/bin/bash | ||
|
||
# Crawl current connected port of WAS | ||
CURRENT_PORT=$(cat /home/ubuntu/service_url.inc | grep -Po '[0-9]+' | tail -1) | ||
TARGET_PORT=0 | ||
|
||
# Toggle port Number | ||
if [ ${CURRENT_PORT} -eq 8081 ]; then | ||
TARGET_PORT=8082 | ||
elif [ ${CURRENT_PORT} -eq 8082 ]; then | ||
TARGET_PORT=8081 | ||
else | ||
echo "> No WAS is connected to nginx" | ||
exit 1 | ||
fi | ||
|
||
|
||
echo "> Start health check of WAS at http://localhost:${TARGET_PORT}/api/auth/health-check ..." | ||
|
||
for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10 | ||
do | ||
echo "> #${RETRY_COUNT} trying..." | ||
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${TARGET_PORT}/api/auth/health-check) | ||
|
||
if [ ${RESPONSE_CODE} -eq 200 ]; then | ||
echo "> New WAS successfully running" | ||
exit 0 | ||
elif [ ${RETRY_COUNT} -eq 10 ]; then | ||
echo "> Health check failed." | ||
exit 1 | ||
fi | ||
sleep 10 | ||
|
||
# if [ ${CURRENT_PORT} -eq ${TARGET_PORT} ]; then | ||
# echo "> Health Check Failed." | ||
# exit 1 | ||
# else | ||
# echo "> New WAS Successfully running." | ||
# exit 0 | ||
# fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# run_new_was.sh | ||
|
||
#!/bin/bash | ||
|
||
# 현재 포트 읽어오기 | ||
CURRENT_PORT=$(cat /home/ubuntu/service_url.inc | grep -Po '[0-9]+' | tail -1) | ||
TARGET_PORT=0 | ||
|
||
echo "> Current port of running WAS is ${CURRENT_PORT}." | ||
|
||
# 현재 포트가 8081이면 새로 WAS를 띄울 타겟 포트는 8082, 반대라면 8081 | ||
if [ ${CURRENT_PORT} -eq 8081 ]; then | ||
TARGET_PORT=8082 | ||
elif [ ${CURRENT_PORT} -eq 8082 ]; then | ||
TARGET_PORT=8081 | ||
else | ||
echo "> No WAS is connected to nginx" | ||
fi | ||
|
||
TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') | ||
|
||
# 만약 타겟 포트에도 WAS가 떠있다면, kill하고 새롭게 WAS를 띄움 | ||
if [ ! -z ${TARGET_PID} ]; then | ||
echo "> Kill WAS running at ${TARGET_PORT}." | ||
sudo kill ${TARGET_PID} | ||
fi | ||
|
||
nohup java -jar -Dserver.port=${TARGET_PORT} /home/ubuntu/app/build/libs/* > /home/ubuntu/nohup.out 2>&1 & | ||
echo "> Now new WAS runs at ${TARGET_PORT}." | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# switch.sh | ||
|
||
#!/bin/bash | ||
|
||
# Crawl current connected port of WAS | ||
CURRENT_PORT=$(cat /home/ubuntu/service_url.inc | grep -Po '[0-9]+' | tail -1) | ||
TARGET_PORT=0 | ||
|
||
echo "> Nginx currently proxies to ${CURRENT_PORT}." | ||
|
||
# Toggle port number | ||
if [ ${CURRENT_PORT} -eq 8081 ]; then | ||
TARGET_PORT=8082 | ||
elif [ ${CURRENT_PORT} -eq 8082 ]; then | ||
TARGET_PORT=8081 | ||
else | ||
echo "> No WAS is connected to nginx" | ||
exit 1 | ||
fi | ||
|
||
# Change proxying port into target port | ||
echo "set \$service_url http://127.0.0.1:${TARGET_PORT};" | tee /home/ubuntu/service_url.inc | ||
|
||
echo "> Now Nginx proxies to ${TARGET_PORT}." | ||
|
||
# Reload nginx | ||
sudo service nginx reload | ||
|
||
echo "> Nginx reloaded." |