Commit | Line | Data |
---|---|---|
5203e8e5 UO |
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 | |
002b918b | 6 | RERENDEREXPIREDTRIGGERFILE=/home.local/osm/run/rerenderexpiredtiles.setting |
5203e8e5 UO |
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! | |
407cdf50 UO |
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" | |
5203e8e5 | 18 | UPDATECMD="/usr/bin/osm2pgsql --slim --cache=8000 --append --database=osm \ |
407cdf50 UO |
19 | --style=/home.local/osm/dbstyle/openstreetmap-carto.style \ |
20 | --tag-transform-script /home.local/osm/dbstyle/openstreetmap-carto.lua \ | |
1e28d5c9 | 21 | --flat-nodes=/mnt/database/flatnodes/flatnodes.db \ |
407cdf50 | 22 | --hstore --multi-geometry --number-processes 4 \ |
c5981eb1 UO |
23 | --expire-tiles=17-17 --expire-output=$EXPIRYFILE \ |
24 | $CHANGESFILE" | |
5203e8e5 UO |
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 | |
11f3d002 | 78 | echo -n "Updated database: now at upstream state of " |
79 | cat $WEBSTATEFILE | |
1ef97ffe | 80 | #touch /var/lib/tirex/tiles/planet-import-complete |
c5981eb1 UO |
81 | if [ -e $EXPIRYFILE ] ; then |
82 | if [ -e $RERENDEREXPIREDTRIGGERFILE ] ; then | |
e6723fa6 | 83 | echo "Expiryfile and triggerfile exists. Marking the tiles mentioned there as expired..." |
c5981eb1 UO |
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. | |
c1cfefc4 UO |
86 | cat $EXPIRYFILE | sudo -u tirex /home.local/osm/bin/osmtilecleanup.pl \ |
87 | --action touchexpiredlist --zoom 15-20 \ | |
5203e8e5 | 88 | /var/lib/tirex/tiles/osm |
c1cfefc4 UO |
89 | cat $EXPIRYFILE | sudo -u tirex /home.local/osm/bin/osmtilecleanup.pl \ |
90 | --action touchexpiredlist --zoom 15-20 \ | |
5203e8e5 | 91 | /var/lib/tirex/tiles/osmde |
c1cfefc4 UO |
92 | cat $EXPIRYFILE | sudo -u tirex /home.local/osm/bin/osmtilecleanup.pl \ |
93 | --action touchexpiredlist --zoom 15-20 \ | |
94 | /var/lib/tirex/tiles/osmhd | |
407cdf50 UO |
95 | cat $EXPIRYFILE | sudo -u tirex /home.local/osm/bin/osmtilecleanup.pl \ |
96 | --action touchexpiredlist --zoom 15-20 \ | |
97 | /var/lib/tirex/tiles/osmdehd | |
e6723fa6 UO |
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 | |
407cdf50 | 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 |
c5981eb1 UO |
105 | else |
106 | echo "Expiryfile exists but rerendering is disabled." | |
107 | fi | |
5203e8e5 UO |
108 | rm $EXPIRYFILE |
109 | fi | |
110 | echo "Ending update script cleanly: `date`" | |
111 | cleanup | |
112 | exit 0 | |
113 |