#! /bin/bash
#微服务名称,yuser就填yuser即可
serviceName="xxx"
#微服务所在路径,自行定义
servicePath=/home/data/${serviceName}
startJarName=$(ls -lt ${servicePath}/ | grep ${serviceName} | head -n 1 |awk '{print $9}')
echo [系统提示]检测到最新上传的包:${startJarName}
#微服务进程id
pid=0
function calcPid()
{
pid=`ps -ef | grep ${serviceName}-start-. |grep -v grep | awk '{print $2}'`
return 0
}
function startProgress
{
b=''
for ((i=0;$i<=100;i+=2))
do
printf "服务启动中,请稍后:[%-50s]%d%%\r" $b $i
sleep 0.02
b=#$b
done
echo
}
#echo 杀上一个进程${pid}
calcPid
echo "[系统提示]服务启动前的pid是:" ${pid}
#echo "正在重新启动:" ${startJarName}
kill -9 ${pid}
echo [系统提示]进程 ${pid} 已被关闭
echo 0>nohup.out
nohup java -Xms2048M -Xmx2048M -Xss256K -XX:MetaspaceSize=200M -XX:MaxMetaspaceSize=200M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heapdump.hprof -jar ${servicePath}/${startJarName} &
startProgress
calcPid
echo "[系统提示]重新启动后的pid是:" ${pid}
echo "[系统提示]重新启动的Jar包为最新的:" ${startJarName}
echo "》》》》》》》》》》》》》启动完成》》》》》》》》》》》》》"
exit 0
运行效果图: