inst_dir=`cat pid.txt`
if [ $inst_dir == "1" ];then
    g_path="GameServer/"
else
    g_path="GameServer${inst_dir}/"
fi
#################################
stop(){
     if [ $inst_dir == '1' ];then
            cd /data/GameServer/$1 && export NODE_ENV=production; forever $2 -a -l /dev/null app.js
            if [ $? -eq 0 ];then
                echo -e "\e[1;32m $2[ \e[1;33m$1\e[1;32m ]成功!\e[0m"
            else
                echo -e "\e[1;31m $2[ \e[1;33m$1\e[1;31m ]失败!\e[0m"
            fi
        else
            cd /data/GameServer${inst_dir}/$1 && export NODE_ENV=production; forever $2 -a -l /dev/null app.js
            if [ $? -eq 0 ];then
                echo -e "\e[1;32m $2[ \e[1;33m$1\e[1;32m ]成功!\e[0m"
            else
                echo -e "\e[1;31m $2[ \e[1;33m$1\e[1;31m ]失败!\e[0m"
            fi
        fi
}
#################################
if [ "$1" != "" ]&&[ "$2" != "" ];then
    if [ $1 == "all" ];then
        check=`ps aux|grep $g_path |grep -v grep|wc -l`
        if [ $check -ne 0 ];then
            stop fight-server $2
            stop login-server $2
            stop web-server $2
            stop log-server $2
        else
            echo -e "\e[1;33m Game相关进程不存在，请检查后再操作!\e[0m"
        fi
    else
        check=`ps aux|grep $g_path$1 |grep -v grep|wc -l`
        if [ $check -ne 0 ];then
            stop $1 $2
        else
        echo -e "\e[1;33m $1进程不存在，操作无效!\e[0m"
        fi
    fi
else
    echo -e "\e[1;31m 缺少相关参数，操作无效!\e[0m"
fi

