-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[DEPLOY] nginx 무중단 배포 설정
- Loading branch information
Showing
5 changed files
with
121 additions
and
7 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
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,35 @@ | ||
# health_check.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://127.0.0.1:${TARGET_PORT}' ..." | ||
|
||
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://127.0.0.1:${TARGET_PORT}/health) | ||
|
||
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 | ||
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,31 @@ | ||
# 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}." | ||
|
||
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]+') | ||
|
||
if [ ! -z ${TARGET_PID} ]; then | ||
echo "> Kill WAS running at ${TARGET_PORT}." | ||
sudo kill ${TARGET_PID} | ||
fi | ||
|
||
nohup java -jar \ | ||
-Dserver.port=${TARGET_PORT} \ | ||
-Dspring.config.location=/home/ubuntu/app/application.yml \ | ||
/home/ubuntu/app/build/libs/* > /home/ubuntu/nohup.out 2>&1 & | ||
echo "> Now new WAS runs at ${TARGET_PORT}." | ||
sleep 10s | ||
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." |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/favoriteplace/app/controller/HealthCheckController.java
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,17 @@ | ||
package com.favoriteplace.app.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HealthCheckController { | ||
|
||
@GetMapping("/health") | ||
public String hello(){ | ||
return "hello success!"; | ||
} | ||
|
||
} |