Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 배포 스크립트에 복구 기능 추가 #9

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions JWT/deploy/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sudo mv server.jar server.bak.jar
22 changes: 22 additions & 0 deletions JWT/deploy/recover.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion JWT/deploy/runner.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions JWT/deploy/shutdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
13 changes: 13 additions & 0 deletions JWT/deploy/startup.sh
Original file line number Diff line number Diff line change
@@ -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
Loading