赞
踩
微服务本地部署时多个jar后台启动,新建sh脚本放入同级目录即可
-Dloader.path=./lib ./lib为外置jar包目录,目的是方便更新时快速上传新代码,若未配置可自行删除,或自行配置自己的目录
- #!/bin/bash
- # sh start.sh stop 关闭正在运行
- # sh start.sh 直接启动
- # sh start.sh sit 指定配置文件(sit)启动
- #后台运行jar包 这里替换为你的jar包列表
- jar_arr=("karakoram-usercenter-1.0.0.jar" "karakoram-wuyi-1.0.0.jar" "karakoram-inventory-1.0.0.jar" "karakoram-task-1.0.0.jar")
-
- start(){
- stop
-
- yaml_name="prd"
- if [ ${1} ]
- then
- yaml_name=${1}
- fi
- echo ${yaml_name}
-
- for jar_name in ${jar_arr[@]};
- do
-
- #启动jar包
- if [ ${yaml_name} == "sit" ]
- then
- #测试环境
- nohup java -Dloader.path=./lib -jar -Dspring.profiles.active=sit ${jar_name} >./out/${jar_name}.out 2>&1 &
- elif [ ${yaml_name} == "dev" ]
- then
- #开发环境
- nohup java -Dloader.path=./lib -jar -Dspring.profiles.active=dev ${jar_name} >./out/${jar_name}.out 2>&1 &
- else
- #正式环境
- nohup java -Dloader.path=./lib -jar ${jar_name} >./out/${jar_name}.out 2>&1 &
- fi
- echo ${yaml_name} ${jar_name} start
- done
- echo "启动完成"
- }
-
- stop(){
- for jar_name in ${jar_arr[@]};
- do
- #杀掉正在运行的进程
- tpid=`ps -ef|grep $jar_name|grep -v grep|grep -v kill|awk '{print $2}'`
- if [ ${tpid} ]
- then
- echo ${jar_name} ${tpid} kill
- kill -9 ${tpid}
- fi
- done
- echo "kill process success"
- }
-
-
- if [ !${1} -a ${1} == "start" ]
- then
- start ${2}
- elif [ ${1} == "stop" ]
- then
- stop
- else
- start ${1}
- fi
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。