Skip to content

Commit

Permalink
feat: 배포 스크립트 추가 및 자동배포 스크립트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wwingyou committed Apr 7, 2024
1 parent 865228f commit ea32068
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auto-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
- name: Upload deployment scripts
run: |
sudo chmod 755 JWT/deploy/*
scp -i private_key.pem -r JWT/deploy "${username}@${host}:~"
sudo chmod 755 script/deploy/*
scp -i private_key.pem -r script/deploy/* "${username}@${host}:deploy"
- name: Kill current running Spring process
run: ssh -i private_key.pem "${username}@${host}" "deploy/shutdown.sh; deploy/backup.sh"
Expand Down
13 changes: 13 additions & 0 deletions script/deploy/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# 기존 프로세스를 shutdown 후 새 jar를 배포하기 전 기존 jar를 백업하는 용도로 쓰인다.
# server.jar 파일이 있다면 server.bak.jar로 백업하고, 아니면 아무것도 하지 않는다.

if [ -f server.jar ]; then
sudo mv server.jar server.bak.jar
echo "server.bak.jar created."
exit 0
fi

echo "no server.jar file found."
exit 0
12 changes: 12 additions & 0 deletions script/deploy/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# 서버가 실행중인지 확인한다.

pid=$(sudo lsof -t -i :8080)

if [ -z "$pid" ]; then
echo "Error: server is not running."
exit 1
fi

echo "PID '${pid}' is running on port 8080."
32 changes: 32 additions & 0 deletions script/deploy/check_and_recover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# 서버의 상태를 확인하여 실행시 실패했다면 복구한다.

pid=$(sudo lsof -t -i :8080)

if [ -z "$pid" ]; then
echo "Error: server is not running."

echo
echo "========= ERROR LOG =========="
cat out.log
echo "========== LOG END ==========="
echo

script_dir=$(dirname "$0")

if [ -f "server.bak.jar" ]; then
sudo mv server.bak.jar server.jar
echo "backup jar recovered."

"${script_dir}/startup.sh"
exit 1
fi

echo "recovory fail: no backup jar file found"
exit 2

fi

echo "PID '${pid}' is running on port 8080."

22 changes: 22 additions & 0 deletions script/deploy/recover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# 새로운 jar 배포가 실패했을 때 백업된 기존 jar 로 다시 서버를 시작한다.

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
12 changes: 12 additions & 0 deletions script/deploy/shutdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# 기존 server 프로세스를 끝낸다.

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."
13 changes: 13 additions & 0 deletions script/deploy/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# server.jar 로 새로운 서버 프로세스를 실행한다.

pid=$(sudo lsof -t -i :8080)

if [ -n "$pid" ]; then
echo "Error: PID '${pid}' is conneted to port 8080. cannot startup new process."
exit 1
fi
nohup java -jar server.jar --spring.profiles.active=dev > out.log 2>&1 & disown
echo "server started at port 8080."
echo "stdout & stderr directed to 'out.log'"

0 comments on commit ea32068

Please sign in to comment.