3 # DO NOT EDIT - This file is being maintained by Chef
 
   5 # Initialize timestamp with day of latest planet dump
 
   6 # Setting to midnight ensures we get conistent data after first run
 
   7 # osmosis --read-replication-interval-init
 
  11     [ -f state-prev.txt ] && mv state-prev.txt state.txt
 
  14 # Send output to the log
 
  15 exec > /var/log/tile/replicate.log 2>&1
 
  17 # Change to the replication state directory
 
  20 # Install exit handler
 
  23 # Read in initial state
 
  29     # Work out the name of the next file
 
  30     file="changes-${sequenceNumber}.osm.gz"
 
  32     # Save state file so we can rollback if an error occurs
 
  33     cp state.txt state-prev.txt
 
  35     # Fetch the next set of changes
 
  36     osmosis --read-replication-interval --simc --write-xml-change file="${file}" compressionMethod="gzip"
 
  41         # Enable exit on error
 
  44         # Remember the previous sequence number
 
  45         prevSequenceNumber=$sequenceNumber
 
  50         # Did we get any new data?
 
  51         if [ "${sequenceNumber}" == "${prevSequenceNumber}" ]
 
  53             # Log the lack of data
 
  54             echo "No new data available. Sleeping..."
 
  56             # Remove file, it will just be an empty changeset
 
  59             # No need to rollback now
 
  62             # Sleep for a short while
 
  66             echo "Fetched new data from ${prevSequenceNumber} to ${sequenceNumber} into ${file}"
 
  68             # Apply the changes to the database
 
  69 <% if node[:tile][:node_file] -%>
 
  70             osm2pgsql --slim --append --flat-nodes=<%= node[:tile][:node_file] %> ${file}
 
  72             osm2pgsql --slim --append ${file}
 
  75             # No need to rollback now
 
  78             # Expire tiles which are touched by the changes
 
  79             sudo -u www-data /usr/local/bin/expire-tiles ${file} > /dev/null 2>&1 &
 
  82         # Delete old downloads
 
  83         find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \;
 
  85         # Disable exit on error
 
  88         # Log our failure to fetch changes
 
  89         echo "Failed to fetch changes - waiting a few minutes before retry"
 
  91         # Wait five minutes and have another go