From ed5f9ec1b8035a6a21caa54e024187e29d765fb1 Mon Sep 17 00:00:00 2001 From: Lionel Vidaller <lvidaller@grandlyon.com> Date: Fri, 30 Oct 2020 14:16:21 +0100 Subject: [PATCH] mise en place setup --- bal2osm/bal_2_osm.py | 4 ++-- bal2osm/osmfile.sh | 8 ++++---- docker-compose.yml | 4 ++-- nominatim-3.5/Dockerfile | 1 + nominatim-3.5/init.sh | 11 ----------- nominatim-3.5/wait.sh | 14 ++++++++++++++ setup.sh | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 nominatim-3.5/wait.sh create mode 100755 setup.sh diff --git a/bal2osm/bal_2_osm.py b/bal2osm/bal_2_osm.py index 9902b7f..248917c 100644 --- a/bal2osm/bal_2_osm.py +++ b/bal2osm/bal_2_osm.py @@ -3,7 +3,7 @@ # In[1]: - +import sys import pandas as pd import osmium @@ -14,7 +14,7 @@ import osmium #fichier_bal = './bal_extrait.csv' fichier_bal = './bal_200046977.csv' fichier_codes = './correspondance-code-insee-code-postal-gl.csv' -fichier_pbf = '/app/src/data-sources/osmfile/mdl-latest.osm.pbf' +fichier_pbf = sys.argv[1] # premier indice osm_id dans les données résultat diff --git a/bal2osm/osmfile.sh b/bal2osm/osmfile.sh index e8fda64..39601c0 100644 --- a/bal2osm/osmfile.sh +++ b/bal2osm/osmfile.sh @@ -1,11 +1,11 @@ #!/bin/bash -FILE=/app/src/data-sources/osmfile/mdl-latest.osm.pbf +OSMFILE=$1 -if [ -e "$FILE" ]; then - rm "$FILE" +if [ -e "$OSMFILE" ]; then + rm "$OSMFILE" fi echo "::: Creating OSM file... :::" -python3 bal_2_osm.py +python3 bal_2_osm.py $OSMFILE echo "::: OSM file ready :::" diff --git a/docker-compose.yml b/docker-compose.yml index 783bf45..41661c6 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: dockerfile: Dockerfile volumes: - ./nominatimdata:/app/src/data-sources/osmfile - command: sh osmfile.sh + command: sh osmfile.sh /app/src/data-sources/osmfile/mdl-latest.osm.pbf nominatim: # image: nominatim @@ -23,7 +23,7 @@ services: ports: - 6432:5432 - 7070:8080 - command: sh /app/init.sh /app/src/data-sources/osmfile/mdl-latest.osm.pbf postgresdata 4 + command: sh /app/wait.sh /app/src/data-sources/osmfile/mdl-latest.osm.pbf postgresdata 4 photon: build: diff --git a/nominatim-3.5/Dockerfile b/nominatim-3.5/Dockerfile index a315961..3c0c2fd 100644 --- a/nominatim-3.5/Dockerfile +++ b/nominatim-3.5/Dockerfile @@ -50,3 +50,4 @@ COPY start.sh /app/start.sh COPY startapache.sh /app/startapache.sh COPY startpostgres.sh /app/startpostgres.sh COPY init.sh /app/init.sh +COPY wait.sh /app/wait.sh diff --git a/nominatim-3.5/init.sh b/nominatim-3.5/init.sh index 9cc1716..bbd0427 100644 --- a/nominatim-3.5/init.sh +++ b/nominatim-3.5/init.sh @@ -2,15 +2,6 @@ OSMFILE=$1 PGDIR=$2 THREADS=$3 -FILE=/app/src/data-sources/osmfile/mdl-latest.osm.pbf - -sleep 5 - -if [ ! -e "$FILE" ]; then - echo "::: Waiting for OSM file to be ready... :::" - sleep 5 -fi - rm -rf /data/$PGDIR && \ mkdir -p /data/$PGDIR && \ @@ -28,5 +19,3 @@ sudo -u nominatim ./src/build/utils/setup.php --osm-file $OSMFILE --all --thread sudo -u nominatim ./src/build/utils/check_import_finished.php && \ sudo -u postgres /usr/lib/postgresql/12/bin/pg_ctl -D /data/$PGDIR stop && \ sudo chown -R postgres:postgres /data/$PGDIR - -sudo sh ./start.sh diff --git a/nominatim-3.5/wait.sh b/nominatim-3.5/wait.sh new file mode 100644 index 0000000..231c899 --- /dev/null +++ b/nominatim-3.5/wait.sh @@ -0,0 +1,14 @@ +OSMFILE=$1 +PGDIR=$2 +THREADS=$3 + +sleep 5 + +if [ ! -e "$OSMFILE" ]; then + echo "::: Waiting for OSM file to be ready... :::" + sleep 5 +fi + +sudo sh ./init.sh $OSMFILE $PGDIR $THREADS + +sudo sh ./start.sh diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..1066ed0 --- /dev/null +++ b/setup.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +### Nominatim ### + +# Stop existing containers +docker-compose down +docker-compose rm -f +# Clear existing data +sudo rm -Rf ./nominatimdata && mkdir nominatimdata +sudo rm -Rf ./photondata && mkdir photondata + +# Get the Métropole de Lyon database +# wget --directory-prefix=./bal2osm https://download.data.grandlyon.com/files/grandlyon/localisation/bal/bal_200046977.csv + +# Generate OSM file +cd bal2osm +docker build -t bal2osm . + + +docker run -t \ +-v `pwd`/../nominatimdata:/data \ +bal2osm \ +sh osmfile.sh /data/mdl-latest.osm.pbf +cd .. + +# Build the image +cd nominatim-3.5 +docker build -t nominatim . +cd .. + + +# Initialize the database +docker run -t \ +-v `pwd`/nominatimdata:/data \ +nominatim \ +sh /app/init.sh /data/mdl-latest.osm.pbf postgresdata 4 -- GitLab