inst_dir=`cat pid.txt`
if [ $inst_dir == "1" ];then
    g_path="GameServer/"
else
    g_path="GameServer${inst_dir}/"
fi
#################################
start(){ 
    echo $g_path
    #cd /data/$g_path$1 && export NODE_ENV=development; forever start -a -l /dev/null -e err.log app.js
    cd /data/$g_path$1 && export NODE_ENV=production; forever start -a -l /dev/null -e err.log app.js
    if [ $? -eq 0 ];then
        echo -e "\e[1;32m 启动[ \e[1;33m$1\e[1;32m ]成功!\e[0m"
    else
        echo -e "\e[1;31m 启动[ \e[1;33m$1\e[1;31m ]失败!\e[0m"
    fi
}
#################################
#check=`ps aux|grep GameServer${inst_dir}/$1 |grep -v grep|wc -l`
if [ $1 == "all" ];then
    check=`ps aux|grep $g_path |grep -v mad|grep -v grep|grep -v 'bash'|wc -l`
    echo $g_path,$check
    if [ $check -eq 0 ];then
        start web-server
        start login-server
        start log-server
        start fight-server   
    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 -eq 0 ];then
        start $1
    else
       echo -e "\e[1;33m $1已启动，无需再启!\e[0m"
    fi
fi

