#!/bin/bash

# 定义变量
WORK_DIR="/data/sensor"
FILE_PATH=`pwd`
JAR_PATH="$FILE_PATH/iot-local.jar"
SERVICE_NAME="iot-local"

# 检查 JAR 文件是否存在
if [ ! -f "$JAR_PATH" ]; then
   echo "JAR file is not exist: $JAR_PATH"
   exit 1
fi

# 停止现有的服务
echo "stop service $SERVICE_NAME..."
sudo systemctl stop $SERVICE_NAME.service

# 复制文件
cp -f $FILE_PATH/*.jar $WORK_DIR/
cp -f $FILE_PATH/*.properties $WORK_DIR/


# 重新启动服务
echo "start service $SERVICE_NAME..."
sudo systemctl start $SERVICE_NAME.service

echo "serivce $SERVICE_NAME upgrade success and reboot。"
