[AWS] EC2서버 접속하기 - 11 ( Cron 으로 프로젝트 재시작, stop,restart )

 

1 . 우선 /home/ubuntu/cron-restat.sh 파일 생성

mkdir cron-restart.sh

 

 

2. spring-stop.sh 파일 실행파일 생성

 

vi spring-stop.sh


( 안에내용 )

echo "SPRINGBOOT STOP....."

SPRING_PID=$(pgrep -f v1-0.0.1-SNAPSHOT.jar)

kill -9 $SPRING_PID



( 권한 설정 )

chmod u+x spring-stop.sh

 

 

3. spring-restart.sh 실행파일 생성

vi spring-restart.sh  


(안에 내용 )

SPRING_PID=$(pgrep -f v1-0.0.1-SNAPSHOT.jar)
SPRING_PATH="/home/ubuntu/aws-v1/build/libs/v1-0.0.1-SNAPSHOT.jar"


echo $SPRING_PID
echo $SPRING_PATH

# 조건식

if [ -z "$SPRING_PID" ]; then
  echo "스프링이 종료된 상태.."
  echo "스프링 재시작 - $(date)" 1>>/home/ubuntu/cron-restart/spring-restart.log
  nohup java -jar $SPRING_PATH 1>log1.out 2>error1.out &
else
  echo "스프링이 시작된상태.."  
fi

 

 

 

 

 

4. deploy.sh 실행파일

 

# 1.배포 프로세스

echo "deploy start.... 기존 서버가 시작되어 있다면 종료를 하고 배포를 시작해야함"
echo "1. JDK install"
echo "2. github project Download"
echo "3. gradlew 실행권한 주기"
echo "4. project build 하기"
echo "5. ubuntu timeozne setting 하기"
echo "6. nohup 으로 springboot 실행시키기"

# 2. 스프링서버 종료시 재시작
echo "crontab 등록 - spring restart..."
crontab -l > crontab_new
echo "* * * * * /home/ubuntu/cron-restart/spring-restart.sh" 1>>crontab_new
crontab crontab_new
rm crontab_new

 

 

해당강의는 아이티윌  국비지원센터

 

최주호님의 AWS 강의를 듣고 블로그에 기록해두는 용입니다.

https://www.e-itwill.com/course/course_view.jsp?id=123& 

 

아이티윌 K-디지털 기초역량훈련 온라인 센터

아이티윌 온라인 국비지원교육 전용 사이트. K-디지털 기초역량훈련 과정. 국민내일배움카드 전용 강좌 진행중.

www.e-itwill.com