]> git.openstreetmap.org Git - chef.git/blob - cookbooks/overpass/templates/default/overpass-update-db.erb
Merge remote-tracking branch 'github/pull/455'
[chef.git] / cookbooks / overpass / templates / default / overpass-update-db.erb
1 #!/bin/bash
2
3 PYOSMIUM="pyosmium-get-changes --server <%= node[:overpass][:replication_url] %> -f <%= @basedir %>/db/replicate-id"
4 <% if node[:overpass][:meta_mode] == "attic" -%>
5 PYOSMIUM="$PYOSMIUM --no-deduplicate"
6 <% end -%>
7
8 <% if node[:overpass][:meta_mode] == "meta" -%>
9 META=--meta
10 <% elsif node[:overpass][:meta_mode] == "attic" -%>
11 META=--keep-attic
12 <% else -%>
13 META=
14 <% end -%>
15
16 while true; do
17   status=3 # make it sleep on issues
18
19   if [ -f <%= @basedir %>/db/replicate-id ]; then
20     # first apply any pending updates
21     if [ -f <%= @basedir %>/diffs/latest.osc ]; then
22       DATA_VERSION=`osmium fileinfo -e -g data.timestamp.last <%= @basedir %>/diffs/latest.osc`
23       if [ "x$DATA_VERSION" != "x" ]; then
24         echo "Downloaded up to timestamp $DATA_VERSION"
25         while ! <%= @basedir %>/bin/update_from_dir --osc-dir=<%= @basedir %>/diffs --version=$DATA_VERSION $META --flush-size=0; do
26           echo "Error while updating. Retry in 1 min."
27           sleep 60
28         done
29       fi
30       rm <%= @basedir %>/diffs/latest.osc
31     fi
32
33     $PYOSMIUM -v -s 1000 -o <%= @basedir %>/diffs/latest.osc
34     status=$?
35   fi
36
37   if [ $status -eq 0 ]; then
38     echo "Downloaded next batch."
39   elif [ $status -eq 3 ]; then
40     rm <%= @basedir %>/diffs/latest.osc
41     echo "No new data, sleeping for a minute."
42     sleep 60
43   else
44     echo "Fatal error, stopping updates."
45     exit $status
46   fi
47 done