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
20 <% if @postgresql_version >= 12 -%>
22 # Disable JIT and parallel workers in postgres
23 export PGOPTIONS="-c jit=off -c max_parallel_workers_per_gather=0"
26 # Install exit handler
32 # Work out the name of the next file
33 file="changes-$(cat sequence.txt).osc.gz"
35 # Save sequence file so we can rollback if an error occurs
36 cp sequence.txt sequence-prev.txt
38 # Fetch the next set of changes
39 pyosmium-get-changes --sequence-file=sequence.txt --outfile=${file}
47 # Enable exit on error
51 echo "Fetched new data from $(cat sequence-prev.txt) to $(cat sequence.txt) into ${file}"
53 # Apply the changes to the database
54 osm2pgsql --database gis --slim --append --number-processes=1 \
55 <% if node[:tile][:database][:node_file] -%>
56 --flat-nodes=<%= node[:tile][:database][:node_file] %> \
58 <% if node[:tile][:database][:multi_geometry] -%>
61 <% if node[:tile][:database][:hstore] -%>
64 <% if node[:tile][:database][:style_file] -%>
65 --style=<%= node[:tile][:database][:style_file] %> \
67 <% if node[:tile][:database][:tag_transform_script] -%>
68 --tag-transform-script=<%= node[:tile][:database][:tag_transform_script] %> \
72 # No need to rollback now
76 buffers=$(osmium fileinfo --extended --get=data.buffers.count ${file})
78 # If this diff has content mark it as the latest diff
81 ln -f ${file} changes-latest.osc.gz
84 # Queue these changes for expiry processing
85 ln ${file} expire-queue/${file}
87 # Delete old downloads
88 find . -name 'changes-*.gz' -mmin +300 -exec rm -f {} \;
90 # Disable exit on error
92 elif [ $status -eq 3 ]
94 # Log the lack of data
95 echo "No new data available. Sleeping..."
97 # Remove file, it will just be an empty changeset
100 # Sleep for a short while
103 # Log our failure to fetch changes
104 echo "Failed to fetch changes - waiting a few minutes before retry"
106 # Remove any output that was produced
109 # Wait five minutes and have another go