#!/bin/bash

# 所有服务项目列表
GLOBAL_SERVICES=('central' 'gateway' 'world' 'logic' 'mapsearch' 'chat' 'fight' 'gm' 'login' 'pay' 'report' 'version')

# 编译服务名前缀
GLOBAL_SERVICE_NAME_PREFIX=""

# go cmd
GLOBAL_GO_CMD="/usr/local/go1.22.4.linux-amd64/bin/go"

# 查看所有服务
function WatchAllServices() {
  #ps -ef | grep $GLOBAL_SERVICE_NAME_PREFIX
  for globalServiceName1 in "${GLOBAL_SERVICES[@]}"; do
    echo $(ps -ef | grep "${GLOBAL_SERVICE_NAME_PREFIX}${globalServiceName1}")
  done
}

# 杀掉所有进程
# @param killNum 杀死进程形式 支持 2， 9 等，默认9
function KillForceAllService() {

  killNum=$1
  if [ -z "$1" ]; then
    killNum=9
  fi

  for globalServiceName1 in "${GLOBAL_SERVICES[@]}"; do
    # 指定停止某一个程序
    if [ -n "$2" ] && [ "$2" != "${globalServiceName1}" ] ; then
        continue
    fi
    echo "start kill service ${GLOBAL_SERVICE_NAME_PREFIX}${globalServiceName1}"
    # 模糊杀死 -- 避免误杀
    pkill -${killNum} -f "${globalServiceName1}/.*${globalServiceName1}"
  done
}

# 删除log
function DeleteLog() {
    rm -rf logs/error/*.log
    rm -rf logs/debug/*.log
    rm -rf logs/info/*.log
    rm -rf logs/warn/*.log
}
