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