X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/8e9e103e9f748fe7a104c4fba00cc72a847e2d3a..f7546eabebf1b335815bf9c5de2dd7689ac143e1:/cookbooks/tile/templates/default/replicate.erb diff --git a/cookbooks/tile/templates/default/replicate.erb b/cookbooks/tile/templates/default/replicate.erb index 862b6a5e7..aa69177ec 100644 --- a/cookbooks/tile/templates/default/replicate.erb +++ b/cookbooks/tile/templates/default/replicate.erb @@ -2,16 +2,25 @@ # DO NOT EDIT - This file is being maintained by Chef -# Initialize timestamp with day of latest planet dump -# Setting to midnight ensures we get conistent data after first run -# osmosis --read-replication-interval-init +# Before running updates, the replication needs to be set up with the timestamp +# set to the day of the latest planet dump. Setting to midnight ensures we get +# conistent data after first run. osmosis --read-replication-interval-init is +# used to initially create the state file + +# Define exit handler +function onexit { + [ -f state-prev.txt ] && mv state-prev.txt state.txt +} # Send output to the log -exec > /var/log/replicate/replicate.log 2>&1 +exec > /var/log/tile/replicate.log 2>&1 # Change to the replication state directory cd /var/lib/replicate +# Install exit handler +trap onexit EXIT + # Read in initial state . state.txt @@ -19,7 +28,10 @@ cd /var/lib/replicate while true do # Work out the name of the next file - file="changes-${sequenceNumber}.osm.gz" + file="changes-${sequenceNumber}.osc.gz" + + # Save state file so we can rollback if an error occurs + cp state.txt state-prev.txt # Fetch the next set of changes osmosis --read-replication-interval --simc --write-xml-change file="${file}" compressionMethod="gzip" @@ -28,50 +40,61 @@ do if [ $? -eq 0 ] then # Enable exit on error - set -e + set -e # Remember the previous sequence number - prevSequenceNumber=$sequenceNumber + prevSequenceNumber=$sequenceNumber # Read in new state - . state.txt + . state.txt # Did we get any new data? - if [ "${sequenceNumber}" == "${prevSequenceNumber}" ] + if [ "${sequenceNumber}" == "${prevSequenceNumber}" ] then # Log the lack of data - echo "No new data available. Sleeping..." + echo "No new data available. Sleeping..." - # Remove file, it will just be an empty changeset - rm ${file} + # Remove file, it will just be an empty changeset + rm ${file} + + # No need to rollback now + rm state-prev.txt # Sleep for a short while - sleep 30 - else + sleep 30 + else # Log the new data - echo "Fetched new data from ${prevSequenceNumber} to ${sequenceNumber} into ${file}" + echo "Fetched new data from ${prevSequenceNumber} to ${sequenceNumber} into ${file}" # Apply the changes to the database + osm2pgsql --database gis --slim --append --number-processes=1 \ <% if node[:tile][:node_file] -%> - osm2pgsql --slim --append --flat-nodes=<%= node[:tile][:node_file] %> ${file} -<% else -%> - osm2pgsql --slim --append ${file} + --flat-nodes=<%= node[:tile][:node_file] %> \ +<% end -%> +<% if node[:tile][:styles][:default][:revision] >= "v4.0.0" -%> + --multi-geometry --hstore \ + --style=/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.style \ + --tag-transform-script=/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.lua \ <% end -%> + ${file} + + # No need to rollback now + rm state-prev.txt - # Expire tiles which are touched by the changes - /usr/local/bin/expire-tiles ${file} > /dev/null 2>&1 & - fi + # Queue these changes for expiry processing + ln ${file} expire-queue/$file + fi # Delete old downloads - find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \; + find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \; # Disable exit on error set +e else # Log our failure to fetch changes - echo "Failed to fetch changes - waiting a few minutes before retry" + echo "Failed to fetch changes - waiting a few minutes before retry" # Wait five minutes and have another go - sleep 300 + sleep 300 fi done