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
9 # Send output to the log
10 exec > /var/log/tile/replicate.log 2>&1
12 # Change to the replication state directory
15 # Read in initial state
21 # Work out the name of the next file
22 file="changes-${sequenceNumber}.osm.gz"
24 # Fetch the next set of changes
25 osmosis --read-replication-interval --simc --write-xml-change file="${file}" compressionMethod="gzip"
30 # Enable exit on error
33 # Remember the previous sequence number
34 prevSequenceNumber=$sequenceNumber
39 # Did we get any new data?
40 if [ "${sequenceNumber}" == "${prevSequenceNumber}" ]
42 # Log the lack of data
43 echo "No new data available. Sleeping..."
45 # Remove file, it will just be an empty changeset
48 # Sleep for a short while
52 echo "Fetched new data from ${prevSequenceNumber} to ${sequenceNumber} into ${file}"
54 # Apply the changes to the database
55 <% if node[:tile][:node_file] -%>
56 osm2pgsql --slim --append --flat-nodes=<%= node[:tile][:node_file] %> ${file}
58 osm2pgsql --slim --append ${file}
61 # Expire tiles which are touched by the changes
62 sudo -u www-data /usr/local/bin/expire-tiles ${file} > /dev/null 2>&1 &
65 # Delete old downloads
66 find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \;
68 # Disable exit on error
71 # Log our failure to fetch changes
72 echo "Failed to fetch changes - waiting a few minutes before retry"
74 # Wait five minutes and have another go