From d5ac66d3486c46c9bc1a17b8e995dbdd2872186d Mon Sep 17 00:00:00 2001 From: marc-marc-marc Date: Wed, 25 Oct 2023 10:52:17 +0200 Subject: [PATCH 1/2] commit du script existant sur le serveur --- backend/cron-dl-robust.sh | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 backend/cron-dl-robust.sh diff --git a/backend/cron-dl-robust.sh b/backend/cron-dl-robust.sh new file mode 100755 index 0000000..a80e142 --- /dev/null +++ b/backend/cron-dl-robust.sh @@ -0,0 +1,64 @@ +#! /bin/bash + +USER=live + +SOURCE=https://download.openstreetmap.fr/replication/planet/minute/ +SOURCE2=https://planet.openstreetmap.org/replication/minute/ +SWITCH=0 + +LOCK_FILE=/run/lock/$USER-crontab-backend + +DELAY=10 + +exec 200>"$LOCK_FILE" +flock -n 200 +RC=$? +if [ "$RC" != 0 ]; then + echo "ERROR: Already running script. Try again after sometime" + exit 1 +fi + +if [ -e /data/work/$USER/prev-seq ]; then + PREV_SEQ="$(cat /data/work/$USER/prev-seq)" +else + PREV_SEQ=0 +fi +echo "DEBUG: PREV_SEQ $PREV_SEQ" + +[ $(date +%S) -le 10 ] && echo "DEBUG: trop proche de la minute ronde. attente de quelques secondes" && sleep 12 +echo "DEBUG: wget $SOURCE/state.txt" +SEQ=`wget -4 -o /dev/null -O /dev/stdout $SOURCE/state.txt|grep sequenceNumber|cut -d '=' -f 2` + +if (( SEQ <= PREV_SEQ-DELAY )); then + echo "WARNING: downloaded SEQ $SEQ <= PREV_SEQ $PREV_SEQ" + echo "INFO: Switch to $SOURCE2" + SEQ=`wget -4 -o /dev/null -O /dev/stdout $SOURCE2/state.txt|grep sequenceNumber|cut -d '=' -f 2` + SWITCH=1 +fi +echo "DEBUG: downloaded SEQ $SEQ" + +echo "INFO: PREV_SEQ $PREV_SEQ SEQ $SEQ" + +MM=$[$SEQ/1000000] +KK=$[$SEQ-$MM*1000000] +KK=$[$KK/1000] +UU=$[$SEQ-$MM*1000000-$KK*1000] +A=`printf %03d $MM` +B=`printf %03d $KK` +C=`printf %03d $UU` + +echo "DEBUG: $SEQ mean $A/$B/$C" +if [ "$SWITCH" = 1 ]; then + echo "$SOURCE2/$A/$B/$C.osc.gz" + wget -4 -o /dev/null -O /dev/stdout $SOURCE2/$A/$B/$C.osc.gz|gunzip -c|chronic python3 compute-changeset-data.py + return_code="${?}" + echo "DEBUG: return_code $return_code" +else + echo "$SOURCE/$A/$B/$C.osc.gz" + wget -4 -o /dev/null -O /dev/stdout $SOURCE/$A/$B/$C.osc.gz|gunzip -c|chronic python3 compute-changeset-data.py + return_code="${?}" + echo "DEBUG: return_code $return_code" +fi + +echo $SEQ > /data/work/$USER/prev-seq +exit $return_code From 0ff4efaea79575fb44e4f30b8c8d4866ae1c5a35 Mon Sep 17 00:00:00 2001 From: marc-marc-marc Date: Wed, 25 Oct 2023 11:03:04 +0200 Subject: [PATCH 2/2] =?UTF-8?q?am=C3=A9lioration=20du=20script=20afin=20de?= =?UTF-8?q?=20g=C3=A9rer=20le=20cas=20de=20SEQ=20vide=20ou=20non=20numeriq?= =?UTF-8?q?ue=20et=20des=20soucis=20de=20certificats=20ssl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/cron-dl-robust.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/cron-dl-robust.sh b/backend/cron-dl-robust.sh index a80e142..074a5a3 100755 --- a/backend/cron-dl-robust.sh +++ b/backend/cron-dl-robust.sh @@ -20,19 +20,36 @@ fi if [ -e /data/work/$USER/prev-seq ]; then PREV_SEQ="$(cat /data/work/$USER/prev-seq)" + if [ $PREV_SEQ -ge 0 ] 2>/dev/null; then + echo "DEBUG: PREV_SEQ est numerique" + else + echo "ERROR: PREV_SEQ n est pas numerique. rm /data/work/$USER/prev-seq et init PREV_SEQ=0" + echo "ERROR: PREV_SEQ n est pas numerique. rm /data/work/$USER/prev-seq et init PREV_SEQ=0" >&2 + rm -f /data/work/$USER/prev-seq + PREV_SEQ=0 + fi else + echo "WARN: fichier /data/work/$USER/prev-seq absent. init PREV_SEQ=0" PREV_SEQ=0 fi echo "DEBUG: PREV_SEQ $PREV_SEQ" [ $(date +%S) -le 10 ] && echo "DEBUG: trop proche de la minute ronde. attente de quelques secondes" && sleep 12 -echo "DEBUG: wget $SOURCE/state.txt" -SEQ=`wget -4 -o /dev/null -O /dev/stdout $SOURCE/state.txt|grep sequenceNumber|cut -d '=' -f 2` +echo "DEBUG: wget -4 --no-check-certificate -o /dev/null -O /dev/stdout $SOURCE/state.txt|grep sequenceNumber|cut -d '=' -f 2" +SEQ=`wget -4 --no-check-certificate -o /dev/null -O /dev/stdout $SOURCE/state.txt|grep sequenceNumber|cut -d '=' -f 2` + +if [ $SEQ -ge 0 ] 2>/dev/null; then + echo "DEBUG: SEQ est numerique" +else + echo "ERROR: SEQ n est pas numerique" + echo "ERROR: SEQ n est pas numerique" >&2 + exit 2 +fi if (( SEQ <= PREV_SEQ-DELAY )); then echo "WARNING: downloaded SEQ $SEQ <= PREV_SEQ $PREV_SEQ" echo "INFO: Switch to $SOURCE2" - SEQ=`wget -4 -o /dev/null -O /dev/stdout $SOURCE2/state.txt|grep sequenceNumber|cut -d '=' -f 2` + SEQ=`wget -4 --no-check-certificate -o /dev/null -O /dev/stdout $SOURCE2/state.txt|grep sequenceNumber|cut -d '=' -f 2` SWITCH=1 fi echo "DEBUG: downloaded SEQ $SEQ" @@ -50,12 +67,12 @@ C=`printf %03d $UU` echo "DEBUG: $SEQ mean $A/$B/$C" if [ "$SWITCH" = 1 ]; then echo "$SOURCE2/$A/$B/$C.osc.gz" - wget -4 -o /dev/null -O /dev/stdout $SOURCE2/$A/$B/$C.osc.gz|gunzip -c|chronic python3 compute-changeset-data.py + wget -4 --no-check-certificate -o /dev/null -O /dev/stdout $SOURCE2/$A/$B/$C.osc.gz|gunzip -c|chronic python3 compute-changeset-data.py return_code="${?}" echo "DEBUG: return_code $return_code" else echo "$SOURCE/$A/$B/$C.osc.gz" - wget -4 -o /dev/null -O /dev/stdout $SOURCE/$A/$B/$C.osc.gz|gunzip -c|chronic python3 compute-changeset-data.py + wget -4 --no-check-certificate -o /dev/null -O /dev/stdout $SOURCE/$A/$B/$C.osc.gz|gunzip -c|chronic python3 compute-changeset-data.py return_code="${?}" echo "DEBUG: return_code $return_code" fi