#!/bin/bash
PRO_NAME=test
cd /home/wwwroot/default
while true ; do
     #用ps获取$PRO_NAME进程数量
     NUM=`ps aux | grep -w "/usr/bin/php think ${PRO_NAME}" | grep -v grep |wc -l`
     #echo $NUM
     #少于1,重启进程
     if [ "${NUM}" -lt "1" ];then
         echo "${PRO_NAME} was killed"
         nohup /usr/bin/php think ${PRO_NAME} >> ${PRO_NAME}.log 2>&1  &
    #大于1,杀掉所有进程,重启
    elif [ "${NUM}" -gt "1" ];then
        echo "more than 1 ${PRO_NAME},killall ${PRO_NAME}"
        ps aux | grep -w ${PRO_NAME} | grep -v grep |grep -v ${PRO_NAME}_deamon.sh |awk '{print $2}' |xargs kill -9
        nohup  /usr/bin/php think ${PRO_NAME} >> ${PRO_NAME}.log 2>&1  &
     fi
     sleep 5s
done

exit 0

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据