-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
96 lines (81 loc) Β· 2.61 KB
/
deploy.sh
File metadata and controls
96 lines (81 loc) Β· 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
BUILD_PATH=$(ls /home/ubuntu/app/server-0.0.1-SNAPSHOT.jar)
JAR_NAME=$(basename $BUILD_PATH)
echo "> build νμΌλͺ
: $JAR_NAME"
echo "> build νμΌ λ³΅μ¬"
DEPLOY_PATH=/home/ubuntu/app/nonstop/jar/
cp $BUILD_PATH $DEPLOY_PATH
echo "> νμ¬ κ΅¬λμ€μΈ Set νμΈ"
CURRENT_PROFILE=$(curl -s http://localhost/profile)
echo "> $CURRENT_PROFILE"
# μ¬κ³ μλ set μ°ΎκΈ°: set1μ΄ μ¬μ©μ€μ΄λ©΄ set2κ° μ¬κ³ μκ³ , λ°λλ©΄ set1μ΄ μ¬κ³ μμ
if [ $CURRENT_PROFILE == set1 ]
then
IDLE_PROFILE=set2
IDLE_PORT=8082
elif [ $CURRENT_PROFILE == set2 ]
then
IDLE_PROFILE=set1
IDLE_PORT=8081
else
echo "> μΌμΉνλ Profileμ΄ μμ΅λλ€. Profile: $CURRENT_PROFILE"
echo "> set1μ ν λΉν©λλ€. IDLE_PROFILE: set1"
IDLE_PROFILE=set1
IDLE_PORT=8081
fi
echo "> application.jar κ΅μ²΄"
IDLE_APPLICATION=$IDLE_PROFILE-Runnect-Spring-Boot-Server.jar
IDLE_APPLICATION_PATH=$DEPLOY_PATH$IDLE_APPLICATION
ln -Tfs $DEPLOY_PATH$JAR_NAME $IDLE_APPLICATION_PATH
echo "> $IDLE_PROFILE μμ ꡬλμ€μΈ μ ν리μΌμ΄μ
pid νμΈ"
IDLE_PID=$(pgrep -f $IDLE_APPLICATION)
if [ -z $IDLE_PID ]
then
echo "> νμ¬ κ΅¬λμ€μΈ μ ν리μΌμ΄μ
μ΄ μμΌλ―λ‘ μ’
λ£νμ§ μμ΅λλ€."
else
echo "> kill -15 $IDLE_PID"
kill -15 $IDLE_PID
sleep 20
fi
echo "> $IDLE_PROFILE λ°°ν¬"
nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &
echo "> $IDLE_PROFILE 10μ΄ ν Health check μμ"
echo "> curl -s http://localhost:$IDLE_PORT/health "
sleep 10
for retry_count in {1..10}
do
response=$(curl -s http://localhost:$IDLE_PORT/actuator/health)
up_count=$(echo $response | grep 'UP' | wc -l)
if [ $up_count -ge 1 ]
then # $up_count >= 1 ("UP" λ¬Έμμ΄μ΄ μλμ§ κ²μ¦)
echo "> Health check μ±κ³΅"
break
else
echo "> Health checkμ μλ΅μ μ μ μκ±°λ νΉμ statusκ° UPμ΄ μλλλ€."
echo "> Health check: ${response}"
fi
if [ $retry_count -eq 10 ]
then
echo "> Health check μ€ν¨. "
echo "> Nginxμ μ°κ²°νμ§ μκ³ λ°°ν¬λ₯Ό μ’
λ£ν©λλ€."
exit 1
fi
echo "> Health check μ°κ²° μ€ν¨. μ¬μλ..."
sleep 10
done
echo "> Nginx μν νμΈ"
if ! sudo systemctl is-active --quiet nginx; then
echo "> Nginxκ° μ€μ§λμ΄ μμ΅λλ€. μ¬μμν©λλ€."
sudo systemctl start nginx
sleep 2
if sudo systemctl is-active --quiet nginx; then
echo "> Nginx μ¬μμ μ±κ³΅"
else
echo "> Nginx μ¬μμ μ€ν¨."
fi
else
echo "> Nginx μ μ ꡬλ μ€"
fi
echo "> μ€μμΉ"
sleep 10
/home/ubuntu/app/nonstop/switch.sh