Spring Boot 시작,정지,재 부팅,상태 스 크 립 트

이 스 크 립 트 는 SpringBoot 프로젝트 의 프로 세 스 상 태 를 관리 하 는 데 사 용 됩 니 다.
알림 기능 이 있 습 니 다.
프로젝트 폴 더 에 스 크 립 트 를 잃 어 버 리 고 실행 권한 을 추가 하면 됩 니 다.
이 스 크 립 트 를 사용 하려 면 자바-jar 명령 전에BUILD_ID=dontKillMe를 추가 해 야 합 니 다.그렇지 않 으 면 젠 킨 스 는 프로 세 스 를 죽 일 것 입 니 다.
참고:
https://stackoverflow.com/questions/39169457/how-to-tell-jenkins-not-to-kill-processes-after-successful-execution-of-job-in-m
스 크 립 트 유 지 는 github 에 있 습 니 다.필요 하 다 면 주목 할 수 있 습 니 다.
https://github.com/junbaor/shell_script/blob/master/spring-boot.sh

spring-boot.sh

#!/bin/bash

SpringBoot=$2

if [ "$1" = "" ];
then
    echo -e "\033[0;31m        \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
    exit 1
fi

if [ "$SpringBoot" = "" ];
then
    echo -e "\033[0;31m        \033[0m"
    exit 1
fi

function start()
{
    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "$SpringBoot is running..."
    else
        echo "Start $SpringBoot success..."
        nohup java -jar $SpringBoot > /dev/null 2>&1 &
    fi
}

function stop()
{
    echo "Stop $SpringBoot"
    boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

    if [ $count != 0 ];then
        kill $boot_id
        count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

        boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
        kill -9 $boot_id
    fi
}

function restart()
{
    stop
    sleep 2
    start
}

function status()
{
    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "$SpringBoot is running..."
    else
        echo "$SpringBoot is not running..."
    fi
}

case $1 in
    start)
    start;;
    stop)
    stop;;
    restart)
    restart;;
    status)
    status;;
    *)

    echo -e "\033[0;31m Usage: \033[0m  \033[0;34m sh  $0  {start|stop|restart|status}  {SpringBootJarName} \033[0m
\033[0;31m Example: \033[0m
      \033[0;33m sh  $0  start esmart-test.jar \033[0m"
esac
Spring Boot 예제 튜 토리 얼 과 원본 코드 가 업로드 되 었 습 니 다:
https://github.com/javastacks/spring-boot-best-practice
이상 은 Spring Boot 시작,정지,재 부팅,상태 스 크 립 트 의 상세 한 내용 입 니 다.Spring Boot 시작 스 크 립 트 에 대한 자 료 는 다른 관련 글 을 주목 하 십시오!

좋은 웹페이지 즐겨찾기