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 sequence-prev.txt ] && mv sequence-prev.txt sequence.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
27 # Work out the name of the next file
28 file="changes-$(cat sequence.txt).osc.gz"
30 # Save sequence file so we can rollback if an error occurs
31 cp sequence.txt sequence-prev.txt
33 # Fetch the next set of changes
34 pyosmium-get-changes --server=<%= node[:tile][:replication][:url] %> --sequence-file=sequence.txt --outfile=${file}
42 # Enable exit on error
46 echo "Fetched new data from $(cat sequence-prev.txt) to $(cat sequence.txt) into ${file}"
48 # Apply the changes to the database
49 osm2pgsql --database gis --slim --append --number-processes=1 \
50 <% if node[:tile][:database][:node_file] -%>
51 --flat-nodes=<%= node[:tile][:database][:node_file] %> \
53 <% if node[:tile][:database][:multi_geometry] -%>
56 <% if node[:tile][:database][:hstore] -%>
59 <% if node[:tile][:database][:style_file] -%>
60 --style=<%= node[:tile][:database][:style_file] %> \
62 <% if node[:tile][:database][:tag_transform_script] -%>
63 --tag-transform-script=<%= node[:tile][:database][:tag_transform_script] %> \
67 # No need to rollback now
71 buffers=$(osmium fileinfo --extended --get=data.buffers.count ${file})
73 # If this diff has content mark it as the latest diff
76 ln -f ${file} changes-latest.osc.gz
79 # Queue these changes for expiry processing
80 ln ${file} expire-queue/${file}
82 # Delete old downloads
83 find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \;
85 # Disable exit on error
87 elif [ $status -eq 3 ]
89 # Log the lack of data
90 echo "No new data available. Sleeping..."
92 # Remove file, it will just be an empty changeset
95 # Sleep for a short while
98 # Log our failure to fetch changes
99 echo "Failed to fetch changes - waiting a few minutes before retry"
101 # Remove any output that was produced
104 # Wait five minutes and have another go