]> git.openstreetmap.org Git - chef.git/blobdiff - 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
diff --git a/cookbooks/overpass/templates/default/overpass-update-db.erb b/cookbooks/overpass/templates/default/overpass-update-db.erb
new file mode 100644 (file)
index 0000000..5ac8d15
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+PYOSMIUM="pyosmium-get-changes --server <%= node[:overpass][:replication_url] %> -f <%= @basedir %>/db/replicate-id"
+<% if node[:overpass][:meta_mode] == "attic" -%>
+PYOSMIUM="$PYOSMIUM --no-deduplicate"
+<% end -%>
+
+<% if node[:overpass][:meta_mode] == "meta" -%>
+META=--meta
+<% elsif node[:overpass][:meta_mode] == "attic" -%>
+META=--keep-attic
+<% else -%>
+META=
+<% end -%>
+
+while true; do
+  status=3 # make it sleep on issues
+
+  if [ -f <%= @basedir %>/db/replicate-id ]; then
+    # first apply any pending updates
+    if [ -f <%= @basedir %>/diffs/latest.osc ]; then
+      DATA_VERSION=`osmium fileinfo -e -g data.timestamp.last <%= @basedir %>/diffs/latest.osc`
+      if [ "x$DATA_VERSION" != "x" ]; then
+        echo "Downloaded up to timestamp $DATA_VERSION"
+        while ! <%= @basedir %>/bin/update_from_dir --osc-dir=<%= @basedir %>/diffs --version=$DATA_VERSION $META --flush-size=0; do
+          echo "Error while updating. Retry in 1 min."
+          sleep 60
+        done
+      fi
+      rm <%= @basedir %>/diffs/latest.osc
+    fi
+
+    $PYOSMIUM -v -s 1000 -o <%= @basedir %>/diffs/latest.osc
+    status=$?
+  fi
+
+  if [ $status -eq 0 ]; then
+    echo "Downloaded next batch."
+  elif [ $status -eq 3 ]; then
+    rm <%= @basedir %>/diffs/latest.osc
+    echo "No new data, sleeping for a minute."
+    sleep 60
+  else
+    echo "Fatal error, stopping updates."
+    exit $status
+  fi
+done