From 14ad25b22d56ac5ae524bc73cdfa5768ee43bc06 Mon Sep 17 00:00:00 2001 From: wingyou Date: Mon, 25 Mar 2024 16:03:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=EC=97=90=20=EB=B3=B5=EA=B5=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이제 shutdown.sh 실행 후 backup.sh 를 실행하여 기존 jar 파일을 백업해야 합니다. - 배포후 서버 시작은 startup.sh를 사용합니다. 배포과정에서 문제가 발생할 경우 기존에 백업된 jar 파일으로 복구 후 자동으로 재시작합니다. --- JWT/deploy/backup.sh | 3 +++ JWT/deploy/recover.sh | 22 ++++++++++++++++++++++ JWT/deploy/runner.sh | 17 ++++++++++++++++- JWT/deploy/shutdown.sh | 4 ++++ JWT/deploy/startup.sh | 13 +++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 JWT/deploy/backup.sh create mode 100755 JWT/deploy/recover.sh mode change 100644 => 100755 JWT/deploy/runner.sh create mode 100755 JWT/deploy/startup.sh diff --git a/JWT/deploy/backup.sh b/JWT/deploy/backup.sh new file mode 100755 index 0000000..22cf7c1 --- /dev/null +++ b/JWT/deploy/backup.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sudo mv server.jar server.bak.jar diff --git a/JWT/deploy/recover.sh b/JWT/deploy/recover.sh new file mode 100755 index 0000000..723dfb9 --- /dev/null +++ b/JWT/deploy/recover.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# use this script when new jar file exit with unexpected error. + +script_dir=$(dirname "$0") + +if [ -f "server.bak.jar" ]; then + sudo mv server.bak.jar server.jar + echo "backup jar recovered." + "${script_dir}/runner.sh" server.jar + exit_code=$? + + if [ $exit_code -ne 0 ]; then + echo "recovory fail: error occured starting backup jar." + exit 1 + fi + + exit 0 +fi + +echo "recovory fail: no backup jar file found" +exit 2 diff --git a/JWT/deploy/runner.sh b/JWT/deploy/runner.sh old mode 100644 new mode 100755 index a414ceb..7a31d29 --- a/JWT/deploy/runner.sh +++ b/JWT/deploy/runner.sh @@ -1,3 +1,18 @@ #!/bin/bash -nohup java -jar $1 --spring.profiles.active=dev 2>&1 & +nohup java -jar $1 --spring.profiles.active=dev 2>&1 > out.log & + +echo "waiting for server to startup..." +sleep 60 + +# after sleep, check server is still running. +pid=$(sudo lsof -t -i :8080) + +if [ -z "$pid" ]; then + echo "!server startup failed!" + echo "check out.log to see what happend." + exit 1 +fi + +echo "${pid} is successfully running on port 8080." +exit 0 diff --git a/JWT/deploy/shutdown.sh b/JWT/deploy/shutdown.sh index e32c7a5..9b75da3 100755 --- a/JWT/deploy/shutdown.sh +++ b/JWT/deploy/shutdown.sh @@ -3,4 +3,8 @@ pid=$(sudo lsof -t -i :8080) if [ -n "$pid" ]; then kill $pid + echo "${pid} closed." + exit 0 fi + +echo "no process running on port 8080." diff --git a/JWT/deploy/startup.sh b/JWT/deploy/startup.sh new file mode 100755 index 0000000..b76d5d0 --- /dev/null +++ b/JWT/deploy/startup.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# startup fresh deployed jar file + +script_dir=$(dirname "$0") + +"${script_dir}/runner.sh" server.jar +exit_code=$? + +if [ $exit_code -ne 0 ]; then + "${script_dir}/recover.sh" + exit 1 +fi