Adapt checkBlock for everyone
This commit is contained in:
parent
fcf36da45c
commit
e9c3d033f4
|
@ -1,31 +1,57 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
refname="https://g1.cgeek.fr"
|
## MY VARS ###
|
||||||
|
myEmail="poka@p2p.legal"
|
||||||
|
###
|
||||||
|
|
||||||
|
MY_PATH="`dirname \"$0\"`"
|
||||||
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`"
|
||||||
|
|
||||||
|
refname="g1.presles.fr"
|
||||||
|
|
||||||
date=$(date '+%d-%m-%y à %H:%M')
|
date=$(date '+%d-%m-%y à %H:%M')
|
||||||
echo "############################"
|
echo "############################"
|
||||||
echo "$date"
|
echo "$date"
|
||||||
|
|
||||||
rep="/home/poka/scripts"
|
|
||||||
lock=0
|
lock=0
|
||||||
lockSync="/home/poka/scripts/lock-sync"
|
lockSync="$MY_PATH/lock-sync"
|
||||||
[[ -n $lockSync ]] && touch $lockSync
|
[[ -n $lockSync ]] && touch $lockSync
|
||||||
|
|
||||||
PID=$(ps auxf | grep "duniter" | grep -v -E "color=auto|grep|restart" | awk '{ print $2 }')
|
PID=$(ps auxf | grep "duniter" | grep -v -E "color=auto|grep|restart" | awk '{ print $2 }')
|
||||||
PID=($(echo "$PID" | tr '\n' ' '))
|
PID=($(echo "$PID" | tr '\n' ' '))
|
||||||
|
|
||||||
|
sendalerte() {
|
||||||
|
actionAlerte="$1"
|
||||||
|
date=$(date +"%Hh%M")
|
||||||
|
|
||||||
|
mutt -e "set from='duniter-g1@p2p.legal'" -e "set content_type=text/html" -e "set charset=UTF-8" -s "Alerte noeud ğ1 resync à $date !" $myEmail <<MAIL_END
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<body style="color:#1C1C1C; margin:2% 2%;">
|
||||||
|
|
||||||
|
<center><h3>Mon noeud ğ1 a été $actionAlerte</h3></center>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
Par précaution, ce scrip a été locké $lock fois.
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
MAIL_END
|
||||||
|
}
|
||||||
|
|
||||||
if [[ -z $PID ]]; then
|
if [[ -z $PID ]]; then
|
||||||
$rep/duniter-restart.sh
|
$MY_PATH/duniter-restart.sh
|
||||||
actionAlerte="redémarré"
|
sendalerte "redémarré"
|
||||||
sendalerte
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pokaNode=$(curl -s http://192.168.9.54:45000/blockchain/current | jq '.number')
|
myBMA=$(netstat -pnl 2>/dev/null | grep "duniter_defaul" | grep ":45000" | awk '{ print $4 }')
|
||||||
|
myNode=$(curl -s http://$myBMA/blockchain/current | jq '.number')
|
||||||
refNode=$(curl -s $refname/blockchain/current | jq '.number')
|
refNode=$(curl -s $refname/blockchain/current | jq '.number')
|
||||||
|
|
||||||
[[ -e $lockSync ]] && lock=$(cat $lockSync)
|
[[ -e $lockSync ]] && lock=$(cat $lockSync)
|
||||||
if [[ -z $pokaNode ]]; then
|
if [[ -z $myNode ]]; then
|
||||||
if [[ $lock > 3 ]]; then
|
if [[ $lock > 3 ]]; then
|
||||||
rm $lockSync
|
rm $lockSync
|
||||||
touch $lockSync
|
touch $lockSync
|
||||||
|
@ -37,54 +63,23 @@ if [[ -z $pokaNode ]]; then
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
[[ $(cat $lockSync) != 0 ]] && echo 0 > $lockSync
|
[[ $(cat $lockSync) != 0 ]] && echo 0 > $lockSync
|
||||||
diffNode=$(($refNode - $pokaNode))
|
diffNode=$(($refNode - $myNode))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
checkg1() {
|
checkg1() {
|
||||||
|
echo "Mon noeud est au block $myNode tandi que le noeud $refName est à $refNode"
|
||||||
|
|
||||||
echo "Mon noeud est au block $pokaNode tandi que le noeud $refName est à $refNode"
|
if [[ $myNode < $refNode ]]; then
|
||||||
|
echo "Mon noeud est à la bourre, il a $diffNode blocks de retard ..."
|
||||||
if [[ $pokaNode < $refNode ]]; then
|
|
||||||
echo "Mon noeud est à la bourre, il a $diffNode blocks de retard ..."
|
|
||||||
else
|
|
||||||
echo "Tout est bon!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
sendalerte() {
|
|
||||||
|
|
||||||
TO="poka@p2p.legal"
|
|
||||||
date=$(date +"%Hh%M")
|
|
||||||
|
|
||||||
mutt -e "set from='duniter-g1@p2p.legal'" -e "set content_type=text/html" -e "set charset=UTF-8" -s "Alerte noeud ğ1 resync à $date !" $TO <<MAIL_END
|
|
||||||
|
|
||||||
<html>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
||||||
<body style="color:#1C1C1C; margin:2% 2%;">
|
|
||||||
|
|
||||||
<center><h3>Le noeud ğ1 de Poka a été $actionAlerte</h3></center>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
Par précaution, ce scrip a été locké $lock fois.
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
MAIL_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
checkg1
|
|
||||||
#sendalerte
|
|
||||||
|
|
||||||
if [[ $1 == "auto" ]]; then
|
|
||||||
if [ $diffNode -gt 5 ]; then
|
|
||||||
actionAlerte="resynchronisé"
|
|
||||||
sendalerte
|
|
||||||
bash $rep/duniter-resync.sh > /dev/null 2>&1
|
|
||||||
else
|
else
|
||||||
exit 0
|
echo "Tout est bon!"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
checkg1
|
||||||
|
|
||||||
|
if [ $diffNode -gt 5 ]; then
|
||||||
|
[[ $1 == "auto" ]] && sendalerte "resynchronisé"
|
||||||
|
bash $MY_PATH/duniter-resync.sh > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue