9df4a6f0372c8222dd1a9dda870e0c38e1a41350
[chef.git] / cookbooks / planet / templates / default / planetdump.erb
1 #!/bin/bash
2 ulimit -m 4194304 -v 4194304
3 set -e
4
5 if [ -f /tmp/planetdump.lock ]; then
6         if [ "$(ps -p `cat /tmp/planetdump.lock` | wc -l)" -gt 1 ]; then
7                 # process is still running
8                 echo Error: Another planetdump is running
9                 exit 1
10         else
11                 # process not running, but lock file not deleted?
12                 rm /tmp/planetdump.lock
13         fi
14 fi
15
16 #Create Lock
17 echo $$ > /tmp/planetdump.lock
18
19
20 cur_date=`date +%y%m%d`
21 cur_year=`date +%Y`
22 cur_planet=planet-${cur_date}.osm
23 cur_changeset=changesets-${cur_date}.osm
24 planet_dir=/store/planet/
25
26 export CONNECTION_PARAMS='dbname=openstreetmap host=db user=planetdump password=<%= @password %>'
27 export PATH='/usr/local/bin:/usr/bin:/bin:/usr/bin/X11'
28
29
30 if [ \! -d ${planet_dir}/planet/ ]
31         then
32                 echo ${planet_dir}planet/ does not exist
33                 exit 1
34         fi
35 if [ \! -d ${planet_dir}/planet/${cur_year}/ ]; then mkdir ${planet_dir}/planet/${cur_year}/; fi
36 cd ${planet_dir}/planet/${cur_year}/
37
38 /opt/planetdump/planet06_pg | pbzip2 -p6 -6c > .${cur_planet}.bz2.new
39 /opt/planetdump/planet06_pg --changesets | pbzip2 -p6 -9c > .${cur_changeset}.bz2.new
40
41 planet_size=$(du -sb .${cur_planet}.bz2.new | awk '{ print $1 }')
42 changeset_size=$(du -sb .${cur_changeset}.bz2.new | awk '{ print $1 }')
43 if ((planet_size<32000000000)); then
44         echo Planet .${cur_planet}.bz2.new too small
45         exit 1
46 fi
47 if ((changeset_size<720000000)); then
48         echo Changeset .${cur_changeset}.bz2.new too small
49         exit 1
50 fi
51
52 mv .${cur_planet}.bz2.new ${cur_planet}.bz2
53 mv .${cur_changeset}.bz2.new ${cur_changeset}.bz2
54 md5sum ${cur_planet}.bz2 > ${cur_planet}.bz2.md5
55 md5sum ${cur_changeset}.bz2 > ${cur_changeset}.bz2.md5
56
57 #link planet latest to the new file
58 cd ${planet_dir}/planet/
59
60 ln -fs ${cur_year}/${cur_planet}.bz2 planet-latest.osm.bz2
61 ln -fs ${cur_year}/${cur_changeset}.bz2 changesets-latest.osm.bz2
62
63 # mangle md5 files for 'latest' ones
64 rm -f planet-latest.osm.bz2.md5
65 rm -f changesets-latest.osm.bz2.md5
66
67 sed -e "s/${cur_planet}.bz2/planet-latest.osm.bz2/" ${cur_year}/${cur_planet}.bz2.md5 > planet-latest.osm.bz2.md5
68 sed -e "s/${cur_changeset}.bz2/changesets-latest.osm.bz2/" ${cur_year}/${cur_changeset}.bz2.md5 > changesets-latest.osm.bz2.md5
69
70 rm /tmp/planetdump.lock
71