shell 管理SpringBoot 生产环境服务

来源:互联网 发布:centos7 更新 PHP 编辑:程序博客网 时间:2024/06/06 04:57

Spring Boot 在生产环境中运行如果是用maven 打包为jar 运行那么再关闭 重启服务这样每次在操作的时候就非常不方便 这里写了个shell 脚本统一管理

# description: Auto-starts bootTag="PublishImageApplication"MainClass="com.yoke.PublishImageApplication"Lib="/test/lib/"Log="/test/run.log"echo $TagRETVAL="0"# See how we were called.function start() {    echo  $Log     if [ ! -f $Log ]; then        touch $Log    fi    nohup java -Dappliction=$Tag -Djava.ext.dirs=$Lib":${JAVA_HOME}/jre/lib/ext" $MainClass > $Log 2>&1 &      tailf $Log}function stop() {    pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')    if [ "$pid" != "" ]; then              echo -n "boot ( pid $pid) is running"         echo         echo -n $"Shutting down boot: "        pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')        if [ "$pid" != "" ]; then            echo "kill boot process"            kill -9 "$pid"        fi        else              echo "boot is stopped"         fi    status}function status(){    pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')    #echo "$pid"    if [ "$pid" != "" ]; then        echo "boot is running,pid is $pid"    else        echo "boot is stopped"    fi}function usage(){   echo "Usage: $0 {start|stop|restart|status}"   RETVAL="2"}# See how we were called.RETVAL="0"case "$1" in    start)        start        ;;    stop)        stop        ;;    restart)        stop        start        ;;    reload)        RETVAL="3"        ;;    status)        status        ;;    *)      usage      ;;esacexit $RETVAL

Tag: 在中起着标识程序运行标志,如果服务器运行多个java 程序需用java 的 -Dappliction 来区分对应程序

MainClass: 是对应程序的运行的SpringBoot main 类

Lib:是boot程序在生产服务器环境中的所有jar 路径

Log:是记录boot程序运行所有日志保存路径

如脚本在
/boot/run_boot.sh
启动命令: /boot/run_boot.sh start
重启命令: /boot/run_boot.sh restart
关闭命令: /boot/run_boot.sh stop
是否运行: /boot/run_boot.sh status

阅读全文
0 0