forked from kamba4/sunders
moved files into subdirs
This commit is contained in:
parent
bf6ccf5094
commit
10fcf55b10
242 changed files with 23 additions and 0 deletions
93
data_handler/utils/update_camera.sh
Normal file
93
data_handler/utils/update_camera.sh
Normal file
|
@ -0,0 +1,93 @@
|
|||
#!/bin/bash
|
||||
|
||||
exedir=$(cd `dirname "$0"`; pwd)
|
||||
|
||||
REPLICATE_URL=`grep "REPLICATE_URL" "$exedir/config.php" | sed -e 's/.*http/http/' -e 's#...$##' `
|
||||
|
||||
if [ -e "/var/lock/update_camera" ]
|
||||
then
|
||||
# Maybe an other update is running
|
||||
otherPid=$(cat "/var/lock/update_camera")
|
||||
count=$(ps $otherPid | grep -c `basename "$0"`)
|
||||
|
||||
if [ $count -gt 0 ]
|
||||
then
|
||||
echo "$0 is running yet. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# OK. We can update the database...
|
||||
echo $$ > "/var/lock/update_camera"
|
||||
|
||||
exeDir=$(cd `dirname "$0"`; pwd);
|
||||
cd "$exeDir"
|
||||
|
||||
if [ -e "state.txt" ]
|
||||
then
|
||||
rm "state.txt"
|
||||
fi
|
||||
|
||||
#TODO get state from db
|
||||
# Read the last update timestamp
|
||||
# lastTimestamp=$(grep "^timestamp=" "lastState.txt" | cut -d'=' -f2-)
|
||||
# lastSeqNum=$(grep "^sequenceNumber=" "lastState.txt" | cut -d'=' -f2-)
|
||||
|
||||
lastSeqNum=$(php get_sync_state.php)
|
||||
|
||||
curl -L "$REPLICATE_URL/state.txt" -o state.txt
|
||||
|
||||
newTimestamp=$(grep "^timestamp=" "state.txt" | cut -d'=' -f2-)
|
||||
newSeqNum=$(grep "^sequenceNumber=" "state.txt" | cut -d'=' -f2-)
|
||||
|
||||
if [ $newSeqNum -eq $lastSeqNum ]
|
||||
then
|
||||
echo "No new file to be processed"
|
||||
exit 1
|
||||
fi
|
||||
mkdir logs
|
||||
curSeqNum=$lastSeqNum
|
||||
while [ $curSeqNum -lt $newSeqNum ]
|
||||
do
|
||||
curSeqNum=$(( $curSeqNum + 1 ))
|
||||
|
||||
logFileName="logs/log.$curSeqNum"
|
||||
|
||||
if [ -e "change_file.osc" ]
|
||||
then
|
||||
rm "change_file.osc"
|
||||
fi
|
||||
|
||||
if [ -e "change_file.osc.gz" ]
|
||||
then
|
||||
rm "change_file.osc.gz"
|
||||
fi
|
||||
|
||||
echo `date "+%d/%m/%Y %H:%M"`" - Start processing sequence number $curSeqNum" > "$logFileName"
|
||||
|
||||
targetDirName=`echo "000000000$curSeqNum" | sed 's#.*\(...\)\(...\)\(...\)$#\1/\2/\3.osc.gz#'`
|
||||
targetDirName="$REPLICATE_URL/$targetDirName"
|
||||
|
||||
curl -L "$targetDirName" -o change_file.osc.gz 2>&1 | tee -a $logFileName
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
echo "Error during recovery of $targetDirName" | tee -a $logFileName
|
||||
exit 1
|
||||
fi
|
||||
|
||||
gunzip change_file.osc.gz 2>&1 | tee -a $logFileName
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
echo "Error during decompression of $targetDirName" | tee -a $logFileName
|
||||
exit 1
|
||||
fi
|
||||
|
||||
php update_camera.php $curSeqNum 2>&1 | tee -a $logFileName
|
||||
|
||||
targetDirName=`echo "$targetDirName" | sed 's/.osc.gz$/.state.txt/'`
|
||||
|
||||
curl -L "$targetDirName" -o lastState.txt 2>&1 | tee -a $logFileName
|
||||
echo `date "+%d/%m/%Y %H:%M"`" - Finish processing sequence number $curSeqNum" | tee -a "$logFileName"
|
||||
done
|
||||
|
||||
rm "/var/lock/update_camera"
|
Loading…
Add table
Add a link
Reference in a new issue