#!/bin/bash
GITHUB_ID="codingspecialist"
PROJECT_NAME="aws-v2-last"
PROJECT_VERSION="0.0.2"
PROJECT_PID="$(pgrep -f ${PROJECT_NAME}-${PROJECT_VERSION}.jar)"
JAR_PATH="${HOME}/${PROJECT_NAME}/build/libs/${PROJECT_NAME}-${PROJECT_VERSION}.jar"
export GITHUB_ID
export PROJECT_NAME
export PROJECT_VERSION
export PROJECT_PID
export JAR_PATH
#!/bin/bash
source ./var.sh
if [ -z "$PROJECT_PID" ]; then
nohup java -jar -Dspring.profiles.active=prod ${JAR_PATH} 1>${HOME}/log.out 2>${HOME}/err.out &
fi
source XX환경_설정_파일명XX
#!/bin/bash
# 1. env variable
source ./var.sh
echo "1. env variable setting complete"
# 2. clone delete
touch crontab_delete
crontab crontab_delete
rm crontab_delete
echo "2. cron delete complete"
# 3. server checking
if [ -n "${PROJECT_PID}" ]; then
# re deploy
kill -9 $PROJECT_PID
echo "3. project kill complete"
else
# first deploy
# 3-1 apt update
sudo apt-get update -y 1>/dev/null
echo "3-1. apt-get update complete"
# 3-2 jdk install
sudo apt-get -y install openjdk-11-jdk 1>/dev/null
echo "3-2. jdk install complete"
# 3-3 timezone
sudo timedatectl set-timezone Asia/Seoul
echo "3-3. timezone setting complete"
fi
# 4. project folder delete
rm -rf ${HOME}/${PROJECT_NAME}
echo "4. project folder delete complete"
# 5. git clone
git clone https://github.com/${GITHUB_ID}/${PROJECT_NAME}.git
sleep 3s
echo "5. git clone complete"
# 6. gradlew +x
chmod u+x ${HOME}/${PROJECT_NAME}/gradlew
echo "6. gradlew u+x complete"
# 7. build
cd ${HOME}/${PROJECT_NAME}
./gradlew build
echo "7. gradlew build complete"
# 8. start jar
nohup java -jar -Dspring.profiles.active=prod ${JAR_PATH} 1>${HOME}/log.out 2>${HOME}/err.out &
echo "8. start server complete"
# 9. cron registration
touch crontab_new
echo "* * * * * ${HOME}/check-and-restart.sh" 1>>crontab_new
# register the others.... you see >> (append)
crontab crontab_new
rm crontab_new
echo "9. cron registration complete"
touch XXfile-nameXX
: 파일 생성chmod u+x XXfile-or-folder-nameXX
: 파일 또는 폴더 권한 설정crontab XXXX
: cron 적용chmod u+x
실행 권한 부여
./deploy.sh
스크립트 실행
(repository code 이용) codingspecialist/aws-v2-last