| 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 | OSMOSISWORKDIR=/home.local/osm/.osmosis |
| 7 | WEBSTATEFILE=/var/www/lastdbupdate.txt |
| 8 | # Note: set the expire-tiles to 3 less than the real maximum, |
| 9 | # as this makes the tilelist MUCH shorter, and the tiles get rerendered |
| 10 | # anyways due to the metatile-layout! |
| 11 | UPDATECMD="/usr/bin/osm2pgsql --slim --cache=8000 --append --database=osm \ |
| 12 | --style=/home.local/osm/dbstyle/osm2pgsql-new.style \ |
| 13 | --hstore --expire-tiles=17-17 \ |
| 14 | --expire-output=$EXPIRYFILE $CHANGESFILE" |
| 15 | |
| 16 | cleanup() |
| 17 | { |
| 18 | rm -f "$LOCKFILE" |
| 19 | exit 1 |
| 20 | } |
| 21 | |
| 22 | trytofeedupdate() |
| 23 | { |
| 24 | echo "Trying to feed updates into databse..." |
| 25 | echo "Executing: $UPDATECMD" |
| 26 | $UPDATECMD |
| 27 | if [ $? == 0 ] ; then |
| 28 | echo "Update went fine, removing changes-file" |
| 29 | rm -f $CHANGESFILE |
| 30 | else |
| 31 | echo "Update failed with error $?" |
| 32 | fi |
| 33 | } |
| 34 | |
| 35 | echo "Starting update script: `date`" |
| 36 | if [ -e "$LOCKFILE" ] ; then |
| 37 | echo "Lockfile exists - ABORTING" |
| 38 | exit 1 |
| 39 | fi |
| 40 | touch "$LOCKFILE" || exit 9 |
| 41 | trap cleanup 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \ |
| 42 | 20 21 22 23 24 25 26 27 28 29 30 31 |
| 43 | if [ -e $CHANGESFILE ] ; then |
| 44 | echo "Changesfile exists - will try to feed update to Database" |
| 45 | trytofeedupdate |
| 46 | fi |
| 47 | if [ -e $CHANGESFILE ] ; then |
| 48 | echo "Changesfile STILL exists - ABORTING" |
| 49 | cleanup |
| 50 | exit 1 |
| 51 | fi |
| 52 | echo "Downloading changes with OSMOSIS..." |
| 53 | echo "Executing: /usr/bin/osmosis --read-replication-interval workingDirectory=$OSMOSISWORKDIR --simplify-change --write-xml-change $CHANGESFILE" |
| 54 | /usr/bin/osmosis --read-replication-interval workingDirectory=$OSMOSISWORKDIR --simplify-change --write-xml-change $CHANGESFILE |
| 55 | if [ $? != 0 ] ; then |
| 56 | echo "Osmosis execution failed. ABORTING" |
| 57 | cleanup |
| 58 | exit 1 |
| 59 | fi |
| 60 | trytofeedupdate |
| 61 | if [ -e $CHANGESFILE ] ; then |
| 62 | echo "Changesfile STILL exists - update must have failed. ABORTING" |
| 63 | cleanup |
| 64 | exit 1 |
| 65 | fi |
| 66 | echo "Update seems to have been successful." |
| 67 | grep timestamp $OSMOSISWORKDIR/state.txt | sed -e 's/timestamp=//g' -e 's/T/ /g' -e 's/\\:/:/g' > $WEBSTATEFILE |
| 68 | if [ -e $EXPIRYFILE ] ; then |
| 69 | echo "Expiryfile exists. Telling tirex to rerender the tiles mentioned there..." |
| 70 | echo "Number of lines: `wc -l $EXPIRYFILE`" |
| 71 | cat $EXPIRYFILE | /home.local/osm/bin/osmtilecleanup.pl \ |
| 72 | --action rerenderexpiredlist --zoom 13-20 \ |
| 73 | --rrs /home.local/osm/bin/osmrerenderwrapper.sh \ |
| 74 | /var/lib/tirex/tiles/osm |
| 75 | cat $EXPIRYFILE | /home.local/osm/bin/osmtilecleanup.pl \ |
| 76 | --action rerenderexpiredlist --zoom 13-20 \ |
| 77 | --rrs /home.local/osm/bin/osmrerenderwrapper.sh \ |
| 78 | /var/lib/tirex/tiles/osmde |
| 79 | rm $EXPIRYFILE |
| 80 | fi |
| 81 | echo "Ending update script cleanly: `date`" |
| 82 | cleanup |
| 83 | exit 0 |
| 84 | |