重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

springboot中的shell脚本怎么利用jar方式启动-创新互联

这篇文章将为大家详细讲解有关spring boot中的shell脚本怎么利用jar方式启动,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联是专业的彭泽网站建设公司,彭泽接单;提供成都网站建设、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行彭泽网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

用spring boot框架做的项目,将第三方包全部打在jar里面,通过shell脚本启动和停止服务,常用的shell脚本模板如下:

#!/bin/bash
JAVA_OPTIONS_INITIAL=-Xms128M
JAVA_OPTIONS_MAX=-Xmx512M
_JAR_KEYWORDS=monitor-alarm-task-1.0-SNAPSHOT.jar
APP_NAME=monitor-alarm-task
APPLICATION_FILE=/opt/scpip_monitor/application.properties
PID=$(ps aux | grep ${_JAR_KEYWORDS} | grep -v grep | awk '{print $2}' )
ALARM_CONFIG_FILE=`pwd`/alarmConfig.yaml


function check_if_process_is_running {
 if [ "$PID" = "" ]; then
 return 1
 fi
 ps -p $PID | grep "java"
 return $?
}



case "$1" in
 status)
 if check_if_process_is_running
 then
 echo -e "\033[32m $APP_NAME is running \033[0m"
 else
 echo -e "\033[32m $APP_NAME not running \033[0m"
 fi
 ;;
 stop)
 if ! check_if_process_is_running
 then
 echo -e "\033[32m $APP_NAME already stopped \033[0m"
 exit 0
 fi
 kill -9 $PID
 echo -e "\033[32m Waiting for process to stop \033[0m"
 NOT_KILLED=1
 for i in {1..20}; do
 if check_if_process_is_running
 then
 echo -ne "\033[32m . \033[0m"
 sleep 1
 else
 NOT_KILLED=0
 fi
 done
 echo
 if [ $NOT_KILLED = 1 ]
 then
 echo -e "\033[32m Cannot kill process \033[0m"
 exit 1
 fi
 echo -e "\033[32m $APP_NAME already stopped \033[0m"
 ;;
 start)
 if [ "$PID" != "" ] && check_if_process_is_running
 then
 echo -e "\033[32m $APP_NAME already running \033[0m"
 exit 1
 fi
 nohup java -jar -Dalarm.config.file=$ALARM_CONFIG_FILE $JAVA_OPTIONS_INITIAL $JAVA_OPTIONS_MAX $_JAR_KEYWORDS --spring.config.location=$APPLICATION_FILE > /dev/null 2>&1 & 
 echo -ne "\033[32m Starting \033[0m" 
 for i in {1..20}; do
 echo -ne "\033[32m.\033[0m"
 sleep 1
 done
 if check_if_process_is_running 
 then
 echo -e "\033[32m $APP_NAME fail \033[0m"
 else
 echo -e "\033[32m $APP_NAME started \033[0m"
 fi
 ;;
 restart)
 $0 stop
 if [ $? = 1 ]
 then
 exit 1
 fi
 $0 start
 ;;
 *)
 echo "Usage: $0 {start|stop|restart|status}"
 exit 1
esac


exit 0

名称栏目:springboot中的shell脚本怎么利用jar方式启动-创新互联
文章链接:http://cqcxhl.com/article/cdhehp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP