#!/bin/bash

echo =================================
echo 自动化部署脚本启动
echo 自动化部署脚本启动
echo =================================
echo 进入/opt/code/allthings-share-api

cd /opt/code/allthings-share-api
echo 拉取代码

if [ $# -eq 0 ];
  then
    git checkout master
else
    git checkout $1
fi

git pull

echo 开始打包
cd /opt/code/allthings-share-api/common
mvn clean install

cd /opt/code/allthings-share-api/adminapi
mvn clean package

cd /opt/work
echo 杀掉java进程
pkill -f allthings-share-api-adminapi-1.0-SNAPSHOT.jar

rm -rf allthings-share-api-adminapi-1.0-SNAPSHOT.jar
echo 开始复制jar包
cp -rf /opt/code/allthings-share-api/adminapi/target/allthings-share-api-adminapi-1.0-SNAPSHOT.jar /opt/work/

echo 起服务
nohup java -jar allthings-share-api-adminapi-1.0-SNAPSHOT.jar --spring.profiles.active=test > /dev/null 2>&1 &

tail -f /opt/work/logs/adminapi/adminapi.log
