 
 
 
#!/bin/bash
REPOSITORY=/home/ec2-user/{앱이있는 경로}
PROJECT_NAME={자신의 프로젝트 이름}
echo "> Build 파일 복사"
cp $REPOSITORY/zip/*.jar $REPOSITORY/
echo "> 현재 구동중인 애플리케이션 pid확인"
CURRENT_PID=$(pgrep -fl pjh-server | grep jar | awk '{print $1}')
echo "현재 구동중인 애플리케이션 pid : $CURRENT_PID"
if [ -z "$CURRENT_PID"  ];  then
  echo "> 현재 구동 중인 애플리케이션이 없으므로 종료하지 않습니다."
else
  echo "> kill -15 $CURRENT_PID"
  kill -15 $CURRENT_PID
  sleep 5
fi
echo "> 새 애플리케이션 배포"
JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tail -n 1)
echo "> JAR Name: $JAR_NAME"
echo "> $JAR_NAME 에 실행권한 추가"
chmod +x $JAR_NAME
echo "> $JAR_NAME 실행"
nohup java -jar \
    -Dspring.config.location=classpath:/application.properties,
    classpath:application-real.properties,/home/ec2-user/app/application-real-db.properties \
    -Dspring.profiles.active=real \
    $JAR_NAME > $REPOSITORY/nohup.out 2>&1 & 
코드 설명
cp $REPOSITORY/zip/*.jar $REPOSITORY/
CURRENT_PID=$(pgrep -fl pjh-server | grep jar | awk '{print $1}')
if [ -z "$CURRENT_PID"  ];
kill -15 $CURRENT_PID
$(ls -tr $REPOSITORY/*.jar | tail -n 1)
chmod +x $JAR_NAME
nohup java -jar \
    -Dspring.config.location=classpath:/application.properties,classpath:/application-real.properties,/home/ec2-user/app/application-real-db.properties \
    -Dspring.profiles.active=real \
    $JAR_NAME > $REPOSITORY/nohup.out 2>&1 &
language: java
jdk:
  - openjdk8
branches:
  only:
    - master
# Travis CI 서버의 Cache 활성화
cache:
  directories:
    - '$HOME/.m2/repository'
    - '$HOME/.gradle'
# clean 후 Build (Build시 자동으로 test 수행)
script: "./gradlew clean build"
before_deploy:
  - mkdir -p before-deploy # zip에 포함시킬 파일들을 담을 디렉토리 생성
  - cp scripts/*.sh before-deploy/
  - cp appspec.yml before-deploy/
  - cp build/libs/*.jar before-deploy/
  - cd before-deploy && zip -r before-deploy * # before-deploy로 이동후 전체 압축
  - cd ../ && mkdir -p deploy # 상위 디렉토리로 이동후 deploy 디렉토리 생성
  - mv before-deploy/before-deploy.zip deploy/{프로젝트이름}.zip
before_install:
  - chmod +x gradlew
# CI 실행 완료시 메일 알림
notifications:
  email:
    recipients:
      - {이메일}
version: 0.0
os: linux
files:
  - source:  /
    destination: /home/ec2-user/{압축파일경로}
    overwrite: yes
permissions:
  - object: /
    pattern: "**"
    owner: ec2-user
    group: ec2-user
hooks:
  ApplicationStart:
    - location: deploy.sh
      timeout: 60
      runas: ec2-user