From 080ff36af444c685b9a85c4adfa1563a10311141 Mon Sep 17 00:00:00 2001 From: poka Date: Wed, 24 Jun 2020 21:11:49 +0200 Subject: [PATCH] first --- .gitignore | 2 + README.md | 1 + duniter-checkBlock.sh | 90 +++++++++++++++++++++++++++++++++++++++++++ duniter-restart.sh | 20 ++++++++++ duniter-resync.sh | 36 +++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 duniter-checkBlock.sh create mode 100755 duniter-restart.sh create mode 100755 duniter-resync.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bab1ff4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +lock-sync +link diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ffdc8a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Basics scripts to manage Duniter/Ḡ1 node. diff --git a/duniter-checkBlock.sh b/duniter-checkBlock.sh new file mode 100755 index 0000000..95612c0 --- /dev/null +++ b/duniter-checkBlock.sh @@ -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 < + + + +

Le noeud ğ1 de Poka a été $actionAlerte

+
+ +Par précaution, ce scrip a été locké $lock fois. + + + +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 diff --git a/duniter-restart.sh b/duniter-restart.sh new file mode 100755 index 0000000..c287146 --- /dev/null +++ b/duniter-restart.sh @@ -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 diff --git a/duniter-resync.sh b/duniter-resync.sh new file mode 100755 index 0000000..35e8784 --- /dev/null +++ b/duniter-resync.sh @@ -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