Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amélioration du script afin de gérer le cas de SEQ vide ou non numérique et des soucis de certificats ssl #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions backend/cron-dl-robust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#! /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)"
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 -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 --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"

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 --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 --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

echo $SEQ > /data/work/$USER/prev-seq
exit $return_code