This commit is contained in:
poka 2020-06-24 21:11:49 +02:00
commit 080ff36af4
5 changed files with 149 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
lock-sync
link

1
README.md Normal file
View File

@ -0,0 +1 @@
Basics scripts to manage Duniter/Ḡ1 node.

90
duniter-checkBlock.sh Executable file
View File

@ -0,0 +1,90 @@
#!/bin/bash
refname="https://g1.cgeek.fr"
date=$(date '+%d-%m-%y à %H:%M')
echo "############################"
echo "$date"
rep="/home/poka/scripts"
lock=0
lockSync="/home/poka/scripts/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' ' '))
if [[ -z $PID ]]; then
$rep/duniter-restart.sh
actionAlerte="redémarré"
sendalerte
exit 0
fi
pokaNode=$(curl -s http://192.168.9.54:45000/blockchain/current | jq '.number')
refNode=$(curl -s $refname/blockchain/current | jq '.number')
[[ -e $lockSync ]] && lock=$(cat $lockSync)
if [[ -z $pokaNode ]]; then
if [[ $lock > 3 ]]; then
rm $lockSync
touch $lockSync
diffNode=6
else
((lock++))
echo $lock > $lockSync
diffNode=0
fi
else
[[ $(cat $lockSync) != 0 ]] && echo 0 > $lockSync
diffNode=$(($refNode - $pokaNode))
fi
checkg1() {
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
else
exit 0
fi
fi
exit 0

20
duniter-restart.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
date=$(date '+%d-%m-%y à %H:%M')
echo "############################"
echo "$date"
/usr/bin/duniter stop
PID=$(ps auxf | grep "duniter" | grep -v -E "color=auto|grep|restart" | awk '{ print $2 }')
PID=($(echo "$PID" | tr '\n' ' '))
if [[ ! -z $PID ]]; then
echo "Kill PID ${PID[@]}"
kill -9 "${PID[@]}"
fi
sleep 1
/usr/bin/duniter webstart
exit 0

36
duniter-resync.sh Executable file
View File

@ -0,0 +1,36 @@
#!/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"
echo "Début de la resynchronisation du noeud Duniter"
/usr/bin/duniter stop
sleep 1
tail -n 1 $log >> $oldlog
[[ $1 == "erase" ]] && rm -rf ~/.config/duniter/duniter_default/data/
/usr/bin/duniter sync $node --nointeractive > $log 2>&1 &
BACK_PID=$!
sleep 1
tail $log -f | grep ", Applied" &
LOG_PID=$!
wait $BACK_PID
kill -9 $LOG_PID
sleep 1
/usr/bin/duniter webstart
echo "Duniter a été resyncrhonisé"
exit 0