#!/bin/bash
#
#从服务中心下线
curl -X POST 'http://localhost:8073/actuator/service-registry?status=DOWN' -H 'cache-control: no-cache' -H 'content-type: application/json' -d '{}'
sleep 30
#从nacos里踢除服务
curl -X POST 'http://localhost:8073/actuator/shutdown' -H 'cache-control: no-cache'
sleep 5


# 如进程存在，则kill
ps -ef | grep [p]ortal-web-v0.0.1.jar | grep -v "portal-web.sh" | grep -v "grep" | awk '{print $2}'|xargs kill -9
sleep 5

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

# jar包重命名
mv /data/TSP/portal-web-v0.0.1.jar.1 /data/TSP/portal-web-v0.0.1.jar
sleep 3
# 运行jar包
nohup java -Xms2g -Xmx2g -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -XX:MaxDirectMemorySize=512m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/TSP_LOG/gclog/portal-web.log -javaagent:/opt/skywalking_agent/skywalking-agent.jar -Dskywalking.agent.service_name=portal-web-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=27007:/opt/prometheus-jvm/prometheus-jmx-config.yaml -jar -Dspring.profiles.active=prod -Dfile.encoding=UTF-8 -Duser.timezone=GMT+08 /data/TSP/portal-web-v0.0.1.jar >> /data/logs/portal-web.log 2>&1 &
sleep 5
pid=`ps -ef | grep [p]ortal-web-v0.0.1.jar | grep -v "portal-web.sh" | grep -v "grep" | awk '{print $2}'`
if [ "$pid" == "" ]; then
        echo '启动不正常，再次启动'>/tmp/1-web.txt
	nohup java -Xms2g -Xmx2g -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -XX:MaxDirectMemorySize=512m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/TSP_LOG/gclog/portal-web.log -javaagent:/opt/skywalking_agent/skywalking-agent.jar -Dskywalking.agent.service_name=portal-web-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=27007:/opt/prometheus-jvm/prometheus-jmx-config.yaml -jar -Dspring.profiles.active=prod -Dfile.encoding=UTF-8 -Duser.timezone=GMT+08 /data/TSP/portal-web-v0.0.1.jar >> /data/logs/portal-web.log 2>&1 &
else 
	echo '启动正常'>/tmp/2-web.txt
fi
cd
exit 0
