Phala-node异常监控/恢复小命令

说明

phala-node目前运行时,会偶发的卡住。发一个简单实用的小命令,自动监控phala-node的高度是否不断增加。如5-10分钟左右没有变化,则自动重启phala-node。一行命令处理,简单可靠,自用正常

提醒:本地运行可以开窗口直接运行命令。远程登陆可以用screen等命令,保护连接异常断开,导致的命令实效

命令

last=0;while true;do height=$(curl -sH "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "system_syncState", "params":[]}' http://0.0.0.0:9933 | jq '.result.currentBlock') ;if [ "$last" = "$height" ]; then echo [$(date +'%Y-%m-%d %H:%M:%S')] stoped: $height '-' $last = $(($height - $last));docker restart phala-node;sleep 300;else echo [$(date +'%Y-%m-%d %H:%M:%S')] narmal: $height '-' $last = $(($height - $last)); fi;last=$height;sleep 300;done

上面命令格式化展开

last=0;
while true;
do
        height=$(curl -sH "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "system_syncState", "params":[]}' http://0.0.0.0:9933 | jq '.result.currentBlock') ;
        if [ "$last" = "$height" ];  
        then 
                echo [$(date +'%Y-%m-%d %H:%M:%S')] stoped: $height '-' $last = $(($height - $last)); 
                docker restart phala-node; 
                sleep 300; 
        else 
                echo [$(date +'%Y-%m-%d %H:%M:%S')] narmal: $height '-' $last = $(($height - $last)); 
        fi; 
        last=$height; 
        sleep 300;
done

运行效果

2 Likes