]> git.openstreetmap.org Git - chef.git/blob - cookbooks/planet/templates/default/planetdump.erb
Use trap to release lock
[chef.git] / cookbooks / planet / templates / default / planetdump.erb
1 #!/bin/bash
2
3 # Exit on error
4 set -e
5
6 # Get the name of the file and the expected pattern
7 file="$1"
8 pattern="^osm-([0-9]{4}-[0-9]{2}-[0-9]{2})\.dmp$"
9
10 # Give up now if the file isn't a database dump
11 [[ $file =~ $pattern ]] || exit 0
12
13 # Save the date from the file name
14 date="${BASH_REMATCH[1]}"
15
16 # Check the lock
17 if [ -f /tmp/planetdump.lock ]; then
18     if [ "$(ps -p `cat /tmp/planetdump.lock` | wc -l)" -gt 1 ]; then
19         echo "Error: Another planetdump is running"
20         exit 1
21     else
22         rm /tmp/planetdump.lock
23     fi
24 fi
25
26 # Create Lock
27 echo $$ > /tmp/planetdump.lock
28
29 function cleanup {
30          # Release lock
31          rm /tmp/planetdump.lock
32 }
33
34 # Remove lock on exit
35 trap cleanup EXIT
36
37 # Change to working directory
38 cd /store/planetdump
39
40 # Cleanup
41 rm -rf users
42 rm -rf changesets changeset_tags
43 rm -rf nodes node_tags
44 rm -rf ways way_tags way_nodes
45 rm -rf relations relation_tags relation_members
46
47 # Run the dump
48 time nice -n 19 /store/planet-dump-ng/planet-dump-ng \
49      -c "pbzip2 -c" -f "${file}" --dense-nodes=1 \
50      -C "changesets-${date}.osm.bz2" \
51      -x "planet-${date}.osm.bz2" -X "history-${date}.osm.bz2" \
52      -p "planet-${date}.osm.pbf" -P "history-${date}.osm.pbf"
53
54 # Move XML dumps into place
55 for file in "changesets-${date}.osm.bz2" "planet-${date}.osm.bz2" "history-${date}.osm.bz2"
56 do
57     md5sum "#{file}" > "#{file}.md5"
58     mv "${file}" "${file}.md5" "/store/planet/planet"
59 done
60
61 # Move PBF dumps into place
62 for file in "planet-${date}.osm.pbf" "history-${date}.osm.pbf"
63 do
64     md5sum "#{file}" > "#{file}.md5"
65     mv "${file}" "${file}.md5" "/store/planet/pbf"
66 done