Spring Boot微服务启动脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot微服务启动脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#description: starts and stops the boot.sh

app_name=$1
pid=ps aux | grep java | grep $app_name | grep -v "grep" | awk ‘print $2‘

usags()
echo "Usags: sh boot.sh [eureka|config|auth|emqtt|crm|upm|uc|upload|gateway|notification|wx|zipkin|phonestatisctis] [start|stop|status]"
exit 1

#检查程序是否在运行
is_exist()
if [ -z "$pid" ];then
return 1
else
return 0
fi

#启动
is_start()
is_exist
if [ $? -eq "0" ];then
echo "$app_name is running"
else
if [ $app_name == "eureka" ];then
cd /application/jar/$app_name
java -Xms512m -Xmx1024m -jar workos-eureka.jar >> nohup.out&
elif [ $app_name == "config" ];then
cd /application/jar/$app_name
java -Xms512m -Xmx1024m -jar workos-config.jar >> nohup.out&
elif [ $app_name == "auth" ];then
cd /application/jar/$app_name
java -Xms512m -Xmx1024m -jar workos-auth-server.jar >> nohup.out&
elif [ $app_name == "crm" ];then
cd /application/jar/$app_name
java -Xms1024m -Xmx2048m -jar workos-crm-service.jar >> nohup.out&
elif [ $app_name == "emqtt" ];then
cd /application/jar/$app_name
java -Xms512m -Xmx1024m -jar workos-emqtt.jar >> nohup.out&
elif [ $app_name == "gateway" ];then
cd /application/jar/$app_name
java -Xms1024m -Xmx2048m -jar workos-gateway.jar >> nohup.out&
elif [ $app_name == "notification" ];then
cd /application/jar/$app_name
java -Xms512m -Xmx1024m -jar workos-notification-service.jar >> nohup.out&
elif [ $app_name == "phonestatisctis" ];then
cd /application/jar/$app_name
java -Xms512m -Xmx1024m -jar workos-phonestatisctis.jar >> nohup.out&
elif [ $app_name == "uc" ];then
cd /application/jar/$app_name
java -Xms1024m -Xmx2048m -jar workos-uc.jar >> nohup.out&
elif [ $app_name == "upm" ];then
cd /application/jar/$app_name
java -Xms1024m -Xmx2048m -jar workos-upm-service.jar >> nohup.out&
elif [ $app_name == "wx" ];then
cd /application/jar/$app_name
java -Xms1024m -Xmx2048m -jar workos-wx.jar >> nohup.out&
elif [ $app_name == "upload" ];then
cd /application/jar/$app_name
java -Xms1024m -Xmx2048m -jar workos-upload.jar >> nohup.out&
else
cd /application/jar/$app_name
java -Xms256m -Xmx512m -jar workos-zipkin.jar >> nohup.out&
fi
fi

#停止
is_stop()
is_exist
if [ $? -eq "0" ];then
kill -9 $pid
else
echo "$app_name is not running"
fi

#状态
is_status()
is_exist
if [ $? -eq "0" ];then
echo "$app_name is running"
else
echo "$app_name is no running"
fi

#根据输入参数,选择执行方法
case "$1" in
"zipkin")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"config")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"auth")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"gateway")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"upm")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"uc")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"crm")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"wx")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"upload")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"eureka")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"emqtt")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"notification")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
"phonestatisctis")
case "$2" in
"start")
is_start
;;
"stop")
is_stop
;;
"status")
is_status
;;
)
usags
;;
esac
;;
)
usags
;;
esac

以上是关于Spring Boot微服务启动脚本的主要内容,如果未能解决你的问题,请参考以下文章

spring boot 使用脚本启动.bat怎么写

启动/关闭Spring boot服务脚本

spring boot 怎么启动

如何理解 Spring Boot 应用程序已准备好工作?

spring cloud 微服务启动脚本

Spring boot centos部署启动停止脚本