Weekly devIL 8

임선용·2022년 7월 3일
0

트러블 슈팅

  • 0627
    • CICD 작업 이후 프로젝트 명 변경으로 인한 서버 에러 발생

      REPOSITORY=/home/ubuntu/
      cd $REPOSITORY
      
      APP_NAME=marketclip
      JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1)
      JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME
      
      CURRENT_PID=$(pgrep -f $APP_NAME)
      
      echo ">현재 구동 중인 애플리케이션 pid: $CURRENT_PID"
      
      if [ -z $CURRENT_PID ]
      then
        echo ">현재 구동 중인 애플리케이션이 없으므로 종료하지 않습니다."
      else
        echo "> kill -9 $CURRENT_PID"
        sudo kill -15 $CURRENT_PID
        sleep 5
      fi
    • 프로젝트 명 변경으로 인해 kill 명령어가 실행되지 않아서 일어나는 오류

      해결 - 단순히 EC2의 (전 프로젝트명의)프로젝트를 강제적으로 kill하고 재실행 해줬다

  • 0629

    • 이메일 인증번호를 생성하는 방법 ( Random String )
    1. random 클래스를 사용하여 97~122 사이의 난수를 생성하고 char로 변환한 다음 (a~z) StringBuilder에 하나씩 더해준다
      → 힙 메모리(Heap)에 많은 임시 가비지(Garbage)가 생성돼서 사용을 지양했다. (물론 GC(garbage collection)가 처리해주긴 하지만)

      // 1. Random을 이용해 
      int leftLimit = 97; // letter 'a'
      int rightLimit = 122; // letter 'z'
      int targetStringLength = 10;
      Random random = new Random();
      StringBuilder buffer = new StringBuild(targetStringLength);
      for (int i = 0; i < targetStringLength; i++) {
          int randomLimitedInt = leftLimit + (int)
                  (random.nextFloat() * (rightLimit - leftLimit + 1));
          buffer.append((char) randomLimitedInt);
      }
      String generatedString = buffer.toString()
      System.out.println(generatedString);
    2. UUID를 생성해 subString으로 잘라쓰는 방법

      import java.util.UUID;
      
      	String uuid = UUID.randomUUID().toString();
      	String randomString = uuid.substring(0,8);
    3. apache.commons.lang 을 사용하여 랜덤 스트링 생성
      쉽고 편하게 만들 수 있다 + 길이, 숫자와 문자여부 등 변경이 자유롭다

      import org.apache.commons.lang3.RandomStringUtils;
      
      	String randomString = RandomStringUtils.random(8, true, true);
  • 0702

    • GlobalExceptionHandler를 이용하여 예외 처리를 실행하는데,
      편의를 위하여 성공한 응답도 GlobalExceptionHandler로 처리해도 되는지?
    • 400 / BAD_REQUEST 예시
    • 200 / OK 예시
    • 추가) 업데이트를 실행할 때, 성공한 응답을 GlobalExceptionHandler로 처리하게 되면 @Transactional이 실행이 되지 않는 문제 발생
    • 해결) ✅ 성공한 응답을 Exception으로 throw 처리하지 않고, 메서드의 리턴 타입을 ResponseEntity로 설정해 throw가 아닌 return값으로 받게 처리. ✅
  • 0702

    • 깃헙액션 CI/CD 에러 이유

    • application.properties 생성 불가

      이유 - .gitignore로 applications.properties를 제외하고 프로젝트를 올릴 때

      ./src/main/resources 의 경로에 있는 파일이 applications.properties하나이기 때문에

      디렉토리들도 제외하고 올려진다 (파일이 없는 빈 디렉토리들은 무시됨)

      따라서 main.yml에 작성한 cd ./src/main/resources 에서 에러가 생긴다

      main.yml

      - name: application.properties 생성
              # branch가 main일 때
              if: true
              run: |
                # spring의 resources 경로로 이동
                cd ./src/main/resources
                touch ./application.properties
                # GitHub-Actions에서 설정한 값을 application.properties 파일에 쓰기
                echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./application.properties

      해결) ✅ resources 디렉토리에 일단 applications.dev.properties를 추가하여 해결 ✅ 했지만, mvp를 구현하고 난 이후 applications.properties를 ignore하지 않고, 중요한 정보는 다른 곳에서 import받아 사용하는 방식으로 변경할 예정

profile
백엔드 개발 공부중

0개의 댓글