#!/bin/bash
#
source /etc/profile
#从nacos里踢除服务
curl -X POST 'http://localhost:8021/actuator/shutdown'
sleep 5
# 获取PID
#pid=`ps -ef | grep [s]oa-data-handler-v0.0.1.jar | grep -v "soa-data-handler.sh" |grep -v grep | awk '{print $2}'`
#
# 查询进程是否存在
#ps aux | grep [s]oa-data-handler-v0.0.1.jar

# 如进程存在，则kill
#if [ $? -eq 0 ];then
#	kill -9 $pid
#fi
ps -ef | grep [s]oa-data-handler-v0.0.1.jar | grep -v "soa-data-handler.sh" |grep -v grep | awk '{print $2}'| xargs kill -9
sleep 5

cd /data/TSP/

# 运行jar包
nohup java -Xms3g -Xmx3g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:MaxDirectMemorySize=512m -XX:+UseG1GC -XX:G1HeapRegionSize=2 -XX:MaxGCPauseMillis=100 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/TSP_LOG/gclog/soa-data-handler.log  -javaagent:/opt/skywalking_agent/skywalking-agent.jar  -Dskywalking.agent.service_name=soa-data-handler-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=27015:/opt/prometheus-jvm/prometheus-jmx-config.yaml -jar -Dspring.profiles.active=prod -Dfile.encoding=UTF-8 -Duser.timezone=GMT+08 /data/TSP/soa-data-handler-v0.0.1.jar > /data/logs/soa-data-handler.log 2>&1 &
cd
sleep 5
pid=`ps -ef | grep [s]oa-data-handler-v0.0.1.jar | grep -v "soa-data-handler.sh" |grep -v grep | awk '{print $2}'`
if [ "$pid" == "" ]; then
        echo '启动不正常，再次启动'>/tmp/1-data.txt
	nohup java -Xms3g -Xmx3g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:MaxDirectMemorySize=512m -XX:+UseG1GC -XX:G1HeapRegionSize=2 -XX:MaxGCPauseMillis=100 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/TSP_LOG/gclog/soa-data-handler.log  -javaagent:/opt/skywalking_agent/skywalking-agent.jar  -Dskywalking.agent.service_name=soa-data-handler-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=27015:/opt/prometheus-jvm/prometheus-jmx-config.yaml -jar -Dspring.profiles.active=prod -Dfile.encoding=UTF-8 -Duser.timezone=GMT+08 /data/TSP/soa-data-handler-v0.0.1.jar > /data/logs/soa-data-handler.log 2>&1 &
else 
	echo '正常'>/tmp/2-data.txt
fi

exit 0
