Linux系统环境下用于启动jar文件的启动脚本如下:

#!/bin/bash
cd $PWD
while : 
do
service1=$(ps -ef |grep "Register-0.0.1-SNAPSHOT.jar" |grep -v "grep")
service2=$(ps -ef |grep "Config-Service-0.0.1-SNAPSHOT.jar" |grep -v "grep")

if [ "$service1" ] ; then
echo "The Registry Micro-Service is alive!"
else
echo "The Registry Micro-Service was shutdown!"
echo "Starting Registry Micro-Service ..."
//外部配置文件
 java -jar Register-0.0.1-SNAPSHOT.jar --spring.config.location=classpath:/application.properties &
echo "The Registry Micro-Service was started!"
fi

if [ "$service2" ] ; then
echo "The Config-Service Micro-Service is alive!"
else
echo "The Config-Service Micro-Service was shutdown!"
echo "Starting Config-Service Micro-Service ..."
 java -jar Config-Service-0.0.1-SNAPSHOT.jar  --spring.profiles.active=uat &
echo "The Config-Service Micro-Service was started!"
fi

sleep 60
rm -rf nohup.out
done

 

Linux系统环境下用于停止jar文件的停止脚本如下:

#!/bin/sh

echo "Stop MicroService starting..."

pids=`ps -ef | grep "startService10" |grep -v grep| awk '{print $2}'`
if [ "$pids" ]
then
echo "startService10.sh service kill -9 Pid:" $pids
for pid in $pids
do
 echo "service pid:"$pid
 kill -9 $pid
done
echo "Stoped startService10.sh service success."
else
echo "startService10.sh Service is not run."
fi

pid1=`ps -ef | grep "Register-0.0.1-SNAPSHOT".jar | grep -v grep | awk '{print $2}'`
pid2=`ps -ef | grep "Config-Service-0.0.1-SNAPSHOT".jar | grep -v grep | awk '{print $2}'`

if [ "$pid1" ]
then
echo "Registry service kill -9 Pid:" $pid1
kill -9 $pid1
echo "Stoped Registry service success."
else
echo "Registry Service is not run."
fi

if [ "$pid2" ]
then
echo "Config-Service service kill -9 Pid:" $pid2
kill -9 $pid2
echo "Stoped Config-Service service success."
else
echo "Config-Service Service is not run."
fi

echo "Stop 10 finish."

 

posted on 2019-04-26 10:49  遥-ZHZ  阅读(213)  评论(0编辑  收藏  举报