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 state-prev.txt ] && mv state-prev.txt state.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
 
  24 # Read in initial state
 
  30     # Work out the name of the next file
 
  31     file="changes-${sequenceNumber}.osc.gz"
 
  33     # Save state file so we can rollback if an error occurs
 
  34     cp state.txt state-prev.txt
 
  36     # Fetch the next set of changes
 
  37     osmosis --read-replication-interval --simc --write-xml-change file="${file}" compressionMethod="gzip"
 
  42         # Enable exit on error
 
  45         # Remember the previous sequence number
 
  46         prevSequenceNumber=$sequenceNumber
 
  51         # Did we get any new data?
 
  52         if [ "${sequenceNumber}" == "${prevSequenceNumber}" ]
 
  54             # Log the lack of data
 
  55             echo "No new data available. Sleeping..."
 
  57             # Remove file, it will just be an empty changeset
 
  60             # No need to rollback now
 
  63             # Sleep for a short while
 
  67             echo "Fetched new data from ${prevSequenceNumber} to ${sequenceNumber} into ${file}"
 
  69             # Apply the changes to the database
 
  70             osm2pgsql --database gis --slim --append --number-processes=1 \
 
  71 <% if node[:tile][:node_file] -%>
 
  72                       --flat-nodes=<%= node[:tile][:node_file] %> \
 
  74 <% if node[:tile][:styles][:default][:revision] >= "v4.0.0" -%>
 
  75                       --multi-geometry --hstore \
 
  76                       --style=/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.style \
 
  77                       --tag-transform-script=/srv/tile.openstreetmap.org/styles/default/openstreetmap-carto.lua \
 
  81             # No need to rollback now
 
  84             # Queue these changes for expiry processing
 
  85             ln ${file} expire-queue/$file
 
  88         # Delete old downloads
 
  89         find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \;
 
  91         # Disable exit on error
 
  94         # Log our failure to fetch changes
 
  95         echo "Failed to fetch changes - waiting a few minutes before retry"
 
  97         # Wait five minutes and have another go