3 # DO NOT EDIT - This file is being maintained by Chef
5 # Before running updates, the replication needs to be set up with the timestamp
6 # set to the day of the latest planet dump. Setting to midnight ensures we get
7 # conistent data after first run. osmosis --read-replication-interval-init is
8 # used to initially create the state file
12 [ -f sequence-prev.txt ] && mv sequence-prev.txt sequence.txt
15 # Send output to the log
16 exec > /var/log/tile/replicate.log 2>&1
18 # Change to the replication state directory
21 # Install exit handler
27 # Work out the name of the next file
28 file="changes-$(cat sequence.txt).osc.gz"
30 # Save sequence file so we can rollback if an error occurs
31 cp sequence.txt sequence-prev.txt
33 # Fetch the next set of changes
34 pyosmium-get-changes --sequence-file=sequence.txt --outfile=${file}
42 # Enable exit on error
46 echo "Fetched new data from $(cat sequence-prev.txt) to $(cat sequence.txt) into ${file}"
48 # Apply the changes to the database
49 osm2pgsql --database gis --slim --append --number-processes=1 \
50 <% if node[:tile][:node_file] -%>
51 --flat-nodes=<%= node[:tile][:node_file] %> \
53 <% if node[:tile][:styles][:default][:revision] >= "v4.0.0" -%>
54 --multi-geometry --hstore \
55 --style=/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.style \
56 --tag-transform-script=/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.lua \
60 # No need to rollback now
64 buffers=$(osmium fileinfo --extended --get=data.buffers.count ${file})
66 # If this diff has content mark it as the latest diff
69 ln -f ${file} changes-latest.osc.gz
72 # Queue these changes for expiry processing
73 ln ${file} expire-queue/${file}
75 # Delete old downloads
76 find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \;
78 # Disable exit on error
80 elif [ $status -eq 3 ]
82 # Log the lack of data
83 echo "No new data available. Sleeping..."
85 # Remove file, it will just be an empty changeset
88 # Sleep for a short while
91 # Log our failure to fetch changes
92 echo "Failed to fetch changes - waiting a few minutes before retry"
94 # Remove any output that was produced
97 # Wait five minutes and have another go