9.生产部署-注意事项和如何使用脚本

一、 注意事项

1.去除不需要的 jar

开发工具 jar:spring-boot-devtools

2.日志打印方面注意

在不同的环境中应该配置的不同

3.监控一定要做好权限控制或者去除

控制 jar:spring-boot-starter-actuator

druid 的监控 swagger 的接口

4、打包,跳过测试

maven: clean package -Dmaven.test.skip=true

或者pom.xml的<properties>中加入配置

 <skipTests>true</skipTests>

二、 脚本

#!/bin/sh

## chang here
SERVICE_DIR=/demo/spring-boot-demo
SERVICE_NAME=spring-boot-demo-31-1-0.0.1-SNAPSHOT
SPRING_PROFILES_ACTIVE=dev

## java env
export JAVA_HOME=/opt/jdk1.7.0_79
export JRE_HOME=${JAVA_HOME}/jre

case "$1" in 
    start)
        procedure=`ps -ef | grep -w "${SERVICE_NAME}" |grep -w "java"| grep -v "grep" | awk '{print $2}'`
        if [ "${procedure}" = "" ];
        then
            echo "start ..."
            if [ "$2" != "" ];
            then
                SPRING_PROFILES_ACTIVE=$2
            fi
            echo "spring.profiles.active=${SPRING_PROFILES_ACTIVE}"
            exec nohup ${JRE_HOME}/bin/java -Xms128m -Xmx512m -jar ${SERVICE_DIR}/${SERVICE_NAME}\.jar --spring.profiles.active=${SPRING_PROFILES_ACTIVE} >/dev/null 2>&1 &
            echo "start success"
        else
            echo "${SERVICE_NAME} is start"
        fi
        ;;

    stop)
        procedure=`ps -ef | grep -w "${SERVICE_NAME}" |grep -w "java"| grep -v "grep" | awk '{print $2}'`
        if [ "${procedure}" = "" ];
        then
            echo "${SERVICE_NAME} is stop"
        else
            kill -9 ${procedure}
            sleep 1
            argprocedure=`ps -ef | grep -w "${SERVICE_NAME}" |grep -w "java"| grep -v "grep" | awk '{print $2}'`
            if [ "${argprocedure}" = "" ];
            then
                echo "${SERVICE_NAME} stop success"
            else
                kill -9 ${argprocedure}
                echo "${SERVICE_NAME} stop error"
            fi
        fi
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start $2
        ;;  

    *)
        echo "usage: $0 [start|stop|restart] [dev|test|prod]"
        ;;  
esac

资料

springboot如何测试打包部署

Last updated