]> git.openstreetmap.org Git - chef.git/blob - cookbooks/taginfo/templates/default/update-planet.erb
Avoid errors rotating logs on nodes where gpx-import is stopped
[chef.git] / cookbooks / taginfo / templates / default / update-planet.erb
1 #!/bin/sh
2
3 # DO NOT EDIT - This file is being maintained by Chef
4
5 # abort on error
6
7 set -e
8
9 # setup
10
11 PLANETDIR="<%= @directory %>/planet"
12 LOGDIR="${PLANETDIR}/log"
13 PLANETPREV="${PLANETDIR}/planet-previous.pbf"
14 PLANETCURR="${PLANETDIR}/planet.pbf"
15 PLANETNEW="${PLANETDIR}/planet-new.pbf"
16 STATEDIR="${PLANETDIR}/replication"
17 OSCFILE="${PLANETDIR}/$(date +%Y%m%d-%H%M).osc"
18 OSCFILEPREV="${PLANETDIR}/previous.osc"
19
20 OSMIUM=<%= @directory %>/osmium-tool/build/src/osmium
21
22 # start logging
23
24 exec > "${LOGDIR}/$(date +%Y%m%d-%H%M).log" 2>&1
25
26 # if there are old .osc files, they have to be taken into account
27
28 OLDFILE="$(find "${PLANETDIR}" -name "2*-*.osc" -print)"
29 if [ -z "$OLDFILE" ]
30 then
31    osmosis --rri "$STATEDIR" --simc --write-xml-change "$OSCFILE"
32 else
33    osmosis --rxc "$OLDFILE" --rri "$STATEDIR" --mc --simc --write-xml-change "$OSCFILE" && rm "$OLDFILE"
34 fi
35
36 # osc file is ready, create new planet file
37
38 #osmosis --read-xml-change "$OSCFILE" --read-bin "$PLANETCURR" --buffer bufferCapacity=12000 --apply-change --buffer bufferCapacity=12000 --write-pbf file="$PLANETNEW"
39 $OSMIUM apply-changes --verbose --remove-deleted --simplify --fsync --output=$PLANETNEW $PLANETCURR $OSCFILE
40
41 # cleanup
42
43 mv "$PLANETCURR" "$PLANETPREV"
44 mv "$PLANETNEW" "$PLANETCURR"
45 mv "$OSCFILE" "$OSCFILEPREV"
46
47 # expire old logs
48
49 find "${LOGDIR}" -mtime +28 -delete