Spring Boot(Maven) + Jenkins

in springboot •  7 years ago  (edited)
  1. 개요
  • jar 를 실행하는 Script를 Service(Daemon)에 등록하여, 배포 시간을 단축, Jenkins 설정을 간략화.
    Service(Daemon) :: Process가 떠 있으면서 Background에서 실행.
    System에 상주하여 주기적으로 혹은, 특정 상태에 따라 동작하는 프로그램.
    윈도우에서는 Serveice, Linux 계열에서는 Daemon이라 한다.
    Log를 찍지 않아 외부 Tomcat 보다 훨씬 깔끔하고, 배포 속도도 월등히 빠름.
    Log는 Project에서 설정한 File로 확인 가능( Logback 사용).

  • Styleshop + Enliple 연동 Project, Intellij 기준으로 작성.

  1. Workflow
    pom.xml :: packaging → jar
    스크린샷 2018-03-14 오전 11.00.35.png

    Service(daemon) 등록...
    vi 편집기로 Script 작성 :: sudo vi /etc/init.d/{SERVICE_NAME}
    #!bin/sh
    SERVICE_NAME={SERVICE_NAME}
    PATH_TO_JAR={JAR_PATH}
    PID_PATH_NAME={PID_PATH}
    JAVA={JAVA_PATH}
    JAVA_OPTS={JAVA_OPTION}
    case $1 in
    start)
    echo "Starting $SERVICE_NAME ..."
    if [ ! -f $PID_PATH_NAME ]; then
    nohup $JAVA $JAVA_OPTS -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null & echo $! > $PID_PATH_NAME
    echo "$SERVICE_NAME started ..."
    else
    echo "$SERVICE_NAME is already running ..."
    fi
    ;;
    stop)
    if [ -f $PID_PATH_NAME ]; then
    PID=$(cat $PID_PATH_NAME);
    echo "$SERVICE_NAME stoping ..."
    kill $PID;
    echo "$SERVICE_NAME stopped ..."
    rm $PID_PATH_NAME
    else
    echo "$SERVICE_NAME is not running ..."
    fi
    ;;
    restart)
    if [ -f $PID_PATH_NAME ]; then
    PID=$(cat $PID_PATH_NAME);
    echo "$SERVICE_NAME stopping ...";
    kill $PID;
    echo "$SERVICE_NAME stopped ...";
    rm $PID_PATH_NAME
    echo "$SERVICE_NAME starting ..."
    nohup $JAVA $JAVA_OPTS -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null & echo $! > $PID_PATH_NAME
    echo "$SERVICE_NAME started ..."
    else
    echo "$SERVICE_NAME is not running ..."
    fi
    ;;
    esac
    {SERVICE_NAME} :: 등록할 Service(Daemon) 명
    {JAR_PATH} :: Jar File Full Path
    {PID_PATH_NAME} :: Process ID가 저장될 Path/이름... ex. /temp/styleshop-pid
    {JAVA_PATH} :: Java 실행 File Path.. Java가 환경변수로 잡혀있지 않으면 Full Path..
    {JAVA_OPTION} :: Java VM Option..

    Service 권한 등록
    sudo chmod +x /etc/init.d/{SERVICE_NAME}

    Jenkins 등록
    General, 소스코드 관리, 빌드 유발, 빌드 환경은 타 Project 와 동일
    스크린샷 2018-03-15 오후 5.00.41.png
    스크린샷 2018-03-15 오후 5.01.03.png
    SSH Server :: Project Server
    Source file :: Build 후 가져올 jar file Path.... ex. */.jar
    Remove prefix :: 제외할 Directory Path... (질문)
    Remote directory :: 배포할 Directory.
    Excute command :: 실행할 명령어.
    설정에 필요한 Directory는 사전 생성되어 있어야 한다.

참고 : http://heowc.tistory.com/77
http://heowc.tistory.com/38

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @coochadevteam! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You made your First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!