美文网首页
parity 自动重启脚本

parity 自动重启脚本

作者: xun2019 | 来源:发表于2020-08-04 19:19 被阅读0次

#!/bin/bash
PROCESS='hparity'
LOG=mem.txt
SETMEM=16.5
ps -ef | grep $PROCESS | grep -v grep
if [ $? -ne 0 ]
then
        echo "start process......"
        sh start.sh
else
        echo "runing......"
fi

#过滤出需要的进程ID
PID=$(ps -ef | grep $PROCESS | grep -v 'grep' | awk '{print $2;}')

while true
do
    MEM=$(cat /proc/$PID/status | grep RSS | awk '{print $2;}')
    starttime=$(date +%Y-%m-%d\ %H:%M:%S)
    echo "$starttime  $MEM" >>mem.txt

    GMEM=$(printf "%.5f" `echo "scale=5;$MEM/1024/1024"|bc`)
    echo "$GMEM"
    if [ $(echo "$GMEM > $SETMEM"|bc) = 1 ];then
        echo "MEM great than set mem $SETMEM ,restart $PROCESS"
        kill $PID
    fi

    sleep 10
    PID=$(ps -ef | grep $PROCESS | grep -v 'grep' | awk '{print $2;}')
    if [ "$PID" == "" ];then
        echo "start $PROCESS ..."
        sh start.sh        
    fi  


done

相关文章

网友评论

      本文标题:parity 自动重启脚本

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