手撕包菜安装后Shell脚本程序监控程序是否在执行

1、首先需要监控的有3个程序:
simdht_worker.py 、 index_worker.py、manage.py runserver 这3个进程;

2、监控3个脚本内容
监控simdht_worker.py脚本:

#!/bin/bash
#author Zhj
#time 20170108
#program:判断进程是否存在,并重新启动
CountSimdht=`ps -ef | grep python | grep simdht | wc -l`
ulimit -c unlimited
if [[ $CountSimdht -eq 0 ]];then 
    cd /root/ssbc-master/workers
    nohup python simdht_worker.py >/dev/zero 2>&1&
    echo "start process"
else
    echo "The simdht_worker is running" 
fi
监控index_worker.py
#!/bin/bash
#author Zhj
#time 20170108
#program:判断进程是否存在,并重新启动
countindex=`ps -ef | grep python | grep index | wc -l`
ulimit -c unlimited
if [[ $countindex -eq 0 ]];
then
    cd /root/ssbc-master/workers
    nohup python index_worker.py >/dev/zero 2>&1&
    echo "start process"
else
    echo "The index_worker is running" 
fi

监控manage.py runserver的脚本

#!/bin/bash
#author Zhj
#time 20170108
#program:判断进程是否存在,并重新启动
countWeb=`ps -ef | grep python | grep manage | wc -l`
ulimit -c unlimited
if [[ $countWeb -eq 0 ]];
then
    cd /root/ssbc-master/
    nohup python manage.py runserver 0.0.0.0:80 >/dev/zero 2>&1&
    echo "Start WebServer"
else
    echo "The WebServer is running" 
fi
 
3、写入定时任务crontab
crontab -e

*/5 * * * * /root/IndexCheck.sh
*/5 * * * * /root/SimdhtCheck.sh
*/5 * * * * /root/WebserCheck.sh

以上3行内容表示每隔5分钟检查一次,是否正常运行。
 
via.http://baike.ss209.com/post/8.html
最后修改:2017 年 07 月 19 日 09 : 25 PM