Skip to content
Stefan Sadewasser edited this page Mar 10, 2022 · 2 revisions

TODO

How to

Generate an automatic update

The update job can be automated, i.e. a new .osm file should be imported into the database periodically. This may be necessary to keep the map data up to date, as our world is constantly changing.

In order to be able to automate the update job, it must be ensured that the following files exist and ideally are located in one place:

  • OHDMConverter - the jar file of the OHDMConverter, i.e. OHDMConverter_0_5_1.jar
  • jdbc-driver - the jar of the PostgreSQL, i.e postgresql-42.3.3.jar
  • intermediate_parameter - txt file with connection settings for intermediate schema
  • ohdm_parameter - txt file with connection settings for ohdm schema
  • update_parameter - txt file with connection settings for a temporary update schema

To ensure that all paths are set correctly in the following explanations, I would recommend working with absolute paths.

Note all required schemes should be in the same database

Ubuntu 20.04 - CronJob

The update job is realised in Ubuntu 20.04 via cronjob. To create a cronjob, you need an executable bash script that can later be added to the crontabs.

Create .sh script for the cronjob

In the installation instructions section 3, a folder was created which also serves as the directory in which the bash script is saved.

create a bash script like update.sh and add executive rights to it chmod +x update.sh

now open the script and write into it
NOTE the following script is an example with small sample data, make sure you change the important entries (e.g. osm link).

bash
#! /bin/bash

cd ~/convert # be sure that all data in these directory
now=$(date +%Y-%m-%d-%H-%M) # for other date formats look at `man date`
filename=htw-$now.osm.bz2 # example name

# download osm.bz2 file, example HTW Berlin area
if wget -O $filename "https://api.openstreetmap.org/api/0.6/map?bbox=13.52157,52.45568,13.52936,52.45923"
then
    bunzip2 -kf $filename
    printf "decompressed $filename \n\n"
else
    printf "Download failed \n"
    exit 0
fi

converter=$(find . -name 'OHDMConverter*.jar')
jdbc_driver=$(find . -name 'postgresql*.jar')
intermediate_parameter=$(find . -name 'interdb.txt')
osm_file=$(find . -name '*'$now'.osm')

# possibly provide further notifications, for example mailto admin
if [ -f $converter ]; then
    printf "find $converter\n"
else exit 0;
fi

if [ -f $jdbc_driver ]; then
    printf "find $jdbc_driver\n"
else exit 0;
fi

if [ -f $intermediate_parameter ]; then
    printf "find $intermediate_parameter\n"
else exit 0;
fi

if [ -f $osm_file ]; then
    printf "find $osm_file\n"
else exit 0;
fi

# TODO change to update
java -p $jdbc_driver -jar $converter -o $osm_file -i $intermediate_parameter

## theoretic update
# java -d [path/to/jdbc-driver.jar] -jar [path/to/OHDMConverter.jar]\
# -o [path/to/yourFile.osm]\
# -u [path/to/update_database_parameter.txt]\
# -i [path/to/intermediate_database_parameter.txt]\
# -d [path/to/ohdm_database_parameter.txt]

Add the script to crontab

In order for the script to be executed periodically, it must be added to the crontab.

sudo crontab -e to open crontab as root

and add at the end of the file

*\10 * * * * /path/to/sh_file >> /path/to/logfile-$(date +\%Y-\%m-\%d-\%H-\%M).log 2>&1 ← execute script every 10 minutes

0 1 01 03 * /path/to/sh_file >> /path/to/logfile-$(date +\%Y-\%m-\%d-\%H-\%M).log 2>&1 ← execute every year 3 March 1 a.m

NOTE: for other date formats look at man date

Each star stands for a different parameter
┌───────────── Minute (0 - 59)
│ ┌───────────── Stunde (0 - 23)
│ │ ┌───────────── Tag des Monats (1 - 31)
│ │ │ ┌───────────── Monat (1 - 12)
│ │ │ │ ┌───────────── Wochentag (0 - 6)
│ │ │ │ │
* * * * *   /path/to/sh_file ...

examples

Minute Hour Day of Month Month Day of Week meaning
* * * * * Jede Minute, rund um die Uhr, sieben Tage die Woche
0 0 * * * Täglich null Uhr
5 * * * * Fünf Minuten nach jeder vollen Stunde
*/5 * * * * Alle 5 Minuten
1-59/2 * * * * Jede ungerade Minute
5-59/20 * * * * 5, 25 und 45 Minuten nach jeder vollen Stunde
59 23 * * 0 Jeden Sonntag um 23:59 Uhr. Manche Cron-Syntax erlaubt neben 0 für Sonntag auch 7 für Sonntag.
20,30 1 * * 1-5 Montags bis Freitags jeweils um 01:20 und 01:30 Uhr
0 1 1-7 12 1 Das Programm wird um 1:00 an jedem Tag zwischen 1. bis 7. Dezember UND zusätzlich an jeden Montag im Dezember aufgerufen, da hier der Sonderfall greift, dass nur entweder der Tag des Monats oder der Tag der Woche übereinstimmen muss (siehe oben).



Windows - schtask

TODO