This commit is contained in:
poka 2020-11-10 23:54:46 +01:00
commit d201013251
2 changed files with 49 additions and 60 deletions

View File

@ -1,31 +1,57 @@
#!/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')
echo "############################"
echo "$date"
rep="/home/poka/scripts"
lock=0
lockSync="/home/poka/scripts/lock-sync"
lockSync="$MY_PATH/lock-sync"
[[ -n $lockSync ]] && touch $lockSync
PID=$(ps auxf | grep "duniter" | grep -v -E "color=auto|grep|restart" | awk '{ print $2 }')
PID=($(echo "$PID" | tr '\n' ' '))
pokaNode=$(curl -s http://192.168.9.54:45000/blockchain/current | jq '.number')
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
}
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')
if [[ -z $PID || -z $pokaNode ]]; then
$rep/duniter-restart.sh
actionAlerte="redémarré"
sendalerte
$MY_PATH/duniter-restart.sh
sendalerte "redémarré"
exit 0
fi
[[ -e $lockSync ]] && lock=$(cat $lockSync)
if [[ -z $pokaNode ]]; then
if [[ -z $myNode ]]; then
if [[ $lock > 3 ]]; then
rm $lockSync
touch $lockSync
@ -37,54 +63,23 @@ if [[ -z $pokaNode ]]; then
fi
else
[[ $(cat $lockSync) != 0 ]] && echo 0 > $lockSync
diffNode=$(($refNode - $pokaNode))
diffNode=$(($refNode - $myNode))
fi
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 [[ $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
if [[ $myNode < $refNode ]]; then
echo "Mon noeud est à la bourre, il a $diffNode blocks de retard ..."
else
exit 0
echo "Tout est bon!"
fi
}
checkg1
if [ $diffNode -gt 5 ]; then
[[ $1 == "auto" ]] && sendalerte "resynchronisé"
bash $MY_PATH/duniter-resync.sh > /dev/null 2>&1
fi
exit 0

View File

@ -1,18 +1,12 @@
#!/bin/bash
node=g1.presles.fr
#g1.cgeek.fr
#node=duniter.moul.re
log="/var/log/duniter-resync.log"
oldlog="/home/poka/scripts/old-resync.log"
node=g1.presles.fr #g1.cgeek.fr #node=duniter.moul.re
log="$HOME/duniter-resync.log"
echo "Début de la resynchronisation du noeud Duniter"
/usr/bin/duniter stop
sleep 1
tail -n 1 $log >> $oldlog
sleep 0.5
[[ $1 == "erase" ]] && rm -rf ~/.config/duniter/duniter_default/data/
/usr/bin/duniter sync $node --nointeractive > $log 2>&1 &
@ -27,7 +21,7 @@ wait $BACK_PID
kill -9 $LOG_PID
sleep 1
sleep 0.5
/usr/bin/duniter webstart