start.sh 920 Bytes
#!/bin/sh

#working directory
pwd="/Data/code/yoho-phplog"

pgrep="/usr/bin/pgrep"
wc="/usr/bin/wc"
lsof="/usr/sbin/lsof"
python="/usr/bin/python"
php="/Data/local/php/bin/php"

log_file=$pwd'/access.log'
if [ ! -f $log_file ];then
        touch $log_file
        chmod 777 $log_file
fi

monitor(){
        #pid=`ps aux|grep $1.php|$wc -l`
        pid=`ps aux|grep "$1"|$wc -l`

        if [ $pid -le 1 ];then
                msg="At time: `date` :$1  is stop ."
                echo $msg
                echo $msg >> $log_file
                #cmd="$php -f $pwd/$1.php"
                cmd="$1"
                echo $cmd
                echo $cmd >> $log_file
                $cmd 2>&1 &
        else
                echo "$1 is running ."
        fi
}

while true;do

        #http mq
        monitor "$php -f $pwd/HttpMqServer.php"

        #mqclient
        monitor "$python $pwd/MqClient.py"

        sleep 5

done