美文网首页
shell监控进程是否存在(进程数量),循环、crontab任务

shell监控进程是否存在(进程数量),循环、crontab任务

作者: 无味wy | 来源:发表于2022-04-14 15:59 被阅读0次

    监控服务进程是否存在

    #!/bin/bash
    
    while true 
    do
        phpfpm_procnum=`ps -ef|grep "php-fpm"|grep -v grep|wc -l`
        nginx_procnum=`ps -ef|grep "nginx"|grep -v grep|wc -l`
        mysql_procnum=`ps -ef|grep "mysqld"|grep -v grep|wc -l`
        redis_procnum=`ps -ef|grep "redis"|grep -v grep|wc -l`
        
        if [ $phpfpm_procnum -eq 0 ]
        then
            echo "start php-fpm..."
            /etc/init.d/php-fpm start >> /var/log/listen_service_start.log 2>&1
        elif [ $nginx_procnum -eq 0 ]
        then 
            echo "start nginx..."
            /usr/local/nginx/sbin/nginx >> /var/log/listen_service_start.log 2>&1
        elif [ $mysql_procnum -eq 0 ]
        then 
            echo "start mysql..."
            systemctl start mysqld >> /var/log/listen_service_start.log 2>&1
        elif [ $redis_procnum -eq 0 ]
        then 
            echo "start redis..."
            systemctl start redis >> /var/log/listen_service_start.log 2>&1
        else 
            #echo "no cmd"
        fi
        sleep 30 #每30秒检查一轮
    done
    
    #!/bin/bash
    
        index=`ps -ef|grep "voiceTask.sh"|grep -v grep|wc -l`
        
        if [ $index -lt 3 ]
        then
            echo "start voiceTask.sh..."
            sh -x /home/work/webroot/Zn_tp/app/report/task/voiceTask.sh & >> /dev/null 2>&1
        else 
        echo "${index}`date`" >> /dev/null 2>&1
        fi
    

    相关文章

      网友评论

          本文标题:shell监控进程是否存在(进程数量),循环、crontab任务

          本文链接:https://www.haomeiwen.com/subject/tstssrtx.html