-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathlgd-run-sync.sh
More file actions
executable file
·70 lines (51 loc) · 2.06 KB
/
lgd-run-sync.sh
File metadata and controls
executable file
·70 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
configFileName="$1"
#osmosis={osmosis:-osmosis}
osmosis="osmosis"
targetPath=${targetPath:-"sync"}
OSM_DATA_SYNC_RECHECK_INTERVAL=${OSM_DATA_SYNC_RECHECK_INTERVAL:-60}
log() { echo "[`date +'%Y-%m-%d %H:%M:%S'`] $$ [$1] $2" ; }
echo "Starting LinkedGeoData live update (based on osmosis)..."
if [ ! -z "$configFileName" ]; then
if [ ! -f "$configFileName" ]; then
log "info" "No config found, attempting to copy '$configFileName.dist' to '$configFileName'"
cp "$configFileName.dist" "$configFileName"
fi
if ! source "$configFileName"; then
log "error" "Could not load config file: '$configFileName'"
exit 1
fi
fi
mkdir -p "$targetPath"
# Check if we need to initialize the working directory
if [ ! -f "$targetPath/configuration.txt" ]; then
"$osmosis" --read-replication-interval-init workingDirectory="$targetPath"
if [ "$?" -eq "0" ]; then
log "info" "Osmosis target directory has been initialized. Please check configuration in $targetPath, then run this script again"
else
log "error" "Osmosis exited with error code ($?)"
exit 1
fi
exit 0
fi
applyChanges() {
h="$DB_HOST"
if [ ! -z "$DB_PORT" ]; then
h="$DB_HOST:$DB_PORT"
fi
if [ -f "$targetPath/diff.osc" ]; then
"$osmosis" --read-xml-change file="$targetPath/diff.osc" --write-pgsimp-change host="$h" database="$DB_NAME" user="$DB_USER" password="$DB_PASS"
# TODO Decide whether the old diffs should be kept or removed
# Remove possibly existing diff.osc file
rm "$targetPath/diff.osc"
fi
}
# Apply changes that might not have been applied yet
applyChanges
while [ 1 ]; do
"$osmosis" --read-replication-interval workingDirectory=$targetPath --simplify-change --write-xml-change "$targetPath/diff.osc"
applyChanges
# TODO Enhance script to compute time duration to next recheck interval based on timestamp in latest state.txt file
echo "Going to sleep for $OSM_DATA_SYNC_RECHECK_INTERVAL seconds..."
sleep "$OSM_DATA_SYNC_RECHECK_INTERVAL"
done