Centos 監控進程,並自動重啓

Centos 監控進程,並自動重啓

 

編輯Crontab

crontab -e

 

按i進行編輯

*/1 * * * * /root/monitor.sh # 每分鐘運行一遍monitor.sh腳本
0   5 * * * /sbin/reboot # 每天凌晨5點自動重啓服務器
*/1 * * * * /root/monitor.sh # 每分鐘運行一遍monitor.sh腳本
0   5 * * * /sbin/reboot # 每天凌晨5點自動重啓服務器

 

重啓Crond服務

systemctl restart crond

 

配置monitor.sh

#!/bin/sh
echo "==================start monitor==============="
#define commonprocessnum
commonprocessnum=1
#define sleeptime,4 miniutes
sleeptime=30
#iternal
internal=5

#3 define pypath
pypath='/data/centos_env/run_exe'

#monitor the othe process whether has run
#while (( 1 < 11 ))
#do

# 3 check the ptps and if no running then start the prcess
gfid=`ps -ef | grep -i feature-extract |grep -v 'grep'| wc -l`

if [ ${gfid} -ge ${commonprocessnum} ]; then
    sleep 1
else

    cd $pypath
    ./feature-extract &
    sleep ${internal}
    echo "=========3 start the feature-extract process "
fi

#sleppzzz
sleep ${sleeptime}
#done

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章