Initial work on maintaining an up to date planet for taginfo
authorTom Hughes <tom@compton.nu>
Sat, 15 Feb 2014 15:30:33 +0000 (15:30 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 15 Feb 2014 15:30:33 +0000 (15:30 +0000)
cookbooks/taginfo/recipes/default.rb
cookbooks/taginfo/templates/default/configuration.txt.erb [new file with mode: 0644]
cookbooks/taginfo/templates/default/update-planet.erb [new file with mode: 0644]

index 227da7d..ac94c71 100644 (file)
@@ -101,6 +101,47 @@ node[:taginfo][:sites].each do |site|
     notifies :restart, "service[apache2]"
   end
 
+  directory "#{directory}/planet" do
+    owner "taginfo"
+    group "taginfo"
+    mode 0755
+  end
+
+  remote_file "#{directory}/planet/planet.pbf" do
+    action :create_if_missing
+    source "http://planet.openstreetmap.org/pbf/planet-latest.osm.pbf"
+    owner "taginfo"
+    group "taginfo"
+    mode 0644
+  end
+
+  template "#{directory}/planet/configuration.txt" do
+    source "configuration.txt.erb"
+    owner "taginfo"
+    group "taginfo"
+    mode 0644
+  end
+
+  file "#{directory}/planet/download.lock" do
+    owner "taginfo"
+    group "taginfo"
+    mode 0644
+  end
+
+  directory "#{directory}/bin" do
+    owner "taginfo"
+    group "taginfo"
+    mode 0755
+  end
+
+  template "#{directory}/bin/update-planet" do
+    source "update-planet.erb"
+    owner "taginfo"
+    group "taginfo"
+    mode 0755
+    variables :directory => directory
+  end
+
   directory "#{directory}/data" do
     owner "taginfo"
     group "taginfo"
diff --git a/cookbooks/taginfo/templates/default/configuration.txt.erb b/cookbooks/taginfo/templates/default/configuration.txt.erb
new file mode 100644 (file)
index 0000000..6f5bf93
--- /dev/null
@@ -0,0 +1,2 @@
+baseUrl=http://planet.openstreetmap.org/replication/hour
+maxInterval=0
diff --git a/cookbooks/taginfo/templates/default/update-planet.erb b/cookbooks/taginfo/templates/default/update-planet.erb
new file mode 100644 (file)
index 0000000..8fd69ff
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -e
+
+cd "<%= @directory %>/planet"
+
+OSCFILE="$(date +%Y%m%d-%H%M).osc"
+
+# if there are old .osc files, they have to be taken into account
+
+OLDFILE=2*-*.osc
+if [ -z "$OLDFILE" ]
+then
+   osmosis --rri --simc --write-xml-change "$OSCFILE"
+else
+   osmosis --rxc "$OLDFILE" --rri --mc --simc --write-xml-change "$OSCFILE" && rm "$OLDFILE"
+fi
+
+# osc file is ready, create new planet file
+
+osmosis --read-xml-change "$OSCFILE" --read-bin planet.pbf --buffer bufferCapacity=12000 --apply-change --buffer bufferCapacity=12000 --write-pbf planet-new.pbf
+
+# cleanup
+
+mv planet-new.pbf planet.pbf
+rm "$OSCFILE"