#!/bin/bash
BUILD_ID=dontKillMe
java -version

BUILD_TIMESTAMP=`date +'%Y-%m-%d_%H-%M-%S'`
echo $BUILD_TIMESTAMP
echo ${BUILD_TIMESTAMP}

echo "編譯完了" 

export JAVA_HOME=/opt/jdk
export JRE_HOME=/opt/jdk/jre
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar


java -version
pwd
currentLocation=$(pwd)
echo $currentLocation

mkdir -p /opt/tempjar
rm -rf /opt/tempjar/xxl-job-admin-bihua*.jar
cp $currentLocation/xxl-job-admin/target/xxl-job-admin-2.4.0-SNAPSHOT.jar /opt/tempjar/xxl-job-admin-bihua-${BUILD_TIMESTAMP}.jar

echo "殺掉舊的進程" 
ps -ef | grep java | grep -v grep |grep 'xxl-job-admin-bihua' | awk '{print "kill -9 "  $2}'  | sh

sleep 2
echo "開始重慶" 

nohup java -jar -Xmx1G -Xms1G -XX:+UseConcMarkSweepGC /opt/tempjar/xxl-job-admin-bihua-${BUILD_TIMESTAMP}.jar --spring.profiles.active=devBiHua --server.port=8901 > /opt/tempjar/log-xxl-job-admin-bihua.log  & 

tail -f /opt/tempjar/log-xxl-job-admin-bihua.log &

sleep 30



mkdir -p /opt/tempjar
rm -rf /opt/tempjar/xxl-job-executor-sample-springboot-bihua*.jar
cp $currentLocation/xxl-job-executor-samples/xxl-job-executor-sample-springboot/target/xxl-job-executor-sample-springboot-2.4.0-SNAPSHOT.jar /opt/tempjar/xxl-job-executor-sample-springboot-bihua-${BUILD_TIMESTAMP}.jar

echo "殺掉舊的進程" 
ps -ef | grep java | grep -v grep |grep 'xxl-job-executor-sample-springboot-bihua' | awk '{print "kill -9 "  $2}'  | sh

sleep 2
echo "開始重慶" 

nohup java -jar -Xmx1G -Xms1G -XX:+UseConcMarkSweepGC /opt/tempjar/xxl-job-executor-sample-springboot-bihua-${BUILD_TIMESTAMP}.jar --spring.profiles.active=devBiHua --server.port=8997 --xxl.job.admin.addresses='http://127.0.0.1:8901/xxl-job-admin' --xxl.job.executor.port=1235 --nacos.config.server-addr=8.210.212.227:1887 > /opt/tempjar/log-xxl-job-executor-sample-springboot-bihua.log  & 

tail -f /opt/tempjar/log-xxl-job-executor-sample-springboot-bihua.log &

sleep 30