some changes for v4 of openstreetmap-carto (add LUA transform script)
[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 \
16 #           --expire-tiles=17-17 --expire-output=$EXPIRYFILE \
17 #           $CHANGESFILE"
18 UPDATECMD="/usr/bin/osm2pgsql --slim --cache=8000 --append --database=osm \
19            --style=/home.local/osm/dbstyle/openstreetmap-carto.style \
20            --tag-transform-script /home.local/osm/dbstyle/openstreetmap-carto.lua \
21            --flat-nodes=/mnt/database/flatnodes/flatnodes.db \
22            --hstore --multi-geometry --number-processes 4 \
23            --expire-tiles=17-17 --expire-output=$EXPIRYFILE \
24            $CHANGESFILE"
25
26 cleanup()
27 {
28         rm -f "$LOCKFILE"
29         exit 1
30 }
31
32 trytofeedupdate()
33 {
34         echo "Trying to feed updates into databse..."
35         echo "Executing: $UPDATECMD"
36         $UPDATECMD
37         if [ $? == 0 ] ; then
38                 echo "Update went fine, removing changes-file"
39                 rm -f $CHANGESFILE
40         else
41                 echo "Update failed with error $?"
42         fi
43 }
44
45 echo "Starting update script: `date`"
46 if [ -e "$LOCKFILE" ] ; then
47         echo "Lockfile exists - ABORTING"
48         exit 1
49 fi
50 touch "$LOCKFILE" || exit 9
51 trap cleanup 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \
52              20 21 22 23 24 25 26 27 28 29 30 31
53 if [ -e $CHANGESFILE ] ; then
54         echo "Changesfile exists - will try to feed update to Database"
55         trytofeedupdate
56 fi
57 if [ -e $CHANGESFILE ] ; then
58         echo "Changesfile STILL exists - ABORTING"
59         cleanup
60         exit 1
61 fi
62 echo "Downloading changes with OSMOSIS..."
63 echo "Executing: /usr/bin/osmosis --read-replication-interval workingDirectory=$OSMOSISWORKDIR --simplify-change  --write-xml-change $CHANGESFILE"
64 /usr/bin/osmosis --read-replication-interval workingDirectory=$OSMOSISWORKDIR --simplify-change  --write-xml-change $CHANGESFILE
65 if [ $? != 0 ] ; then
66         echo "Osmosis execution failed. ABORTING"
67         cleanup
68         exit 1
69 fi
70 trytofeedupdate
71 if [ -e $CHANGESFILE ] ; then
72         echo "Changesfile STILL exists - update must have failed. ABORTING"
73         cleanup
74         exit 1
75 fi
76 echo "Update seems to have been successful."
77 grep timestamp $OSMOSISWORKDIR/state.txt | sed -e 's/timestamp=//g' -e 's/T/ /g' -e 's/\\:/:/g' > $WEBSTATEFILE
78 echo -n "Updated database: now at upstream state of "
79 cat $WEBSTATEFILE
80 #touch /var/lib/tirex/tiles/planet-import-complete
81 if [ -e $EXPIRYFILE ] ; then
82         if [ -e $RERENDEREXPIREDTRIGGERFILE ] ; then
83                 echo "Expiryfile and triggerfile  exists. Marking the tiles mentioned there as expired..."
84                 echo "Number of lines: `wc -l $EXPIRYFILE`"
85                 # Used to be zoom 13-20 but that causes too much load. Reduced to 15-20.
86                 cat $EXPIRYFILE | sudo -u tirex /home.local/osm/bin/osmtilecleanup.pl \
87                                    --action touchexpiredlist --zoom 15-20 \
88                                    /var/lib/tirex/tiles/osm
89                 cat $EXPIRYFILE | sudo -u tirex /home.local/osm/bin/osmtilecleanup.pl \
90                                    --action touchexpiredlist --zoom 15-20 \
91                                    /var/lib/tirex/tiles/osmde
92                 cat $EXPIRYFILE | sudo -u tirex /home.local/osm/bin/osmtilecleanup.pl \
93                                    --action touchexpiredlist --zoom 15-20 \
94                                    /var/lib/tirex/tiles/osmhd
95                 cat $EXPIRYFILE | sudo -u tirex /home.local/osm/bin/osmtilecleanup.pl \
96                                    --action touchexpiredlist --zoom 15-20 \
97                                    /var/lib/tirex/tiles/osmdehd
98                 # Now immediately rerender all the tiles there that are in our area.
99                 # The rest gets done on demand by mod_tile.
100                 echo "Triggering rerendering of expired tiles in our area..."
101                 tirex-batch --prio=31 --expire=+3600 --filter='exists;older(1450000000)' map=osm   bbox=10.93,49.37,11.14,49.63 z=15-20
102                 tirex-batch --prio=31 --expire=+3600 --filter='exists;older(1450000000)' map=osmde bbox=10.93,49.37,11.14,49.63 z=15-20
103                 tirex-batch --prio=31 --expire=+3600 --filter='exists;older(1450000000)' map=osmhd bbox=10.93,49.37,11.14,49.63 z=15-20
104                 tirex-batch --prio=31 --expire=+3600 --filter='exists;older(1450000000)' map=osmdehd bbox=10.93,49.37,11.14,49.63 z=15-20
105         else
106                 echo "Expiryfile exists but rerendering is disabled."
107         fi
108         rm $EXPIRYFILE
109 fi
110 echo "Ending update script cleanly: `date`"
111 cleanup
112 exit 0
113
This page took 0.049206 seconds and 3 git commands to generate.