X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/35171e1e6bceb46b7d575de5dda768eb97f4bd49..96e2ac0bfb678221faaa0feba7039deeb853ddf0:/cookbooks/tile/templates/default/replicate.erb diff --git a/cookbooks/tile/templates/default/replicate.erb b/cookbooks/tile/templates/default/replicate.erb index 81fc66419..88917dff2 100644 --- a/cookbooks/tile/templates/default/replicate.erb +++ b/cookbooks/tile/templates/default/replicate.erb @@ -1,100 +1,26 @@ -#!/bin/bash +#!/bin/sh # DO NOT EDIT - This file is being maintained by Chef -# 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 sequence-prev.txt ] && mv sequence-prev.txt sequence.txt -} - -# Send output to the log -exec > /var/log/tile/replicate.log 2>&1 - -# Change to the replication state directory -cd /var/lib/replicate - -# Install exit handler -trap onexit EXIT - -# Loop indefinitely -while true +while [ 1 = 1 ] do - # Work out the name of the next file - file="changes-$(cat sequence.txt).osc.gz" - - # Save sequence file so we can rollback if an error occurs - cp sequence.txt sequence-prev.txt - - # Fetch the next set of changes - pyosmium-get-changes --sequence-file=sequence.txt --outfile=${file} - - # Save exit status - status=$? - - # Check for errors - if [ $status -eq 0 ] - then - # Enable exit on error - set -e - - # Log the new data - echo "Fetched new data from $(cat sequence-prev.txt) to $(cat sequence.txt) into ${file}" - - # Apply the changes to the database - osm2pgsql --database gis --slim --append --number-processes=1 \ -<% if node[:tile][:node_file] -%> - --flat-nodes=<%= node[:tile][:node_file] %> \ + /bin/osm2pgsql-replication update \ + --database gis \ + --post-processing /usr/local/bin/replicate-post \ + -- \ + --number-processes=1 \ + --log-progress=false \ + --expire-tiles=13-19 \ + --expire-output=/var/lib/replicate/dirty-tiles.txt \ +<% if node[:tile][:database][:multi_geometry] -%> + --multi-geometry \ <% 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 \ +<% if node[:tile][:database][:hstore] -%> + --hstore \ +<% end -%> +<% if node[:tile][:database][:tag_transform_script] -%> + --tag-transform-script=<%= node[:tile][:database][:tag_transform_script] %> <% end -%> - ${file} - - # No need to rollback now - rm sequence-prev.txt - - # Get buffer count - buffers=$(osmium fileinfo --extended --get=data.buffers.count ${file}) - - # If this diff has content mark it as the latest diff - if [ $buffers -gt 0 ] - then - ln -f ${file} changes-latest.osc.gz - fi - - # Queue these changes for expiry processing - ln ${file} expire-queue/${file} - - # Delete old downloads - find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \; - - # Disable exit on error - set +e - elif [ $status -eq 3 ] - then - # Log the lack of data - echo "No new data available. Sleeping..." - - # Remove file, it will just be an empty changeset - rm ${file} - - # Sleep for a short while - sleep 30 - else - # Log our failure to fetch changes - echo "Failed to fetch changes - waiting a few minutes before retry" - - # Remove any output that was produced - rm -f ${file} - # Wait five minutes and have another go - sleep 300 - fi + sleep 30 done