diff --git a/scripts/health_check.sh b/scripts/health_check.sh index 143d7c6..50ea9db 100644 --- a/scripts/health_check.sh +++ b/scripts/health_check.sh @@ -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 \ No newline at end of file +done diff --git a/scripts/run_new_was.sh b/scripts/run_new_was.sh index e84286d..3200ad0 100644 --- a/scripts/run_new_was.sh +++ b/scripts/run_new_was.sh @@ -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 diff --git a/scripts/switch.sh b/scripts/switch.sh index 4c90c36..59c0c81 100644 --- a/scripts/switch.sh +++ b/scripts/switch.sh @@ -3,7 +3,7 @@ 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 @@ -11,15 +11,15 @@ 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.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."