X-Git-Url: https://git.openstreetmap.org/chef.git/blobdiff_plain/8e9e103e9f748fe7a104c4fba00cc72a847e2d3a..a2131407eb794673e66a2289ebda25007b4f561a:/cookbooks/tile/templates/default/replicate.erb diff --git a/cookbooks/tile/templates/default/replicate.erb b/cookbooks/tile/templates/default/replicate.erb index 862b6a5e7..e1ecab695 100644 --- a/cookbooks/tile/templates/default/replicate.erb +++ b/cookbooks/tile/templates/default/replicate.erb @@ -6,12 +6,20 @@ # Setting to midnight ensures we get conistent data after first run # osmosis --read-replication-interval-init +# Define exit handler +function onexit { + [ -f state-prev.txt ] && mv state-prev.txt state.txt +} + # Send output to the log -exec > /var/log/replicate/replicate.log 2>&1 +exec > /var/log/tile/replicate.log 2>&1 # Change to the replication state directory cd /var/lib/replicate +# Install exit handler +trap onexit EXIT + # Read in initial state . state.txt @@ -21,6 +29,9 @@ do # Work out the name of the next file file="changes-${sequenceNumber}.osm.gz" + # Save state file so we can rollback if an error occurs + cp state.txt state-prev.txt + # Fetch the next set of changes osmosis --read-replication-interval --simc --write-xml-change file="${file}" compressionMethod="gzip" @@ -45,6 +56,9 @@ do # Remove file, it will just be an empty changeset rm ${file} + # No need to rollback now + rm state-prev.txt + # Sleep for a short while sleep 30 else @@ -58,8 +72,11 @@ do osm2pgsql --slim --append ${file} <% end -%> + # No need to rollback now + rm state-prev.txt + # Expire tiles which are touched by the changes - /usr/local/bin/expire-tiles ${file} > /dev/null 2>&1 & + sudo -u www-data /usr/local/bin/expire-tiles ${file} > /dev/null 2>&1 & fi # Delete old downloads