一、基础服务:
- Mysql
- Redis
- Mongodb
- Ftp
- Rabbitmq
- nginx
注:基础服务采用docker-compose安装,开机自启,从略。
二、应用服务
- eureka
- gateway
- bdm
- hvc
- lvc
开机执行一键启动脚本,脚本如下:
#!/bin/bash
# description: auto_run_jar
# author: freedom
# 程序基本路径
BASE_PATH="/home/riva2/ispd-2.8"
# 刷新环境变量
source /etc/profile
# 启动方法
start() {
# 启动程序
echo "$(date "+%Y-%m-%d %H:%M:%S") starting $JAR_NAME ........."
nohup java -jar -Xms512m -Xmx512m -Dlog4j2.formatMsgNoLookups=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$ADDRESS -Dfile.encoding=UTF-8 -Dcas.standalone.config=$CONFIG_PATH $JAR_NAME > $LOG_FILE 2>&1 &
# 查询日志检测java程序是否启动成功
echo "$(date "+%Y-%m-%d %H:%M:%S") checking if $JAR_NAME started ..."
while [ -f $LOG_FILE ]
do
################ NOTE: update grep patern by ur apps !!!
result=`grep "$STARTED_MARK" $LOG_FILE`
if [[ "$result" != "" ]]
then
echo "$(date "+%Y-%m-%d %H:%M:%S") springboot start $JAR_NAME ..."
break
else
echo "$(date "+%Y-%m-%d %H:%M:%S") waiting for start $JAR_NAME ..."
sleep 10s
fi
done
echo "$(date "+%Y-%m-%d %H:%M:%S") $JAR_NAME started success."
}
startEureka() {
# 启动程序
echo "$(date "+%Y-%m-%d %H:%M:%S") starting $JAR_NAME ........."
nohup java -jar $JAVA_OPTS -server -XX:+TieredCompilation -XX:+UseSerialGC -XX:+PrintGCDateStamps -Xloggc:/data/rubbish.log -XX:+PrintGCDetails -Xms300m -Xmx500m $JAR_NAME > $LOG_FILE 2>&1 &
# 查询日志检测java程序是否启动成功
echo "$(date "+%Y-%m-%d %H:%M:%S") checking if $JAR_NAME started ..."
while [ -f $LOG_FILE ]
do
################ NOTE: update grep pattern by ur apps !!!
result=`grep "$STARTED_MARK" $LOG_FILE`
if [[ "$result" != "" ]]
then
echo "$(date "+%Y-%m-%d %H:%M:%S") springboot start $JAR_NAME ..."
break
else
echo "$(date "+%Y-%m-%d %H:%M:%S") waiting for start $JAR_NAME ..."
sleep 10s
fi
done
echo "$(date "+%Y-%m-%d %H:%M:%S") $JAR_NAME started success."
}
startGateway() {
# 启动程序
echo "$(date "+%Y-%m-%d %H:%M:%S") starting $JAR_NAME ........."
nohup java -jar -Dfile.encoding=UTF-8 -Dcas.standalone.config="$CONFIG_PATH" "$JAR_NAME" > $LOG_FILE 2>&1 &
# 查询日志检测java程序是否启动成功
echo "$(date "+%Y-%m-%d %H:%M:%S") checking if $JAR_NAME started ..."
while [ -f $LOG_FILE ]
do
################ NOTE: update grep pattern by ur apps !!!
result=`grep "$STARTED_MARK" $LOG_FILE`
if [[ "$result" != "" ]]
then
echo "$(date "+%Y-%m-%d %H:%M:%S") springboot start $JAR_NAME ..."
break
else
echo "$(date "+%Y-%m-%d %H:%M:%S") waiting for start $JAR_NAME ..."
sleep 10s
fi
done
echo "$(date "+%Y-%m-%d %H:%M:%S") $JAR_NAME started success."
}
# 停止方法
stop() {
echo "$(date "+%Y-%m-%d %H:%M:%S") stopping $JAR_NAME ........."
ID=`ps -ef | grep "$JAR_NAME" | grep -v "$0" | grep -v "grep" | grep -v stop| awk '{print $2}'`
echo "start kill pid: $ID..."
for id in $ID
do
kill $id
echo "killed $id"
done
# 查看程序是否已停止
echo "$(date "+%Y-%m-%d %H:%M:%S") checking if stopped ..."
while true
do
count=`ps -ef | grep "$JAR_NAME" | grep -v "grep"`
if [ "$?" != "0" ]
then
# 程序已停止
echo "$(date "+%Y-%m-%d %H:%M:%S") $JAR_NAME stopped success."
break
else
# 程序仍在运行
echo "$(date "+%Y-%m-%d %H:%M:%S") > waiting for stop..."
fi
sleep 5s
done
}
#########################################################################################################
#eureka 程序名
JAR_NAME="spd-eureka-config.jar"
JAR_PATH=$BASE_PATH"/eureka"
LOG_FILE=$JAR_PATH"/nohup.out"
STARTED_MARK="Started Eureka Server"
# change dir
cd $JAR_PATH
stop
startEureka
# gateway启动
JAR_NAME="spd-gateway.war"
JAR_PATH=$BASE_PATH"/gateway"
CONFIG_PATH=$JAR_PATH"/config"
LOG_FILE=$JAR_PATH"/nohup.out"
# 按自己日志成功标识修改
STARTED_MARK="Started GatewayApp"
# change dir
cd $JAR_PATH
stop
startGateway
#########################################################################################################
# bdm
JAR_NAME="spd-bdm-2.8.12.1.5.war"
JAR_PATH=$BASE_PATH"/ispd-bdm"
CONFIG_PATH=$JAR_PATH"/config"
LOG_FILE=$JAR_PATH"/nohup.out"
ADDRESS=8400
STARTED_MARK="Started SpdBdmApplication"
# change dir
cd $JAR_PATH
stop
start
#########################################################################################################
# hvc-hosp
JAR_NAME="spd-hvc-hosp-2.8.12.1.5.war"
JAR_PATH=$BASE_PATH"/ispd-hvc-hosp"
CONFIG_PATH=$JAR_PATH"/config"
LOG_FILE=$JAR_PATH"/nohup.out"
ADDRESS=8401
STARTED_MARK="Started SpdHvcApplication"
# change dir
cd $JAR_PATH
stop
start
#########################################################################################################
# hvc-dept
JAR_NAME="spd-hvc-dept-2.8.12.1.7.war"
JAR_PATH=$BASE_PATH"/ispd-hvc-dept"
CONFIG_PATH=$JAR_PATH"/config"
LOG_FILE=$JAR_PATH"/nohup.out"
ADDRESS=8407
# change dir
cd $JAR_PATH
stop
start
########################################################################################################
# lvc-hosp
JAR_NAME="spd-lvc-hosp-2.8.12.1.5.war"
JAR_PATH=$BASE_PATH"/ispd-lvc-hosp"
CONFIG_PATH=$JAR_PATH"/config"
LOG_FILE=$JAR_PATH"/nohup.out"
ADDRESS=8406
STARTED_MARK="Started SpdLvcApplication"
# change dir
cd $JAR_PATH
stop
start
#########################################################################################################
# lvc-dept
JAR_NAME="spd-lvc-dept-2.8.12.1.5.war"
JAR_PATH=$BASE_PATH"/ispd-lvc-dept"
CONFIG_PATH=$JAR_PATH"/config"
LOG_FILE=$JAR_PATH"/nohup.out"
ADDRESS=8408
# change dir
cd $JAR_PATH
stop
start