ins_id=`cat pid.txt`
#path='./release/mad/'
path='./mad/'
mad_list=`ls ${path}mad${ins_id}_*`
ps=`ps aux|grep mad${ins_id}_|grep -v grep|wc -l`
stop(){
   if [ "x$ps" != "x0" ];then
       ps aux|grep mad${ins_id}_|grep -v grep|xargs kill -15 >/dev/null 2>&1
   fi
}
status(){
        for i in $mad_list
        do
            pux=`ps aux|grep $i|grep -v grep|wc -l`
            if [ "x$pux" == "x0" ];then
               echo -e "$i \e[1;31;1m[ 停止! ]\e[0m"
            else
               echo -e "$i \e[1;32;1m[ 运行! ]\e[0m"
            fi
        done
}
start(){
        for i in $mad_list
        do
           # cd $path
            name=`echo $i |awk -F '_' '{print $2}'`
            nohup $i --service ${name} >/dev/null 2>&1 &
         #   nohup ./mad/mad1_subtitle --service subtitle  >/dev/null 2>&1
        done
}
st(){
    if [ "x$1" == "xstart" ];then
       stop
       start
       status
    elif [ "x$1" == "xstop" ];then
       stop
       status
    elif [ "x$1" == "xstatus" ];then
       status
    fi
}
st $1
#echo $mad_list
#start
