#!/bin/bash
#
#从nacos里踢除服务
curl -X POST 'http://localhost:8026/actuator/shutdown'
sleep 5
# 查询进程是否存在
#fi
ps -ef | egrep "[s]oa-equipment-v0.0.1.jar" |grep -v "grep"|grep -v "soa-equipment.sh" | awk '{print $2}'|xargs kill -9
sleep 3

cd /data/TSP/
# 检查jar包是否存在
if [ -f soa-equipment-v0.0.1.jar ];then
        mv soa-equipment-v0.0.1.jar ./backups/soa-equipment-v0.0.1.jar-$(date +%F_%T)
fi

# jar包重命名
mv /data/TSP/soa-equipment-v0.0.1.jar.1 /data/TSP/soa-equipment-v0.0.1.jar
sleep 5
# 运行jar包
nohup java -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:MaxDirectMemorySize=256m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/TSP_LOG/gclog/soa-equipment.log  -javaagent:/opt/skywalking_agent/skywalking-agent.jar  -Dskywalking.agent.service_name=soa-equipment-1 -Dskywalking.collector.backend_service=10.20.80.124:11800,10.20.20.183:11800,10.20.50.2:11800 -javaagent:/opt/prometheus-jvm/jmx_prometheus_javaagent-0.14.0.jar=27032:/opt/prometheus-jvm/prometheus-jmx-config.yaml -jar -Dspring.profiles.active=prod -Dfile.encoding=UTF-8 -Duser.timezone=GMT+08 /data/TSP/soa-equipment-v0.0.1.jar > /data/logs/soa-equipment.log 2>&1 &
cd
sleep 5
pid=`ps -ef | egrep "[s]oa-equipment-v0.0.1.jar" |grep -v "grep"|grep -v "soa-equipment.sh" | awk '{print $2}'`
if [ "$pid" == "" ]; then
        echo '启动不正常，再次启动'>/tmp/1-equipment.txt
        nohup java -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:MaxDirectMemorySize=256m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/TSP_LOG/gclog/soa-equipment.log -javaagent:/opt/skywalking_agent/skywalking-agent.jar  -Dskywalking.agent.service_name=soa-equipment-1 -Dskywalking.collector.backend_service=10.20.80.124:11800,10.20.20.183:11800,10.20.50.2:11800 -javaagent:/opt/prometheus-jvm/jmx_prometheus_javaagent-0.14.0.jar=27032:/opt/prometheus-jvm/prometheus-jmx-config.yaml -jar -Dspring.profiles.active=prod -Dfile.encoding=UTF-8 -Duser.timezone=GMT+08 /data/TSP/soa-equipment-v0.0.1.jar > /data/logs/soa-equipment.log 2>&1 &
else
        echo '正常'>/tmp/2-equipment.txt
fi
cd

exit 0
