#!/bin/bash

echo Starting .........

export LANG="en_US.UTF-8"

nacospid = $(ps -ef|grep nacos|grep -v grep | awk '{print $2}')
xxljobpid = $(ps -ef|grep xxl-job|grep -v grep | awk '{print $2}')
platformpid = $(ps -ef|grep energy-manage-service|grep -v grep | awk '{print $2}')
miniopid = $(ps -ef|grep minio|grep -v grep | awk '{print $2}')


if systemctl is-active --quiet docker; then
    echo "........docker 正在运行........"

    if [ -n "$nacospid" ]
      then
        echo "正在运行的nacos进程 :$nacospid"
        # kill -9 $nacospid
        # echo  "========================================"
        # echo "杀死:$nacospid 进程 "
      else
        echo "........ nacos未运行........"
        # 启动nacos服务
        /data/nacos/bin/startup.sh -m standalone
        echo "........ nacos启动成功........"
    fi

    sleep 2s

    if [ -n "$xxljobpid" ]
      then
        echo "正在运行的xxl-job进程 :$xxljobpid"
        # kill -9 $xxljobpid
        # echo  "========================================"
        # echo "杀死:$xxljobpid 进程 "
      else
        echo "........ xxl-job未运行........"
        # 启动xxl-job服务
        nohup java -jar /data/xxl-job/xxl-job-admin.jar &
        echo "........ xxl-job运行成功........"
    fi

    sleep 2s

    if [ -n "$platformpid" ]
      then
        echo "正在运行的平台进程 :$platformpid"
        # kill -9 $platformpid
        # echo  "========================================"
        # echo "杀死:$platformpid 进程 "
      else
        echo "........ 平台未运行........"
        # 启动平台服务
#        /data/app/start.sh
        echo "........ 平台运行成功........"
    fi

    sleep 2s

    if [ -n "$miniopid" ]
      then
        echo "正在运行的minio进程 :$miniopid"
        # kill -9 $miniopid
        # echo  "========================================"
        # echo "杀死:$miniopid 进程 "
      else
        echo "........ minio文件系统未运行........"
        # 启动minio服务
        # /var/minio/minio-startup.sh
        echo "........ minio运行成功........"
    fi

else
    echo "........docker 未运行........"
fi
