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}.osm.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 <% if node[:tile][:node_file] -%>
 
  71             osm2pgsql --slim --append --number-processes=1 --flat-nodes=<%= node[:tile][:node_file] %> ${file}
 
  73             osm2pgsql --slim --append --number-processes=1 ${file}
 
  76             # No need to rollback now
 
  79             # Expire tiles which are touched by the changes
 
  80             sudo -u www-data /usr/local/bin/expire-tiles ${file} > /dev/null 2>&1 &
 
  83         # Delete old downloads
 
  84         find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \;
 
  86         # Disable exit on error
 
  89         # Log our failure to fetch changes
 
  90         echo "Failed to fetch changes - waiting a few minutes before retry"
 
  92         # Wait five minutes and have another go