Skip to content

Commit

Permalink
🐛: bugfix 로깅 시에 Permission Denied로 인한 문제 해결 #49
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Dec 6, 2023
1 parent 115ba11 commit 8cd1638
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions scripts/health_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ if [ ${CURRENT_PORT} -eq 8081 ]; then
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "[$NOW_TIME] No WAS is connected to nginx" >> /home/ubuntu/api-server/deploy_err.log
echo "[$NOW_TIME] No WAS is connected to nginx"
exit 1
fi

echo "[$NOW_TIME] Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..." >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..."

for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10
do
echo "[$NOW_TIME] #${RETRY_COUNT} trying..." >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] #${RETRY_COUNT} trying..."
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/actuator/health)

if [ ${RESPONSE_CODE} -eq 200 ]; then
echo "[$NOW_TIME] New WAS successfully running" >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] New WAS successfully running"
exit 0
elif [ ${RETRY_COUNT} -eq 10 ]; then
echo "[$NOW_TIME] Health check failed." >> /home/ubuntu/api-server/deploy_err.log
echo "[$NOW_TIME] Health check failed."
exit 1
fi
sleep 10
done
done
14 changes: 7 additions & 7 deletions scripts/run_new_was.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ HOST_NAME=$(cat /etc/hostname)
CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0

echo "[$NOW_TIME] Current port of running WAS is ${CURRENT_PORT}." >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] Current port of running WAS is ${CURRENT_PORT}."

if [ ${CURRENT_PORT} -eq 8081 ]; then
TARGET_PORT=8082
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "[$NOW_TIME] No WAS is connected to nginx" >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] No WAS is connected to nginx"
fi

TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')

if [ ! -z ${TARGET_PID} ]; then
echo "[$NOW_TIME] Kill WAS running at ${TARGET_PORT}." >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] Kill WAS running at ${TARGET_PORT}."
sudo kill ${TARGET_PID}
fi

if [ ${HOST_NAME} == "core-prod-server" ]; then
nohup java -jar -Dserver.port=${TARGET_PORT} -Duser.timezone=Asia/Seoul -Dspring.profiles.active=prod /home/ubuntu/api-server/*.jar >> /home/ubuntu/api-server/deploy.log 2>/home/ubuntu/api-server/deploy_err.log &
echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/api-server/deploy.log
nohup java -jar -Dserver.port=${TARGET_PORT} -Duser.timezone=Asia/Seoul -Dspring.profiles.active=prod /home/ubuntu/api-server/*.jar &
echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}."
exit 0
else
nohup java -jar -Dserver.port=${TARGET_PORT} -Duser.timezone=Asia/Seoul -Dspring.profiles.active=dev /home/ubuntu/api-server/*.jar >> /home/ubuntu/api-server/deploy.log 2>/home/ubuntu/api-server/deploy_err.log &
echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/api-server/deploy.log
nohup java -jar -Dserver.port=${TARGET_PORT} -Duser.timezone=Asia/Seoul -Dspring.profiles.active=dev /home/ubuntu/api-server/*.jar &
echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}."
exit 0
fi
8 changes: 4 additions & 4 deletions scripts/switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S
CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0

echo "[$NOW_TIME] Nginx currently proxies to ${CURRENT_PORT}." >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] 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 "[$NOW_TIME] No WAS is connected to nginx" >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] 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};" | sudo tee /etc/nginx/conf.d/service-url.inc

echo "[$NOW_TIME] Now Nginx proxies to ${TARGET_PORT}." >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] Now Nginx proxies to ${TARGET_PORT}."
# Reload nginx
sudo service nginx reload

echo "[$NOW_TIME] Nginx reloaded." >> /home/ubuntu/api-server/deploy.log
echo "[$NOW_TIME] Nginx reloaded."

0 comments on commit 8cd1638

Please sign in to comment.