Switch to using planet-dump-ng instead of planetdump
authorTom Hughes <tom@compton.nu>
Tue, 16 Dec 2014 00:41:51 +0000 (00:41 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 16 Dec 2014 21:39:30 +0000 (21:39 +0000)
cookbooks/planet/metadata.rb
cookbooks/planet/recipes/dump.rb
cookbooks/planet/templates/default/planetdump.cron.erb [deleted file]
cookbooks/planet/templates/default/planetdump.erb

index 7d868d0..3e2f5f3 100644 (file)
@@ -8,3 +8,4 @@ version           "1.0.0"
 depends           "apache"
 depends           "git"
 depends           "osmosis"
+depends           "incron"
index 197ed10..02f3ae3 100644 (file)
 # limitations under the License.
 #
 
-include_recipe "git"
+node.default[:incron][:planetdump] = {
+  :user => "www-data",
+  :path => "/store/backup",
+  :events => [ "IN_CREATE", "IN_MOVED_TO" ],
+  :command => "/usr/local/bin/planetdump $#"
+}
 
-db_passwords = data_bag_item("db", "passwords")
+include_recipe "git"
+include_recipe "incron"
 
 package "gcc"
 package "make"
-package "libpqxx3-dev"
+package "autoconf"
+package "automake"
+package "libxml2-dev"
+package "libboost-dev"
+package "libboost-program-options-dev"
+package "libboost-date-time-dev"
+package "libboost-filesystem-dev"
+package "libboost-thread-dev"
+package "libboost-iostreams-dev"
+package "libosmpbf-dev"
+package "libleveldb-dev"
+package "libsnappy-dev"
+package "libprotobuf-dev"
+package "osmpbf-bin"
 
-directory "/opt/planetdump" do
+directory "/opt/planet-dump-ng" do
   owner "root"
   group "root"
   mode 0755
 end
 
-git "/opt/planetdump" do
+git "/opt/planet-dump-ng" do
   action :sync
-  repository "git://git.openstreetmap.org/planetdump.git"
-  revision "live"
+  repository "git://github.com/zerebubuth/planet-dump-ng.git"
+  revision "master"
   user "root"
   group "root"
 end
 
-execute "/opt/planetdump/Makefile" do
+execute "/opt/planet-dump-ng/autogen.sh" do
   action :nothing
-  command "make planet06_pg"
-  cwd "/opt/planetdump"
+  command "./autogen.sh"
+  cwd "/opt/planet-dump-ng"
   user "root"
   group "root"
-  subscribes :run, "git[/opt/planetdump]"
+  subscribes :run, "git[/opt/planet-dump-ng]"
 end
 
-template "/usr/local/bin/planetdump" do
-  source "planetdump.erb"
-  owner "root"
+execute "/opt/planet-dump-ng/configure" do
+  action :nothing
+  command "./configure --with-leveldb=/usr"
+  cwd "/opt/planet-dump-ng"
+  user "root"
   group "root"
+  subscribes :run, "execute[/opt/planet-dump-ng/autogen.sh]"
+end
+
+execute "/opt/planet-dump-ng/Makefile" do
+  action :nothing
+  command "make"
+  cwd "/opt/planet-dump-ng"
+  user "root"
+  group "root"
+  subscribes :run, "execute[/opt/planet-dump-ng/configure]"
+end
+
+directory "/store/planetdump" do
+  owner "www-data"
+  group "www-data"
   mode 0755
-  variables :password => db_passwords["planetdump"]
 end
 
-template "/etc/cron.d/planetdump" do
-  source "planetdump.cron.erb"
+template "/usr/local/bin/planetdump" do
+  source "planetdump.erb"
   owner "root"
   group "root"
-  mode 0644
+  mode 0755
 end
diff --git a/cookbooks/planet/templates/default/planetdump.cron.erb b/cookbooks/planet/templates/default/planetdump.cron.erb
deleted file mode 100644 (file)
index b7403d2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-MAILTO=grant-smaug@firefishy.com
-10 0 * * 3 www-data /usr/local/bin/planetdump
index 9df4a6f..068ce5d 100644 (file)
@@ -1,71 +1,61 @@
 #!/bin/bash
-ulimit -m 4194304 -v 4194304
-set -e
 
-if [ -f /tmp/planetdump.lock ]; then
-       if [ "$(ps -p `cat /tmp/planetdump.lock` | wc -l)" -gt 1 ]; then
-               # process is still running
-               echo Error: Another planetdump is running
-               exit 1
-       else
-               # process not running, but lock file not deleted?
-               rm /tmp/planetdump.lock
-       fi
-fi
-
-#Create Lock
-echo $$ > /tmp/planetdump.lock
-
-
-cur_date=`date +%y%m%d`
-cur_year=`date +%Y`
-cur_planet=planet-${cur_date}.osm
-cur_changeset=changesets-${cur_date}.osm
-planet_dir=/store/planet/
-
-export CONNECTION_PARAMS='dbname=openstreetmap host=db user=planetdump password=<%= @password %>'
-export PATH='/usr/local/bin:/usr/bin:/bin:/usr/bin/X11'
+# Exit on error
+set -e
 
+# Get the name of the file and the expected pattern
+file="$1"
+pattern="^osm-([0-9]{4}-[0-9]{2}-[0-9]{2})\.dmp$"
 
-if [ \! -d ${planet_dir}/planet/ ]
-       then
-               echo ${planet_dir}planet/ does not exist
-               exit 1
-       fi
-if [ \! -d ${planet_dir}/planet/${cur_year}/ ]; then mkdir ${planet_dir}/planet/${cur_year}/; fi
-cd ${planet_dir}/planet/${cur_year}/
+# Give up now if the file isn't a database dump
+[[ $file =~ $pattern ]] || exit 0
 
-/opt/planetdump/planet06_pg | pbzip2 -p6 -6c > .${cur_planet}.bz2.new
-/opt/planetdump/planet06_pg --changesets | pbzip2 -p6 -9c > .${cur_changeset}.bz2.new
+# Save the date from the file name
+date="${BASH_REMATCH[1]}"
 
-planet_size=$(du -sb .${cur_planet}.bz2.new | awk '{ print $1 }')
-changeset_size=$(du -sb .${cur_changeset}.bz2.new | awk '{ print $1 }')
-if ((planet_size<32000000000)); then
-       echo Planet .${cur_planet}.bz2.new too small
-       exit 1
-fi
-if ((changeset_size<720000000)); then
-       echo Changeset .${cur_changeset}.bz2.new too small
+# Check the lock
+if [ -f /tmp/planetdump.lock ]; then
+    if [ "$(ps -p `cat /tmp/planetdump.lock` | wc -l)" -gt 1 ]; then
+       echo "Error: Another planetdump is running"
        exit 1
+    else
+       rm /tmp/planetdump.lock
+    fi
 fi
 
-mv .${cur_planet}.bz2.new ${cur_planet}.bz2
-mv .${cur_changeset}.bz2.new ${cur_changeset}.bz2
-md5sum ${cur_planet}.bz2 > ${cur_planet}.bz2.md5
-md5sum ${cur_changeset}.bz2 > ${cur_changeset}.bz2.md5
-
-#link planet latest to the new file
-cd ${planet_dir}/planet/
-
-ln -fs ${cur_year}/${cur_planet}.bz2 planet-latest.osm.bz2
-ln -fs ${cur_year}/${cur_changeset}.bz2 changesets-latest.osm.bz2
-
-# mangle md5 files for 'latest' ones
-rm -f planet-latest.osm.bz2.md5
-rm -f changesets-latest.osm.bz2.md5
-
-sed -e "s/${cur_planet}.bz2/planet-latest.osm.bz2/" ${cur_year}/${cur_planet}.bz2.md5 > planet-latest.osm.bz2.md5
-sed -e "s/${cur_changeset}.bz2/changesets-latest.osm.bz2/" ${cur_year}/${cur_changeset}.bz2.md5 > changesets-latest.osm.bz2.md5
+# Create Lock
+echo $$ > /tmp/planetdump.lock
 
+# Change to working directory
+cd /store/planetdump
+
+# Cleanup
+rm -rf users
+rm -rf changesets changeset_tags
+rm -rf nodes node_tags
+rm -rf ways way_tags way_nodes
+rm -rf relations relation_tags relation_members
+
+# Run the dump
+time nice -n 19 /store/planet-dump-ng/planet-dump-ng \
+     -c "pbzip2 -c" -f "${file}" --dense-nodes=1 \
+     -C "changesets-${date}.osm.bz2" \
+     -x "planet-${date}.osm.bz2" -X "history-${date}.osm.bz2" \
+     -p "planet-${date}.osm.pbf" -P "history-${date}.osm.pbf"
+
+# Move XML dumps into place
+for file in "changesets-${date}.osm.bz2" "planet-${date}.osm.bz2" "history-${date}.osm.bz2"
+do
+    md5sum "#{file}" > "#{file}.md5"
+    mv "${file}" "${file}.md5" "/store/planet/planet"
+done
+
+# Move PBF dumps into place
+for file in "planet-${date}.osm.pbf" "history-${date}.osm.pbf"
+do
+    md5sum "#{file}" > "#{file}.md5"
+    mv "${file}" "${file}.md5" "/store/planet/pbf"
+done
+
+# Release lock
 rm /tmp/planetdump.lock
-