make it possible to enable or disable rerenderings by a file.
[osmrrze.git] / scripts / doosmupdate.sh
1 #!/bin/bash
2
3 LOCKFILE=/home.local/osm/run/.osmupdate.lock
4 CHANGESFILE=/home.local/osm/run/osmosis-changes.osc.gz
5 EXPIRYFILE=/home.local/osm/run/expiredtiles.lst
6 RERENDEREXPIREDTRIGGERFILE=/home.local/osm/run/rerenderexpiredtiles.setting
7 OSMOSISWORKDIR=/home.local/osm/.osmosis
8 WEBSTATEFILE=/var/www/lastdbupdate.txt
9 # Note: set the expire-tiles to 3 less than the real maximum,
10 # as this makes the tilelist MUCH shorter, and the tiles get rerendered
11 # anyways due to the metatile-layout!
12 UPDATECMD="/usr/bin/osm2pgsql --slim --cache=8000 --append --database=osm \
13            --style=/home.local/osm/dbstyle/osm2pgsql-new.style \
14            --flat-nodes=/mnt/database/flatnodes/flatnodes.db \
15            --hstore --multi-geometry --expire-tiles=17-17 \
16            --expire-output=$EXPIRYFILE  $CHANGESFILE"
17
18 cleanup()
19 {
20         rm -f "$LOCKFILE"
21         exit 1
22 }
23
24 trytofeedupdate()
25 {
26         echo "Trying to feed updates into databse..."
27         echo "Executing: $UPDATECMD"
28         $UPDATECMD
29         if [ $? == 0 ] ; then
30                 echo "Update went fine, removing changes-file"
31                 rm -f $CHANGESFILE
32         else
33                 echo "Update failed with error $?"
34         fi
35 }
36
37 echo "Starting update script: `date`"
38 if [ -e "$LOCKFILE" ] ; then
39         echo "Lockfile exists - ABORTING"
40         exit 1
41 fi
42 touch "$LOCKFILE" || exit 9
43 trap cleanup 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \
44              20 21 22 23 24 25 26 27 28 29 30 31
45 if [ -e $CHANGESFILE ] ; then
46         echo "Changesfile exists - will try to feed update to Database"
47         trytofeedupdate
48 fi
49 if [ -e $CHANGESFILE ] ; then
50         echo "Changesfile STILL exists - ABORTING"
51         cleanup
52         exit 1
53 fi
54 echo "Downloading changes with OSMOSIS..."
55 echo "Executing: /usr/bin/osmosis --read-replication-interval workingDirectory=$OSMOSISWORKDIR --simplify-change  --write-xml-change $CHANGESFILE"
56 /usr/bin/osmosis --read-replication-interval workingDirectory=$OSMOSISWORKDIR --simplify-change  --write-xml-change $CHANGESFILE
57 if [ $? != 0 ] ; then
58         echo "Osmosis execution failed. ABORTING"
59         cleanup
60         exit 1
61 fi
62 trytofeedupdate
63 if [ -e $CHANGESFILE ] ; then
64         echo "Changesfile STILL exists - update must have failed. ABORTING"
65         cleanup
66         exit 1
67 fi
68 echo "Update seems to have been successful."
69 grep timestamp $OSMOSISWORKDIR/state.txt | sed -e 's/timestamp=//g' -e 's/T/ /g' -e 's/\\:/:/g' > $WEBSTATEFILE
70 echo -n "Updated database: now at upstream state of "
71 cat $WEBSTATEFILE
72 #touch /var/lib/tirex/tiles/planet-import-complete
73 if [ -e $EXPIRYFILE -a -e $RERENDEREXPIREDTRIGGERFILE ] ; then
74         echo "Expiryfile exists. Telling tirex to rerender the tiles mentioned there..."
75         echo "Number of lines: `wc -l $EXPIRYFILE`"
76         # Used to be zoom 13-20 but that causes too much load. Reduced to 15-20.
77         # Trying completely without. Lots of load, way too many false positives. -unrz191 2015-09-04
78         cat $EXPIRYFILE | /home.local/osm/bin/osmtilecleanup.pl \
79                                    --action rerenderexpiredlist --zoom 15-20 \
80                                    --rrs /home.local/osm/bin/osmrerenderwrapper.sh \
81                                    /var/lib/tirex/tiles/osm
82         cat $EXPIRYFILE | /home.local/osm/bin/osmtilecleanup.pl \
83                                    --action rerenderexpiredlist --zoom 15-20 \
84                                    --rrs /home.local/osm/bin/osmrerenderwrapper-osmde.sh \
85                                    /var/lib/tirex/tiles/osmde
86         rm $EXPIRYFILE
87 fi
88 echo "Ending update script cleanly: `date`"
89 cleanup
90 exit 0
91
This page took 0.042581 seconds and 3 git commands to generate.